- #1
ISamson
Gold Member
- 438
- 151
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!
Thanks!
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).
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).
Yes, and it generates a PWM signal on that pin.ISamson said:I have once used the analogWrite() and it seemed working fine to me...
cnh1995 said:Yes, and it generates a PWM signal on that pin.
ISamson said:I have once used the analogWrite() and it seemed working fine to me...
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.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.
cnh1995 said:(I recently built a 6-bit R-2R DAC and generated sinewave signal (fixed magnitude- variable frequency) from it. It was fun!)
Borek said:Covox
22Borek said:No idea how old you are, does the name Covox ring a bell?
I'll look it up. Thanks!Borek said:I got one made for me by a friend of mine around 1990
The main difference between analog and digital pins on an Arduino board is the type of signal they can read or write. Analog pins can read or write continuous analog signals, while digital pins can only read or write binary signals (0 or 1).
The number of analog and digital pins on an Arduino board varies depending on the model. Most Arduino boards have 6 analog pins labeled A0-A5 and 14 digital pins labeled 0-13. However, some models may have more or fewer pins.
No, you cannot use a digital pin as an analog pin or vice versa. Each pin has a specific purpose and function, and they are not interchangeable. Attempting to use a pin for a different purpose may result in incorrect readings or damage to the board.
Analog signals are commonly used in sensors such as temperature sensors, light sensors, and potentiometers. Digital signals are used in devices such as switches, buttons, and LEDs.
The pins on an Arduino board are usually labeled to indicate whether they are analog or digital. Analog pins are labeled with the letter A (e.g. A0, A1, A2), while digital pins are labeled with a number (e.g. 0, 1, 2). You can also refer to the pinout diagram for your specific Arduino board.