> For the complete documentation index, see [llms.txt](https://guides.mccaskeyrobotics.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guides.mccaskeyrobotics.org/arduino/getting-started-leds.md).

# Getting Started - LEDs

1. First find the logo like this on your computer and open it up. ![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FMv2UwmIIfXkVc6DuYAXU%2F0?alt=media)
2. Now plug in your Arduino like this: ![http://www.open-electronics.org/wp-content/uploads/2015/07/Fig11.png](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FIwoB18nwXq5ORiufQCpE%2F1?alt=media)Connect the other side to a USB port on your computer.
3. When you open up the Arduino Integrated Development Environment (IDE for short) you will need to choose Tools → Port and then make sure that you see Arduino Uno (it might not say COM16… your port might be different). ![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FWZh7zGUb7KiJbFJuxQ93%2F2?alt=media)
4. Now delete all the code in your editor and copy/paste the following code into your editor.

```
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
  Note: Most Arduinos have an on-board LED you can control. It is attached to pin 13 on the Uno.
*/

// the setup function runs once when you press reset or power the board
void setup() {
  pinMode(13, OUTPUT);
}
// the loop function runs over and over as long as the board has power
void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}
```

1. Now click the horizontal arrow to upload your code to the Arduino. When prompted to, save your file as “Blink”. **TIP:** Try to save all your projects with names that will make them easy to find later!

![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FEL3PzNSqPIOnQrqHn8TK%2Fupload.png?alt=media\&token=437cbed8-de36-4a04-a8f8-8433f077a999)

1. You should now see a little light next to a letter L blinking.

![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FA3u8psLdPdu8l38nYSL0%2F4?alt=media)

A few notes about the code... there are at least three sections to every Arduino program...

<table><thead><tr><th width="167.00000000000003" align="center">Section</th><th>Description</th></tr></thead><tbody><tr><td align="center">Variables</td><td>This is where all the data that will be used throughout the project gets declared. You will also see libraries get added here.  </td></tr><tr><td align="center">Setup</td><td>This code runs once when the board gets power or reset button gets pressed. </td></tr><tr><td align="center">Loop</td><td>This code repeats over and over without stopping until the board loses power.</td></tr></tbody></table>

![Variables](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FOwxB7xbILpQBjyFe6Yud%2Fimage.png?alt=media\&token=05ce76c0-a167-4513-b64b-3f7c226e1c1b)

![The Setup](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FLZleqJNZTsD2LZHKn9P8%2Fimage.png?alt=media\&token=e31c301d-77cd-4aac-9a34-fc2cba741759)

![The Loop](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2Fx9YKQ9BkECQz8PgSlRaq%2Fimage.png?alt=media\&token=bf9d7b0f-32dd-4de5-adf0-04256f73c9a7)

6\. Now that you have your first program running, let's wire up our own LED! You will need the following pieces…

<table data-header-hidden><thead><tr><th width="177.8249498017814">Name</th><th width="193.14971763995345">Image</th><th></th></tr></thead><tbody><tr><td>A resistor</td><td><img src="https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FDr2q1N5cMof8pAvMKjgx%2F5?alt=media" alt="" data-size="original"></td><td>This limits the amount of current flowing through the circuit. Orientation doesn’t matter. The stripes tell you the value of the resistor. Use any piece you can find.</td></tr><tr><td>An LED</td><td><img src="https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2F58ZoYKsjN4zWinJUB3g1%2F6?alt=media" alt="" data-size="original"></td><td>Only conducts current one way! The long side is positive!</td></tr><tr><td>A breadboard</td><td><img src="https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2FDt7gavUI2K8a349Kejvg%2Fimage.png?alt=media&amp;token=2de8a0d1-3c05-422e-95af-b1c4e42e85b0" alt="" data-size="original"></td><td><p>Used to make quick temporary connections while testing circuits and learning.</p><p>Red/Blue horizontal rows are connected. Vertical rows in the middle are connected.</p></td></tr><tr><td>Some wires</td><td><img src="https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2Ff5eSxmL6lbyGyls8bfMB%2F8?alt=media" alt="" data-size="original"></td><td>Conduct electricity. Don’t worry about getting the color right.</td></tr></tbody></table>

Here is the circuit. Don’t worry about exact placement… just make sure you get parts connected to one another in the same row like shown below.

![](https://3423273789-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjRgHmD322MUgRPOyqMLh%2Fuploads%2Fp5vuv1exmss7cY1S6Rip%2F9?alt=media)

If wired correctly, the same code should be making your LED blink as well.

Take a look at this [slideshow](https://docs.google.com/presentation/d/1ofcswVlP0cLhzlGuUpuu2McH98r1ZOxTLH6aS7qHJ-0/edit?usp=sharing) for an explanation of the functions used in the sketch.

{% embed url="<https://docs.google.com/presentation/d/1ofcswVlP0cLhzlGuUpuu2McH98r1ZOxTLH6aS7qHJ-0/edit?usp=sharing>" %}

A few things to try…

* Change the value of ledPin to some other number between 3 and 12 and re-upload the code. You should notice the LEDs are not blinking anymore. Now move the red wire to whatever pin number you chose. Notice the LED is blinking again.
* Change the speed of the blinking by adjusting the delay time variable. This value is used in the delay function to control how many milliseconds the program waits until a new command is given
* Flip the orientation of the LED. Notice that it stops blinking. This proves to you that LEDs only conduct electricity in one direction.
