Difference between Analog and Digital Pins on my Arduino Board

Click For Summary

Discussion Overview

The discussion centers on the differences between analog and digital pins on Arduino boards, exploring their functionalities, applications, and some common misconceptions. Participants share their experiences and technical details related to the use of these pins in various contexts.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • Some participants explain that analog pins are used for reading analog voltage through an ADC, while digital pins are primarily for output, controlling devices like LEDs and buzzers.
  • There is mention of the analogWrite() command, with some participants asserting that it does not exist for analog pins, while others claim to have successfully used it.
  • A participant describes how analogRead() provides a value corresponding to the voltage input, while analogWrite() uses PWM to simulate varying voltage levels.
  • Discussion includes the idea that using analogWrite() for D/A conversion may require additional circuitry to filter the PWM signal into a proportional DC voltage.
  • Participants share personal experiences, such as building a 6-bit R-2R DAC and generating sinewave signals, which adds a practical perspective to the discussion.
  • There is a reference to historical technology (Covox), which prompts curiosity and further inquiry among participants.

Areas of Agreement / Disagreement

Participants express differing views on the capabilities of analog and digital pins, particularly regarding the use of analogWrite(). While some agree on the basic functionalities, there is no consensus on the specifics of PWM and its implications for analog output.

Contextual Notes

Some statements about the use of pins may depend on specific Arduino models, and the discussion does not resolve the technical nuances of PWM versus true analog output.

Who May Find This Useful

This discussion may be useful for Arduino users, electronics hobbyists, and those interested in understanding the practical applications of analog and digital pins in projects.

ISamson
Gold Member
Messages
435
Reaction score
150
I wanted to ask what the difference between analog and digital pins is on my Arduino (or any other board). I have been using both but don't really know what the difference is.
Thanks!
 
Engineering news on Phys.org
Analog pins are the ADC (analog to digital converter) input pins. They are used for reading analog voltage (between 0-5V on arduino, by default). Check out the sample program for analogRead() command.

Digital pins are used mainly as output pins. You can connect various devices (LEDs, buzzer, LCD) on the digital pins and turn them on/off by writing HIGH or LOW on the respective pins. Check out digitalWrite() command. Before using a digital pin, you have to set it in input/output mode using pinMode() command. You can use a digital pin in input mode as well, especially when using interrupts in your code. Digital pins 2 and 3 of UNO can be used for interrupt detection. In general, you can check the status (on or off) of a device (or a switch) connected to a digital pin by using that pin in input mode. The command used is digitalRead().
 
  • Like
Likes   Reactions: ISamson
Perhaps two things worth to add, as I have seen people confused about them:

1. Some pins can be used as either analog or digital, their use is not predefined in the hardware.

edit: this is wrong, see detailed explanation below:
2. There is no analogWrite() command (in other words: analog pin can be used only for reading, while digital pin can be used for both reading and writing).
 
Last edited:
  • Like
Likes   Reactions: ISamson
Borek said:
2. There is no analogWrite() command (in other words: analog pin can be used only for reading, while digital pin can be used for both reading and writing).

I have once used the analogWrite() and it seemed working fine to me...
Could this be true?
 
cnh1995 said:
Analog pins are the ADC (analog to digital converter) input pins. They are used for reading analog voltage (between 0-5V on arduino, by default). Check out the sample program for analogRead() command.

Digital pins are used mainly as output pins. You can connect various devices (LEDs, buzzer, LCD) on the digital pins and turn them on/off by writing HIGH or LOW on the respective pins. Check out digitalWrite() command. Before using a digital pin, you have to set it in input/output mode using pinMode() command. You can use a digital pin in input mode as well, especially when using interrupts in your code. Digital pins 2 and 3 of UNO can be used for interrupt detection. In general, you can check the status (on or off) of a device (or a switch) connected to a digital pin by using that pin in input mode. The command used is digitalRead().

Borek said:
Perhaps two things worth to add, as I have seen people confused about them:

1. Some pins can be used as either analog or digital, their use is not predefined in the hardware.

2. There is no analogWrite() command (in other words: analog pin can be used only for reading, while digital pin can be used for both reading and writing).

Very useful. Thank you!
 
ISamson said:
I have once used the analogWrite() and it seemed working fine to me...
Yes, and it generates a PWM signal on that pin.
 
  • Like
Likes   Reactions: ISamson
cnh1995 said:
Yes, and it generates a PWM signal on that pin.

Really!? The analogWrite() generates PMW. Wow!
 
ISamson said:
I have once used the analogWrite() and it seemed working fine to me...

OK, I was wrong with my wording, my mistake. What I meant was it works in a completely different way.

What you read with the analogRead() command is a value (from 0..1023 range) that tells you the value of the voltage (as @cnh1995 wrote, in reference to the voltage used to run the processor, so typically 5 V on the Arduino). When you attach a 3 V battery to the Arduino leg and you read it with analogRead() you will get something around 3/5*1023 = 614. It doesn't work the other way - when you use analogWrite() you will not get other voltage than 5 V on the output leg, rather it i will be using PWM modulation - switching the voltage on and off pretty quickly, so that it is "on" only part of the time. Net effect is that for example the LED seems to be working at half the brightness, because it really works only part of the time.
 
  • Like
Likes   Reactions: ISamson and cnh1995
Borek said:
When you attach a 3 V battery to the Arduino leg and you read it with analogRead() you will get something around 3/5*1023 = 614. It doesn't work the other way - when you use analogWrite() you will not get other voltage than 5 V on the output leg, rather it i will be using PWM modulation - switching the voltage on and off pretty quickly, so that it is "on" only part of the time. Net effect is that for example the LED seems to be working at half the brightness, because it really works only part of the time.
That's right. So if you want to use analogWrite() for D/A conversion, you'll have to use some filter circuitry to convert high frequency PWM signal into proportional dc voltage. So I believe it is easier to make one separate DAC (R-2R ladder) and use it with arduino's digital pins.

(I recently built a 6-bit R-2R DAC and generated sinewave signal (fixed magnitude- variable frequency) from it. It was fun!)
 
  • Like
Likes   Reactions: ISamson
  • #10
cnh1995 said:
(I recently built a 6-bit R-2R DAC and generated sinewave signal (fixed magnitude- variable frequency) from it. It was fun!)

Resister ladders are tricky (accuracy!) but yes, they are simple and as long as you are OK with just a few bits they can work quite good. No idea how old you are, does the name Covox ring a bell? I got one made for me by a friend of mine around 1990 :smile:
 
  • Like
Likes   Reactions: cnh1995
  • #11
Borek said:
Covox

Who/what is he/she/it?
 
  • #12
  • Like
Likes   Reactions: ISamson
  • #13
Borek said:
No idea how old you are, does the name Covox ring a bell?
22
Borek said:
I got one made for me by a friend of mine around 1990 :smile:
I'll look it up. Thanks!
 
  • Like
Likes   Reactions: ISamson

Similar threads

Replies
7
Views
3K
Replies
5
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
Replies
10
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 14 ·
Replies
14
Views
2K
Replies
5
Views
2K
Replies
80
Views
5K
  • · Replies 3 ·
Replies
3
Views
2K