Light seeking robot

Error message

  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _drutex_create_regex() (line 363 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Notice: Use of undefined constant filter - assumed 'filter' in preg_replace() (line 1 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module(363) : regexp code).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _filter_drutex_process() (line 315 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _drutex_create_regex() (line 363 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Notice: Use of undefined constant filter - assumed 'filter' in preg_replace() (line 1 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module(363) : regexp code).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _filter_drutex_process() (line 315 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _drutex_create_regex() (line 363 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Notice: Use of undefined constant filter - assumed 'filter' in preg_replace() (line 1 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module(363) : regexp code).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _filter_drutex_process() (line 315 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _drutex_create_regex() (line 363 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Notice: Use of undefined constant filter - assumed 'filter' in preg_replace() (line 1 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module(363) : regexp code).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _filter_drutex_process() (line 315 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _drutex_create_regex() (line 363 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Notice: Use of undefined constant filter - assumed 'filter' in preg_replace() (line 1 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module(363) : regexp code).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _filter_drutex_process() (line 315 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _drutex_create_regex() (line 363 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Notice: Use of undefined constant filter - assumed 'filter' in preg_replace() (line 1 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module(363) : regexp code).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _filter_drutex_process() (line 315 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _drutex_create_regex() (line 363 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Notice: Use of undefined constant filter - assumed 'filter' in preg_replace() (line 1 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module(363) : regexp code).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _filter_drutex_process() (line 315 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _drutex_create_regex() (line 363 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Deprecated function: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in _drutex_unhide_all() (line 479 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Notice: Undefined index: tools in drutex_submodule_is_active() (line 635 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Notice: Undefined index: verbatim in drutex_submodule_is_active() (line 635 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).
  • Notice: Undefined index: numbering in drutex_submodule_is_active() (line 635 of /home/davemr/mo-seph.com/sites/all/modules/drutex/drutex.module).

Prototype for a light seeking robot

It uses two tiny servos for movement, and 4 ambient light sensors (sfh3710) arranged in a cross, pointing slightly outwards for sensors. Then it just compares each pair of sensors to see which way to move.

#include <Servo.h>
 
Servo bottom;
Servo top;
 
int bottom_servo_pin = 9;
int top_servo_pin = 10;
int lu_pin = 4;
int lr_pin = 5;
int ld_pin = 6;
int ll_pin = 7;
 
float topMax = 0.95;
float topMin = 0.4;
float topPos = 0.5;
float bottomMax = 0.9;
float bottomMin = 0.1;
float bottomPos = 0.5;
float deltaTop = 0.01;
float deltaBottom = 0.00;
 
float lu = 0.0;
float lr = 0.0;
float ld = 0.0;
float ll = 0.0;
 
float x_speed = 0.01;
float y_speed = 0.01;
float x_thresh = 0.001;
float y_thresh = 0.001;
 
void setup()
{
  Serial.begin(9600);
  top.attach(top_servo_pin);
  bottom.attach(bottom_servo_pin);
  top.write(90);
  bottom.write(90);
}
 
void loop()
{
  updateSensors();
  updatePos();
  writePos();
  delay(10);
}
 
void updateSensors()
{
  lu = (float)analogRead( lu_pin )/1024.0;
  lr = (float)analogRead( lr_pin )/1024.0;
  ld = (float)analogRead( ld_pin )/1024.0;
  ll = (float)analogRead( ll_pin )/1024.0;
}
 
void updatePos()
{
  float average = (lu + ld + lr + ll) / 4;
  float dx = x_speed * ( ll - lr ) / average;
  float dy = y_speed * ( lu - ld ) / average;
  if( abs( dx ) > x_thresh ) bottomPos += dx;
  if( abs( dy ) > y_thresh ) topPos += dy;
  clipPos();
}
 
void clipPos()
{
  if( topPos > 1.0 ) topPos = 1.0;
  if( bottomPos > 1.0 ) bottomPos = 1.0;
  if( topPos < 0.0 ) topPos = 0.0;
  if(bottomPos < 0.0 ) bottomPos = 0.0;
}
 
void writePos()
{
  clipPos();
  top.write((int)( topPos * 180.0 ) );
  bottom.write((int)( bottomPos * 180.0 ) );
}