IoT Hacks for IoT geeks.

Analog Input Pins

11:24 PM Posted by Gopal Kildoliya No comments
The Atmega controllers used for the Arduino contain an onboard 6 channel analog-to-digital (A/D) converter with 10 bit resolution (0-1023). The main function of the analog pins is to read analog sensors, but analog pins also have all the functions of digital pins (pin 0 to pin 13).

To use the analog pin as a digital pin we have to use the following code:
pinMode(A0, OUTPUT);
digitalWrite(A0, HIGH);
Here A0 is analog pin 0.
The analog pins also have internal pull-up resistors like other digital pins and cofigured as for digital pins:-
digitalWrite(A0, HIGH);  // set pullup on analog pin 0 
The analogRead command will not work correctly if a pin has been previously set to an output, so set it back to an input before using analogRead. 
There may be a noise if we use switching in reading of analog pin with other analog pin. So we have to use a delay to read two analog pins.
Reference voltage used for analog input:
To configures the reference voltage used for analog input we use the following command:
The options for type are:
DEFAULT: the default analog reference of 5V or 3.3V according to board
INTERNAL: an built-in reference, equal to 1.1V on the ATmega168 or ATmega328 and 2.56V on the ATmega8 
EXTERNAL: the voltage applied to the AREF pin (0 to 5V only).
NOTE:- Don't use anything less than 0V or more than 5V for external reference voltage on the AREF pin! If you're using an external reference on the AREF pin, you must set the analog reference to EXTERNAL before calling analogRead().
Reads the value from the specified analog pin. It will map input voltages between 0 and 5 (ref volt) volts into integer values between 0 and 1023. So the resolution 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.
Maximum reading rate is about 10,000 times a second. If the analog input is not connected to external circuit then the readings will fluctuate. 


Post a Comment