Please explain simple circuits behavior

Hi, I've started to play with Arduino a few days ago, and I must say it's the funnest toy I've got in years!

I've started to mess around with simple photocell circuits, using the V5 power pin as a power source and reading the output through Analog Input 5. Now, the questions.

A. when nothing is connected to AnIn 5 it gives out random (so it seems) values around 400-500, why is that?

B. I've made some simple circuits (pictures below) which put different readings in to the analog input pin, I'd really appreciate it if someone could explain to me why each circuit gives the reading it gives, and maybe show me the math behind it.

Circuit 1:

The analog reading is always 0, no matter how much light the photocell receives. Is that because all the power goes to the ground?

Circuit 2 (not grounded):

The analog reading is always 1023 (maximum), Why is that?

Circuit 3 (the correct, working one):

The readings match the light exposure of the cell when the resistor is added to the circuit. How does the resistor make the circuit function correctly? How are the values of the output affected by the resistor?

Sheesh that was a long one :smiley:

Welcome to the wonderful world of Arduino! :smiley:
I'm still fairly new myself, but I'll do the best I can to explain what I've learned so far!:slight_smile:

A: The random values you get are considered "floating values", random noise generated from .. anything, RF signals, the chip it self, you touching the board, a good selection! Generally, that's why you need to use a Pull up or Pull down resistor (pull-down in your 3rd picture) when you're using Switches. The resistor will hold it to ground, or to 5v, so the noise won't trigger the values, then once you push the button, viola!

B: I'm not sure how to explain some of the pictures.. but the first one, you'll need to research Voltage Dividers. (Potentiometers are voltage dividers) Voltage divider - Wikipedia

Second circuit, the same reason. The electricity needs a GND connection, or the current can't travel through the circuit. For example, when you connect a second battery pack, you won't get any power unless you connect the ground of the battery, to the same ground of the Arduino.
Here, our awesome member Grumpy_Mike has some great explanations on his website, take a look:
http://www.thebox.myzen.co.uk/Tutorial/Introduction.html
And I'm sure he'll come along and fix some of my post:D He has a good bit of information to read, go back to the main site for more projects and learning tools!

This is an AWESOME book, download a copy. Has a bunch of starter projects for the Arduino, and it goes through all the code it uses, along with the hardware setup! (Also made by another great member, MikeMc!)
http://earthshinedesign.co.uk/ASKManual/Site/ASKManual.html Click on the picture to get started, I suggest you save it to your hard drive so you don't need to load everytime you want to open it, it's VERY useful.

Anyways.. sorry for the random information, hopefully I explained most of your questions!
Best of luck, and welcome again!:smiley:

First one is always 0, because whatever resistance the LDR is, it will always be short circuited to ground. The second is always 1023 (5volt) because the impedence of the arduino is very high (100 mega ohms) the current flowing to the arduino (next to nothing) won't be affected by the comparitively low resistance of the LDR. The third one forms a voltage divider circuit, and the voltage will vary dependant on the resistance of the LDR. If you use a 10k resistor and the LDR is 10k at a given light level then the reading will be 512 (or thereabouts). When its dark and the LDR resistance is very high, then the voltage is nearer 0, when its bright and the LDR is low, then the voltage will be nearer 5V.

Thanks for the explanations and the links (the book is really great!), I guess I'll have to go over the theoretical part of stuff once again, in a more thorough way :smiley:

BTW, here's a great Circuit Simulator java applet, I found it really useful!