This was the wiring that I used for my Arduino Project.

This is the code used in the project.

I have had trouble with this for the past week and nothing I have been doing works. I've tried replacing the photosensors and change the wiring, but I've never had any success.

  • 3
    there is no way to test your code ... nobody is going to spend the time typing it in so that they can test it .... if you really want some help, pleae post text instead of a picture of text .... use the {} button to format the code – jsotola Oct 24 '19 at 0:48
  • Don't post an image of your fritzing circuit. Post a photo of your Arduino and your breadboard so we can see it's wired correctly and can see the value of the pull down resistors. – Dougie Oct 24 '19 at 6:15
  • If the pictures are correct: You attached the servo pin to PIN 9 but connected it to PIN 2 as far as I can see. PIN 2 is not a PWM pin. A servo lib drives the servo with PWM. So I would recommend to use PIN 9. And of cause you did not read the values of the LDRs repeatedly in the loop as stated in one of the given answers. – Peter Paul Kiefer Oct 26 '19 at 16:03

The serial resistor is 220 ohm. I think that is to low value try 10K resistor. The photosensor had to have a higher serial resistor. /Mikael

| improve this answer | |

There is something wrong with your code. You are not reading the sensor value continuously in the loop. There are few loopholes in the code.

int F = analogRead(Flat);
int S = analogRead(Sharp);

You are reading the analog value outside the loop() function. This is not the right way of writing code. your code will not execute without including the code under the setup() or loop() function. setup() function code will run only once and loop() function code will run repeatedly.

So you have to include the sensor reading code within the loop() function.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.