0
0
Embedded Cprogramming~5 mins

Writing HIGH and LOW to output pins in Embedded C

Choose your learning style9 modes available
Introduction

We write HIGH or LOW to output pins to turn devices like LEDs or motors on or off.

Turning an LED on or off in a simple circuit.
Controlling a buzzer to make sound or stay silent.
Switching a relay to control a bigger device.
Sending signals to other electronic parts.
Syntax
Embedded C
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).

Examples
Turn on the device connected to pin 13.
Embedded C
digitalWrite(13, HIGH);
Turn off the device connected to pin 8.
Embedded C
digitalWrite(8, LOW);
Sample Program

This program makes an LED connected to pin 13 blink on and off every second.

Embedded C
#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
}
OutputSuccess
Important Notes

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.

Summary

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).