I am using the serial monitor window to read the analog inputs of my UNO R3 using a simple sketch that is just looking at analog pin 0. There are a couple things I don't understand. I am new to arduino so maybe someone can help me understand. Nothing is connected to the arduino but the serial monitor is giving values of around 300. When I connect a wire from analog pin 0 to GND the value goes to 0 which seems to be expected behavior. I don't understand why it is giving a value of 300 when nothing is connected. Shouldn't it give a value near 1023? Also when I removed the wire from analog pin 0 to GND, the values being printed into the serial monitor window took about 4 seconds to return to the original value near 300. I don't understand why this is so slow. Is it supposed to work like this?
Is it supposed to work like this?
yes, these are called floating lines. The ADC(analog digital convertor) just reads noise which can be any value
took about 4 seconds to return to the original value near 300
A charge is slowly building up until it gets to a steady state value. The i/p is a high impedance/resistance so noise in the surrounding circuit is effect your readings.
When you write your sketches you initialize variables so you don’t have undefined values in them, hence you avoid bugs or errors.
When you hook up to i/ps and o/ps you connect hardware to them so they are in a way initialized i.e. they aren’t at some unknown level of voltage. These can be external pull up or pull down resistors, internal pull up resistors, sensors, switches etc.
Try touching the pin with your finger you will see the number change. Unless you connect a sensor or something to the channel, it will read random numbers.
Two easy tests:
- Hook the wire to 5V you should see 1023
- hook the wire to 3.3V you should see about 700 or so/