Go Down

Topic: Saying "Hi!" with my current project (Read 3880 times) previous topic - next topic


Looks pretty cool.  Nice work on the base - looks 'manufactured'.  The IR thing will do what - scan around?  Detect motion?

I'm very interested in your driver strategy.  I've found that the 1-degree steps are pretty coarse.  So I'm trying microseconds from about 650 to 2400 (seems to concur with Federico - but I'm not sure I understand it yet).
This is a couple bits from my code: 1st is servo 1, second is servo 2, third is time interval in ms:

{650, 1000, 2000}, //650 is about the limit for ccw rotation

 {2600, 1290, 1000}, //2600 is around the limit for cw rotation


The basic idea is to make a very primitive "motion tracker" using simple IR phototransistors.
Of course, it will basically just rotate until both sensors have relatively equal readings. What will keep it from being jittery, is defining a deadband in the code. Other than that, it basically does a +1 or -1 left or right..
I am not using PWM, just calling out, or calculating out the angle of the servo 0-180 degrees using the Arduino library.
I will share code here after I do a test with the sensors mounted on the 1st servo.


Jan 10, 2011, 01:41 am Last Edit: Jan 10, 2011, 07:06 am by Mr_Manny Reason: 1
I got it wired up for a full test with the IR sensors mounted on the turret, but the results were less than encouraging.
Possibly my sensors need amplification, or my wiring is just shorting.
The axis is not responsive unless I shine bright light on it, and sometimes jittery.

EDIT: I think it is a fault phototransistor. Only one sensor activates the slew.

Here is the code I adapted:


  Base Coding For Arduino Motion Tracker Using IR Sensors
  Adapted by Mr_Manny from code by Dave Auld
  Original Url: http://www.codeproject.com/KB/system/ArduinoLightTrack.aspx

#include <Servo.h>

// Define Pins To Be used
int pin_L = 5;             //Left Sensor Pin
int pin_R = 4;             //Right Sensor Pin
int servoX = 11;           //Pin For The Horizontal Servo

int leftValue = 0;         //The left Sensor Value
int rightValue = 0;        //The right Sensor Value
int error =0;              //The Deviation between the 2 sensors
int errorAVG = 0;          //Error Average - Rolling 2 Point

int deadband = 10;         //Range for which to do nothing with output 10 = -10 to +10      

//Servo Declarations
Servo ServoHorz;           //Make a Servo object
int Position = 45;         //Position to write out

int minPos = 10;           //Min Position
int maxPos = 170;          //Max Position

float output = (maxPos - minPos) /2;  //Start Position, Try 90deg Later

void setup()

void loop()
  //Read Sensors And Calculate
   leftValue = analogRead(pin_L);
   rightValue = analogRead(pin_R);

 error = leftValue - rightValue;
 errorAVG = (errorAVG + error) / 2;
 float newOutput = output + getTravel();
 if (newOutput > maxPos)
   newOutput = maxPos;
   if (newOutput < minPos)
     newOutput = minPos;
    //Output Writing
    output = newOutput;

int getTravel()
  // -1 = Left; +1 = Right
 if (errorAVG < (deadband * -1))
   return 1;
   if (errorAVG > deadband)
     return -1;
     //Do not move within deadband
     return 0;


Jan 11, 2011, 03:22 am Last Edit: Jan 11, 2011, 03:43 am by Mr_Manny Reason: 1
So, I tried a different sketch, and it works more predictably.
I need to go over my adapted code, and find the problem.
When I run this sketch, the tracker seems to have exagerated jitter/oscillation randomly.

Maybe somebody can spot the problem ?  ;) :-?

EDIT: Ok, maybe it needs a center position to start:


void setup()
ServoHorz.write(minPos);  //Quick Initialization before start


Jan 16, 2011, 01:40 am Last Edit: Jan 16, 2011, 07:52 pm by Mr_Manny Reason: 1
I just received my Sensor Shield V4.0, and it is going to make my testing easier.
Pretty neat, just what I needed. I also bought a new pair of IR phototransistors to change the wiring setup a little, and now I can solder a standard servo cable to the sensor.


Looks awesome!!
Great idea to do the 3d design then do the real concept!!

Keep up the good work !


Jan 16, 2011, 11:49 pm Last Edit: Jan 17, 2011, 01:29 am by Mr_Manny Reason: 1
Small Update. Here is testing of the X axis.
Sorry about the soundtrack, you might want to mute.


The test involves a lamp above and a white plastic sphere for reflection.

Go Up