Tutorial 2: Control a LED

Controlling a LED is one of the simplest things you can do with an Arduino. Only a few common components are needed to get your software changing your physical environment. In this tutorial I will shed a little light on how to digitally turn a device on and off.

DIFFICULTY
EASY
CIRCUITRY KNOWLEDGE
LITTLE
C++ PROGRAMMING
LITTLE
ABOUT
0
MINUTES
  • How to build a simple LED circuit
  • How to use the digitalWrite Arduino command
You can copy / paste the code below if you’re having issues with typos or want a shortcut. However I recommend that you follow along in the tutorial to understand what is going on!


int x = 0 ;
int LED_Pin = 13 ;

void setup() {
  Serial.begin(9600) ;
  pinMode(LED_Pin, OUTPUT) ;
}

void loop() {
  x += 1 ;
  Serial.print("This is loop iteration ") ;
  Serial.println(x) ;

  digitalWrite(LED_Pin, HIGH) ;
  delay(500) ;
  digitalWrite(LED_Pin, LOW) ;
  delay(500) ;
}