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.
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.