Writing Arduino Code
Make the LED Turn On
10 minStudent plan
Your first real sketch. Configure a pin as an output and drive it high, written by you, checked line by line.
After this lesson you can
- Write a sketch that turns an LED on
- Say why pinMode has to come first
- Read what each line of a two-line sketch actually does
The whole job, in two lines
Turning an LED on is two instructions in the right places.
In setup(), declare the pin an output:
pinMode(13, OUTPUT);
In loop(), drive it high:
digitalWrite(13, HIGH);
That is it. The pin goes to 5 V, current flows through the LED and its series resistor to ground, and the LED lights. Because loop() repeats forever it is set high over and over, which is harmless, writing HIGH to a pin that is already high changes nothing.
In the full lesson
- The whole job, in two lines
- Why pinMode matters
- Now write it
This lesson comes with the Student plan. The first module of Programming is free.