1
\$\begingroup\$

What is the difference between digital and analog input pins declared on microcontroller? In which situations we use analog and in which digital input pins? What will happen if we put an digital signal into into analog input pin, and vice versa?

\$\endgroup\$
  • 6
    \$\begingroup\$ Use an analogue pin for an analogue signal and a digital pin for a digital signal. \$\endgroup\$ – Andy aka Jul 22 '15 at 8:42
  • \$\begingroup\$ This might be more appropriate for arduino.SE \$\endgroup\$ – cspirou Jul 22 '15 at 14:50
9
\$\begingroup\$

The difference is that a digital pin is only able to detect whether there is a voltage present on a pin or not, while an analog pin is connected to an internal Analog to Digital Converter (ADC) and can measure the actual voltage on the pin.

A digital pin is suited to detect if a button has been pressed, while an analog pin might for example measure the position of a potentiometer.

\$\endgroup\$
  • \$\begingroup\$ But can we use analog input pin for button-pressed detection? \$\endgroup\$ – Junior Jul 22 '15 at 8:45
  • \$\begingroup\$ @ParadoxECE Yes, you can. Analog ports are capable of performing digital functions, but you would usually avoid doing that to make available the extra functionality that an analog port offers. Note that the inverse is not true, digital only pins do not have analog (ADC) functionality, but might have other uses for things like I2C, UART, SPI, etc. \$\endgroup\$ – justinrjy Jul 22 '15 at 9:28
  • \$\begingroup\$ Analog pins often cannot trigger interrupts. \$\endgroup\$ – Simon Richter Jul 22 '15 at 13:38
1
\$\begingroup\$

You can easily apply a digital signal to an analog pin. But be aware that detection of an analog value via ADC is normally slower than reading out a digital pin. What you get is, depending on the value, a quite low or a quite high value, but nothing in-between.

If you apply an analog signal to a digital pin, however, things are not so easy. Depending on the circuitry used for reading out that pin, it may happen that you have a CMOS situation where both transistors are conducting, a situation which is conntected to high losses of power.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.