Using a photoresistor to block menu with arduino!

Hey guys!
Im doing a project in school where im using a menu on an LCD display and four buttons to navigate. The microcontroler im using is Arduino. I got the program for the LCD from Tutorial: manage menu and LCD display with Arduino – Coagula – Giuseppe Di Cillo, and it is working perfectly! But i want to combine it with a photoresistor, so when i press a button and the value is to high, the screen will say "Make the room darker" or something like that. And if the value is low enough it will proceede to submenus.

Thanks! :slight_smile:

Hook the LDR up to an analog input, read the value and make a decision based on that value.


Rob

I am pretty new to programing, but I've figured out how to read the pin. The part I'm not sure is where to place de "decisions" depending on the value. And if i should be using "if" statement.

And if i should be using "if" statement.

Yes.

For example (very roughly)

int light_level = analogRead(A0);

if (light_level < 500) {
    lcd.print ("Dark enough");
} else {
    lcd.print ("Not dark enough");
}

Rob

Thanks for the help, but it's not really what im looking for.
When i press the a button on the menu, i want it to either "block" the menu and write "make it darker", but if its dark enough it will proceede to submenu.
I'm sorry if im pretty slow :~

Well let's make a small change

int light_level = analogRead(A0);

if (light_level < 500) {
    print_menu();
} else {
    lcd.print ("Make it darker");
}

Rob

Thank you very much! It helped alot, and now it's working :slight_smile: