Hi,
I am having an issue with a project and have narrowed it down to the fact that the analog pins aren't returning useful values. I would expect that when completely disconnected they would return zero but are in fact returning values in the vicinity of 290 to 300.
Also if I give one of them 5volts then that one goes up to around 1018 and the others jump up to around 768.
I tried an alternative board sold by our local electronics company (Jaycar) and that gives a value of around 460 with zero volts.
Here's the basic code I used to read the pins. Any help for a newb would be appreciated
Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and prevents the forum software from incorrect interpretation of the code.
It does indeed read zero! OK thanks for that. My actual problem is with getting usable values from a photoresistor i.e. values that actually substantially change when the light conditions change but I thought I'd found the issue with the pins not returning a zero value. At least I can rule that out now.
Done! Sorry I didn't do this to begin with - I did get a message about it when I posted but the page looked fine so didn't bother. I can see it does make a difference though so will do so in future.
How are you connecting the photoresistor (or Light Dependant Resistor, LDR)? You need to use a fixed value resistor (eg. 10K) with it to form a voltage divider.
As I read it, he only connected one; the others will, of course, be affected by charge transfer, but no one has explained that yet, and the topic is solved, so I'll avoid it.
C
Hi Paul,
I have 5 volts on one side of the photoresistor and a 10K resistor to earth on the other side and a lead to an analog pin on the non-earth side of the resistor. I followed the Arduino project book for that part of the wiring so it should be ok.
Thank you for the tantalizing hint regarding charge transfer - I did a bit of googling and a slight rewire and now have my desired three sensors all giving useful results. I prematurely 'solved' the topic because I thought I had enough to progress with but your hint got me across the line Much appreciated.
Contributors @groundFungus and @Paul_B point out here that it may be possible to do away with the external resistor in the divider by using INPUT_PULLUP on either digital or analog inputs.
Only issue with that is the vagaries of semiconductor 'resistance' formation mean that the internal pullup resistance is 'approximate', and varies from device to device. But presumably the OP will need to do a calibration of each such device anyway, so maybe it will suffice. My problem with on-chip resistance is that it will almost invariably change with temperature, as the chip warms and cools(for example, when powering more or fewer LEDs). That introduces unpredictability in the pullup resistance, which is no big deal when being used as a pullup, but may be undesirable in a calibrated circuit.
YMMV, no warranty, ya gets what ya pays for, etc. etc.
C
I think you are making the common mistake of thinking that 0 volts (zero volts) is the same as 'no volts'. 0 volts is a point in the circuit designated by the circuit designer against which all other voltages in the circuit are measured unless stated otherwise. No volts is a physical impossibility, all normal matter made of protons, neutrons and electrons has a voltage, it must have because in the middle of an atom there is a positive charge and round the outside a negative charge. There is always a voltage on a pin, it just might not be the voltage you expect it to be.