Blinky - Hello World of Robotics

Kim Arnett  - May 30 '17 - - Dev Community

Hey ya'll! I hope you enjoyed my first robotics post and are ready to start your own! Orig post over at my blog

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

here: arduino.cc/en/Main/Software
*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:

1        2        3        4        5

header

  1. Verify - Compile the code to see if there are any right out failures or errors.
  2. Upload - Put the code on the Arduino. Code will begin running right away as long as there's power.
  3. New - Create a new document
  4. Open - Open an existing document
  5. Save - Save the document to your computer

Prep the Uno

  1. Plug it into your USB slot

  2. The board will light up indicating there's power

  3. 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.

  4. Should look something like

setup

Code

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;
Enter fullscreen mode Exit fullscreen mode

In the setup function we'll define the LED as an output with:

pinMode(led, OUTPUT);
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

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.

Code On Github

Original tutorial here.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .