Friday, 30 June 2017

adc - Arduino has an input value in disconnected pin



I'm new to arduino. Maybe is an elemental question...


If I load this program:


int mval = 0;
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows:

}

void loop() {


mval = analogRead(1);
Serial.println(mval);

delay(1000);
}

I get a value that varies between 300 and 400. When I think it have to be 0, being that there's nothing connected to that input.


Any ideas?? It's an arduino UNO connected to my laptop via USB



Answer




You're getting something called "floating input". When you think about it, an ideal device for measuring input will have a very high input impedance, and thus will not remove very much electricity from the pin.


So what happens is that random electrons float on to (or off of) the pin (either from electro-magnetic interference in the environment or from direct contact with something with a slight charge), and because it acts like a very high resistance connection to ground, this charge will drain off very slowly. Thus when you go to measure it, it looks like there's some voltage there! In general, you either hook this up to some device which provides a voltage, or you put in a pull-up or pull-down resistor and adjust your expectations on that pin.


I hope that helps and if not I'm sure someone has a link to another person who has answered this question more competently (I see in the related section at least one near-identical question).


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...