Blinky - Hello World of Robotics
Kim Arnett May 30 '17
This is an introduction to your Arduino Uno. I am still new to robotics myself, but together we will prevail. I hope to pass on what I know and you can pass on what you know, and soon we'll all be experts, right?!
Whenever you're learning a new software platform, you create a "Hello World" application. Well, the equivalent in the hardware world is called "Blinky". This tutorial is an introduction to the Arduino platform. I'll be using the Arduino Uno R3 and an LED bulb that came with my learn to solder kit.
Download the Arduino IDE
*This tutorial is using Arduino 1.8.1
As a beginner, I had better luck using on Windows 10 platform than I did my 2015 MacBook Pro. I ran into a driver problem on the Mac and possibly downloaded a Japanese virus while trying to fix it. Oops.
Quick IDE Intro:
- Verify - Compile the code to see if there are any right out failures or errors.
- Upload - Put the code on the Arduino. Code will begin running right away as long as there's power.
- New - Create a new document
- Open - Open an existing document
- Save - Save the document to your computer
Prep the Uno
Plug it into your USB slot
The board will light up indicating there's power
Find an LED - Put the positive end (Longest leg / smallest piece inside the LED) into pin 13. Insert the negative end into the GND (Ground) pin.
Should look something like
When you create a new file, or the default one, you'll see two methods: Setup and Loop.Setup is run exactly one time at the beginning of the program by the hardware, than the continuous code goes in the, you guessed it, loop function.At the beginning of the file we'll make a reference to the pin our LED is in:
int led = 13;
In the setup function we'll define the LED as an output with:
Lastly in the loop function, we'll tell the light to blink. We send a signal to the pin (13), which will be either HIGH or LOW. This signal corresponds to the voltage given to that pin. HIGH, the light will turn on, and LOW the light will turn off. We also want to delay, wait, between turning the light on and off. Here's the code for the loop function:
digitalWrite(led, HIGH); delay(5000); digitalWrite(led, LOW); delay(1000);
Save -> Verify -> Upload
Press the Verify button at the top (Checkmark). This will sweep through your code and make sure no outstanding issues exist.
Note: If you get this error on Windows (ser_open(): can't open device "\.\COM[x]")
Open Device Manager ->Ports -> and determine what port the Uno is on. Then Go to Tools -> Port -> then select the correct port it's expecting.
If everything comes out good, select the upload button.
Once the program compiles the Uno will refresh and your program should now be running. The light will be on for 5 seconds, and off for 1 second.