I am making a school project where i need to create a parking loot in tinkercad. Me and my mate tried to use a bunch of photoresistor that worked as a sensor. No light = car = red led; light = no car = green led. We can't figure out why the leds dont turn on. We are still on a low level of abilities on this type of work and in class we didn't see a lot of components, so the photoresistor were one of the best choice.

Here is the screenshot of the whole project, it's in italian so if you guys needs a transduction of the variable just tell me. Don't mind the button, we were trying something.

enter image description here

Here is the code: In this line "if(analogRead(fotoresistori[i]) < 300)" we put 300 because with 0 etc. it did not work

int fotoresistori[] = {A0, A1, A2, A3, A4};
int verdi[] = {11, 10, 9, 8, 7};
int rossi[] = {6, 5 , 4, 3, 2};

void setup()
  pinMode(13, INPUT);
  pinMode(12, INPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);

void loop()
  if(digitalRead(13) == HIGH){
  else if(digitalRead(12) ){
  for(int i = 0; i<5; i++){
    if(analogRead(fotoresistori[i]) < 300){
      digitalWrite(rossi[i], HIGH);
      digitalWrite(verdi[i], LOW);
      digitalWrite(rossi[i], LOW);
      digitalWrite(verdi[i], HIGH);

The value of A0 is always at 0.


1 Answer 1


You're not applying any voltage to the photoresistors and the other end is connected to earth so it will always be zero. You need to connect the analog end to +5v via a suitable current limiting resistor (suggest 10K for a typical photoresistor) then measure the voltage.

  • Ok thank you. I will try it now
    – Visioli
    Commented May 23, 2022 at 16:43
  • I did this: i.imgur.com/gVTMa8A.png but the led still won't turn on. But thanks to you now the output of A0 is no longer stucked on 0.
    – Visioli
    Commented May 23, 2022 at 17:02
  • Ok mate i did everything and i worked! At the end there was another error, but thanks for the advice
    – Visioli
    Commented May 23, 2022 at 17:45
  • Glad you worked it out in the end
    – Bra1n
    Commented May 23, 2022 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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