Hello, i am a bit of a newbie, and i am trying to measure the analog pin 0 (A0) on my Arduino UNO R3 board.
I have code that prints to the serial monitor/plotter the reading of the analog pin A0. This all works fine, when i apply 5v to the pin, the reading goes to, i think it was 1023, if i apply 3.3v to the pin, it goes to 600 and something, if i apply Ground to the pin, it goes to Zero. This is all fine, however if i have nothing connected to the pin, the reading fluctuates all over the place, from zero to 1023.
Could someone please tell me why this happens, etc.
That is what is called a "floating pin". As you've seen it might read any old value it has picked up from the air.
The moral is "Do not waste your time reading analog pins with nothing connected to them". If you need to disconnect a test thing from the pin then include a resistor to pull the pin up or down to 5V or 0V.
presumably all the analog pins ( A0-A5) are "floating pins"?
How can i make it so that when the board senses a signal at one of the pins, it does something(switches something on etc)? What pin do i need to use for this?
All pins, analog or digital can float. I.e. if there is nothing connected the result of reading the pin is undefined.
What is it that you are trying to connect/measure or whatever? There no point me trying to guess at a generic answer that very likely won't fit your circumstances.
At the moment i am simply playing around, familiarizing myself with the code side of things.
i am trying to simply get a LED to light up when i supply a signal to one of the pins on the board. At the moment i am just using the UNO's 5/3.3v supply and a button, however in future the LED could be anything, and so could the signal.
What i was trying to do, was supply a signal to the A0 pin, and then in the code, i would tell it to when analogRead(A0) is over, say, 800, (because 5v seems to go to 1023), it turns on the LED on one of the digital pins.
well that is what i had in my head...
Of course in practice, because when i am not supplying anything to A0, the number goes all over the place, often reaching over 800, this would not work.
A far more useful test would be to connect a potentiometer to 5V, GND and the analog pin. That way you get a varying voltage. That approximates what any analog sensor will do. Switches are different again but they're better accessed using digitalRead().
sag2:
How can i make it so that when the board senses a signal at one of the pins, it does something(switches something on etc)?
Using digitalRead() or analogRead() and testing the data that is returned. Obviously, the computer can't read your mind and guess what your criteria are for registering an event on the pin, so you have to define and implement that yourself. There is no generic answer.
Consult the Arduino example suite for many code examples of this. A simple example:
Thanks for all the reply's.
i managed to get it to work with the potentiometer method, and i wrote some code similar to that posted by "aarg", and it worked fine.