I cannot get photoresistor to work with LCD (or anything else for that matter)

Hello. This is my first post as I've had an Arduino for all of about 2 weeks. I'm trying to do a project for an intro class, and I'm at my wits' end with it. I successfully managed to use some code to make an animated heart on the LCD screen that comes with the Arduino kit to look like it's beating. I'll skip ahead and say that I clearly don't have the skills to do what I originally wanted to do, and now I'm just trying to simply use a photoresistor so that when you put your finger over it, the LCD screen lights up and shows the animation, and when your finger is not over the photoresistor, everything goes dark. For right now, I'm just trying to at least achieve a proof of concept with the LCD backlight, but that hasn't worked either. I pasted the code below. Once I can get that part to work, I could then copy it over into the animation code (I hope). Thanks in advance for any help you can provide. Lastly, if the code seems confusing it's because I don't know what I'm doing! The class barely touches on the coding aspect, so I really am brand new to this. As an example, I have no idea what Serial.begin(9600) is or why it always seems to be that number. I'm rambling so I'll stop. Thanks again!

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // RS, E, D4, D5, D6, D7
int backLight=13;
int lightValue;
int photoresistor = A0;
void setup() {
Serial.begin(9600);
pinMode(backLight, OUTPUT);
pinMode(lightValue, INPUT);
}

void loop()
{int lightValue = analogRead(photoresistor);
Serial.println(lightValue);
if (lightValue > 1000) {
digitalWrite (backLight, LOW);
}
else {digitalWrite(backLight, HIGH);
}}

The backlight of an LCD should by powered from power line, like 5V pin from arduino. I think that there is not enough power in normal arduino output to switch it on.
Maybe try with simple LED first.

Value 1000 for the photo resistor is a little bit to high, I'm pretty sure there will be some noise. Try half of that, something like 512, as the maximum is 1024.
Also photo resistor should be used in conjunction with another normal resistor as voltage divider. Otherwise analog read won't show anything as it reads voltage levels (0 to 5V) and not the rezistance (or current) of just the photo resistor.
Something like this:
unnamed

There is a reference tab on the main site page here. All that stuff is explained and documented there.

There's no way You can power the backlight from an output. Use clearScreen for that.

Use the built in LED on the board for testing.

Open the serial monitor and you will see the values returned while reading the photo resistor (LDR) with different light inputs. Then you can set thethreshold in the if structure.

Thanks for the fast responses. I'll try to respond to as many as I can. I do have the LCD and the photoresistor powered by the 5V output. The number 1000 was a number chosen at random because it doesn't seem to matter what number I put in, nothing changes. I will check out that reference tab, thanks. I'm not sure what clearScreen is, maybe I'll see it when I go to the reference tab that another person mentioned. I have started trying to test out using the built in LED but I haven't gotten very far and it isn't working, at least not yet. And not sure what serial monitor is. I'm sorry that I don't seem to know much. You all probably don't need to respond further because the responses show me just how much I don't know. I just don't want to waste anyone's time. Maybe I can find an Arduino for dummies book haha. Lastly, if anyone is interested, here is a photo of the contraption.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.