Photovore bot > WIP

photovore_code.html (31038Bytes)



Rigged up something if it can be called a bot. Two LDRs provide sensor information. Intially, i set up the code so that if one sensor got more light, then the opposite wheel would turn forward and the other wheel backward. This turned out to be extremely jerky, with the thing acting like an epileptic loony. Hence, after continuous research on pwm, i've tried a different approach. Sensor values are read and if one gets more light, the opposite wheel turns with a pwm pulse propotional to that sensor reading, while the other wheel turns at a slower rate, determined by the opposite sensor.

heres some pseudo code to clarify...

1. Read left and right sensors

2. If left > right, then

a. speed of right motor = pwm value based on left sensor right turns faster

b. speed of left motor = pwm value based on (right sensor reading / 2) ... ie left turns much slower

3. if right > left, then exact opposite of above

4. if right and left almost equal, then turn both motors at same speed


I also tried completely halting one motor while the other turned, to change direction but i thought this was smoother. Perhaps there are far better methods...


specs: Arduino, 6v battery, two 12v gear motors, two LDRs.


If anyone has spare time , perhaps they could be gracious enough to glance at the rudimentary code (attached as htm file for greater readability)??

Thank you


PS > wall banging video attached...

same same but different

I don’t read Arduino, so your code is gibberish to me, but reading from your post it seems like;

1) If left sensor is brigtest, then left sensor controls right motor and vice versa

2) If right sensor is brightest, then left sensor controls right motor and vice versa


-There isn’t any difference between those two actions… What have I missed?

I think theres a lot of

I think theres a lot of unnecessary math in the code. First up you take analog sensor readings and map them to a value from 0-254. Why not just put that raw number straight into the analogWrite? If the left is brighter it goes slower and vice versa. Plus you can make it dark seeking by switching sensor -> motor values.

Doing this will have the unwanted affect of making BOTH sides slow in the dark. If you don`t want that, map the values to something like 150-254 instead.

not exactly… its more

not exactly…


its more like this…

a. If left senses more light, then right motor spins faster and left spins slower

b. if right senses more, then left motor spins faster and right goes slower

the raw values obtained were

the raw values obtained were above 254, more in the range of 600+. Inputing that would make both turn at full speed. Hence scaled it down to that range.

Yes, it stops when its in the dark, but what will guide it if there is no light? I mean, mapping it to higher values will ascertain that the motors keep turning, but how will it know where to go without any light?

thanks for feedback.