001 Arduino-For-Beginners-Pins-Recap
001 Arduino-For-Beginners-Pins-Recap
Digital Pins
Digital pins are used to read/write digital values (which are binary values: HIGH/LOW or 1/0).
For any given digital pin on the Arduino, you can decide to set it as INPUT or OUTPUT, with the
pinMode(pin_number, mode) function.
Then:
- For INPUT pins, you can read the state of the pin with digitalRead(pin_number)
- For OUTPUT pins, you can write the state of the pin with digitalWrite(pin_number)
Note:
- For some of the digital pins (with a “~” symbol next to the number on the board), you can
use a PWM with the function analogWrite(pin_number, value between 0..255).
Analog Pins
Analog pins are used to read analog values (variation of the voltage between 0 and 5V).
You don’t need to set up the mode for an analog input pin, it’s already set as INPUT.
Then:
- To read an analog value, you can use analogRead(pin_number), which will convert the
analog signal into a digital value between 0 and 1023, that you can use in your code.
Or:
- You can use any analog pin as a standard digital pin. Very handy when you’ve already
used all digital pins. To do that, don’t forget to set the mode for the pin with
pinMode(pin_number, mode). Note that you can’t use the PWM functionality on analog
pins.