1

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);
  Serial.begin(9600);
}

void loop()
{
  Serial.println(postiDisponibili);
  if(digitalRead(13) == HIGH){
    postiDisponibili++;
  }
  else if(digitalRead(12) ){
    postiDisponibili--;
  }
  for(int i = 0; i<5; i++){
    if(analogRead(fotoresistori[i]) < 300){
      digitalWrite(rossi[i], HIGH);
      digitalWrite(verdi[i], LOW);
    }else{
      digitalWrite(rossi[i], LOW);
      digitalWrite(verdi[i], HIGH);
    }      
  }
  delay(500);
}

The value of A0 is always at 0.

0

1 Answer 1

0

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.

4
  • Ok thank you. I will try it now
    – Visioli
    May 23 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
    May 23 at 17:02
  • Ok mate i did everything and i worked! At the end there was another error, but thanks for the advice
    – Visioli
    May 23 at 17:45
  • Glad you worked it out in the end
    – Bra1n
    May 23 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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