Let's Make Robots!

LDR Problem

 

I have a problem I am building a Photovore using an Arduino and I cant get the same readings from the 2 LDRs which are affected by the same amount of light. And I need a solution and some example code would be helpfull I tried mapping the values down to 1 to 100 but it doesnt work good Oh yeah one of the ldrs is more sensitive to light i think is this possible.

AttachmentSize
Thecode.pde3.76 KB

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I am using this http://www.pololu.com/catalog/product/2231 so should i use a logic battery and and a battery for motors ill post pictures and video asap.

You're running off of a single 9v battery, aren't you? (I can just feel it).

Beyond that, this also feels like motor noise to me. Stick with what others have said, need to see video, etc. --but in addition, I think you need some caps on your motors. Just some basic, .1uF caps on your motor terminals. Just pick a LMR post at random and you will probably see the caps on the motors and how to connect them.

In addition, a big polarized cap (the one with - marked on one side (round, like a can)) on your power lines may help as well.

When I say jumping I mean the values of the LDRs and I am using chowmix code cause the code you gave the motor is going so slow that it's not moving the motors only move from 255 and 220 so I can hear the noise. When I do a test run With only the LDRs the values are the same but when the motors are moving the values change a lot (jumping). I could post a video of the debugging while testing and with the motors running. I was thinking sine the LDRs and motors are connected to the same power rails and power source maybe spikes from the motors are disturbing the LDRs. What do you think.

Definitely try to seperate the power source. What motor driver are you using. It'll be very helpful if you can post a schematic. Basically you want to have a power source for the motors that only shares a common ground with the arduino's power.

Ive got a problem again it is that during debugging the LDRs I get a steadt stream of data but when it is in the real program which also moves the motors the values jump alot and i mean majorly what is the problem is it because my motors are powered by the same powersource as my LDR I think that is the problem if it is what should i do.

First, post a video of it running for us. If we can see the way it's jumping (the rhythm, timing, etc.) it might save some time. Do it on a sunny day and put near a window so that it has a sunbeam to Dx with. Try to show the breadboard in a steady shot or just attach a photo. Webcam/camera phone video should be fine.

Second, did you load the code I wrote or are you still using Chowmix's instructable code?

It is youre code I could not find a way to make a photovore so I cannabalized youre code from instructables and my own Im Sorry why does it have to 1023 - analogread i do not understand.

that line of code is used to invert the value. I use the internal pullup resistor inside the arduino pins and connect the other end of the LDR to ground. The values usually show up as 0 being very bright, and 1023 being completely dark. But I use 1023 - analogRead() to invert the sensor value so that 1023 is the brightest and 0 is the darkest. I find it easier to work with that way. 1023 is the maximum value of the analogRead function. 

I recognize that code, It was written by me :) although it seems you have made some changes..

Sorry if it gave you any problems..

At first glance I noticed this, 

{

LeftSensor = 960 -  analogRead(LeftSensor);

delay(1); // the delay allows the Analog to Digital converter IC to recover for the next reading.

RightSensor = 1020 -  analogRead(RightSensor);

delay(1);

}

 

it should be {1023 - analogRead();} for both sensors, unless you changed that to equalize the sensors.

The LDR is connected to vcc i drew the fritsing wrong first time. And i will try with the 5k pots luckily i got 2 at home. and thank you for the help