I need help with the serial monitor (read message)

so I’m kinda new to Arduino and I want to try out a project that basically reads the current flowing through a photoresistor and then displays it in the serial monitor.

So, I connected one end of the photoresistor to the ‘ANALOG IN (0)’ and the other end to ‘5V’. I have attached a photo of my code, and I was wondering if somebody could tell me what’s wrong. please be nice, I’m very new to this.

Screen Shot 2019-12-25 at 4.37.14 PM.png

From the search function in the upper right of this page.

measure current

To put your code in a code box, use the </> icon in the far left of the post tool bar and paste your code between the two bracket sets that appear.

To go back and put your code in a code box, in the bottom right of your post, select “more” and click modify. When the modify post opens, high light your code and click the </> in the far left of the post tool bar. This will put you code in code brackets. Then save the changes.

Please don’t post photos of code. Just copy and paste the code using the code button </>. See How to use the Forum

The Arduino analog pins measure voltage between 0 and 5v (for a 5v Arduino).

A light dependent resistor (LDR) needs to be wired with a fixed resistor to make a voltage divider and the analog pin is connected to the joint between the two resistors. Like this

5v ------------LDR -------------Fixed Resistor-----------GND
                    analog pin

A fixed resistor of the order of 100k would probably be suitable but it depends on the brightness of the light you are trying to sense.

Note that if all you need is a light/dark sensor you can use an LDR as above with a digital pin - and the analog pins can also be used as digital pins.


And even better, connect the LDR between the pin and ground and use a pull-up resistor. Using INPUT_PULLUP on that pin will substitute for an approximately 47k pull-up.