Introduction
We write HIGH or LOW to output pins to turn devices like LEDs or motors on or off.
We write HIGH or LOW to output pins to turn devices like LEDs or motors on or off.
digitalWrite(pinNumber, HIGH); digitalWrite(pinNumber, LOW);
pinNumber is the number of the pin you want to control.
HIGH means turning the pin on (usually 5V or 3.3V), LOW means turning it off (0V).
digitalWrite(13, HIGH);digitalWrite(8, LOW);This program makes an LED connected to pin 13 blink on and off every second.
#include <Arduino.h> void setup() { pinMode(13, OUTPUT); // Set pin 13 as output } void loop() { digitalWrite(13, HIGH); // Turn LED on delay(1000); // Wait 1 second digitalWrite(13, LOW); // Turn LED off delay(1000); // Wait 1 second }
Always set the pin mode to OUTPUT before writing HIGH or LOW.
Use delay() to create visible changes like blinking.
HIGH and LOW correspond to voltage levels, so check your board's voltage.
Use digitalWrite(pin, HIGH) to turn a pin on.
Use digitalWrite(pin, LOW) to turn a pin off.
Set the pin as OUTPUT first with pinMode(pin, OUTPUT).
pinMode(pin, OUTPUT), which configures the pin for output.digitalWrite(pin, value) sets the pin voltage HIGH or LOW.HIGH to turn the pin ON. The correct syntax is digitalWrite(5, HIGH);.pinMode(3, OUTPUT); digitalWrite(3, LOW); digitalWrite(3, HIGH);
pinMode(3, OUTPUT);.pinMode(7, OUTPUT); digitalWrite(7, HIGH) digitalWrite(7, LOW);
digitalWrite(7, HIGH) is missing a semicolon at the end.pinMode(7, OUTPUT); and digitalWrite(7, LOW); are correct syntax.pinMode(10, OUTPUT); to configure pin 10 for output.digitalWrite(10, HIGH); then delay(1000); to wait 1 second, then digitalWrite(10, LOW); and delay again.Pass the test and this pattern moves unknown