-
Notifications
You must be signed in to change notification settings - Fork 2
Arduino basic digital output
The typical way of programming an Arduino pin as a digital output is to set its mode as OUTPUT in the setup() function, and then use digitalWrite() within the loop().
const static int MY_PIN = 13;
setup() {
outputMode(MY_PIN, OUTPUT);
}
loop() {
if (...) {
digitalWrite(MY_PIN, HIGH);
} else {
digitalWrite(MY_PIN, LOW);
}
For most Arduinos, it is customary to use pin 13 as a status output, as there is an amber LED connected to PIN 13 on the Arduino Uno board. This is not necessarily true for other Arduino-compatible boards, and it may be necessary to place a LED at the PIN.
When connecting a LED to an MCU pin, it is important to make sure that the LED does not load the MCU pin too much, i.e. that it does not draw or supply too much current. To limit the current, the typical way is to place a serial resistor. 100 Ohms is a good basic resistor value for 3.3V logic systems; if you don't understand why, please consider that the voltage drop over a typical basic LED is about 2 volts (3 volts for blue LEDs) and that a MCU pin can typically sink or supply at most 20-30 mA, preferably less. Hence, you should place such a resistor that it creates at least 1V voltage drop at 20mA.