Lesson goal: Turn an LED on or off using an Arduino

Previous: Make an (x,y) plot | Home | Next: Turn on LEDS with mouse

This lesson will show you how to turn an LED on the Arduino on and off.
pinmode(pin,direction)
digitalwrite(pin,level)
Move the mouse over a dotted box for more information.

Now you try. Can you figure out how to turn the LED on? Off?

Type your code here:


See your results here:

If you have your own LED, insert it directly into the Arduino between pin 13 and GND. If you don't have an LED, that's OK. There's a orange LED built right onto the Arduino board, which is connected to pin 13.

If inserting your own LED, be sure the longer lead is inserted into pin 13, and the shorter into GND. Alternatively, be sure the lead closest to flat edge on the plastic case is inserted into GND and the other into pin 13.

This code will configure pin 13 as an output pin and then send a digital level to it. If you send a HIGH to 13, you should see the yellow LED on the Arduino, near pin 13 turn on. If you send a LOW, the LED should go off.

Here is what your Arduino assembly might look like for this lesson:

Note if you don't have an LED, pay attention to the yellow square labeled "L" on your Arduino (also shown in this image). Dismiss.

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.