Introduction to the Arduino Physical Computing Platform

Posted on August 19, 2010 in Hardware, Teaching
This document is intended for a workshop for visiting high schoolers this fall (October 2010). It assumes absolutely no knowledge in electronics and leaves a few things out intentionally (theres only about an hour to get through this). When the students come in there will already be Arduinos laying around with an LED connected to pin 13. They will already be connected via USB to a computer which has the Arduino IDE open.

What is Arduino and what is it good for?

Arduino is an open-source (anyone can re-make, re-use or contribute to the project) physical computing platform intended for artists, designers, hobbyists and anyone interested in creating interactive objects or environments. It can refer to the physical electronic board itself, the language used to program the board with, or the program that you actually do the programming in (called an IDE).

Using Arduino you can interface with electronics without having to know very much about electronics in general, which can take a long time to learn.

A quick look at the Arduino board

The Arduino device is based around a very small and extremely simple computer called a microcontroller (an AVR ATMega168 or 328 if you’re really curious). Code that is stored in the memory of this microcontroller runs continuously and controls all of the inputs and outputs of the device, also called pins (hence microcontroller). For example you can connect a light (LED) to one of the pins and write a program that makes electricity flow from that pin into the LED, turning it on. Actually that sounds fun, let’s do that!

Anatomy of an Arduino sketch

Programs created using Arduino are also called sketches and are actually written in an abstracted version of C. What makes the Arduino so cool is that you don’t have to actually know any C to make a program! You really only need two main sections (called methods or functions) to make a program, which you can then compile and upload to your Arduino using a USB cable. Let’s take a look at a completely empty Arduino program:

void setup() {
    // Everything you put here will be executed once
    // each time the Arduino is turned on
}

void loop() {
    // Everything you put here will be executed repeatedly
    // according to the clock speed of your Arduino
}

Writing your first Arduino sketch

1) First start up the Arduino IDE and type the exact code from the above section (or watch the instructor for what to do)

2) Tell your Arduino that you want to send electricity from pin 13 by placing the following line into your setup method

pinMode(13, OUTPUT);

3) Now turn your LED on by sending electricity from pin 13 by placing the following line in your loop method

digitalWrite(13, HIGH);

This tells your Arduino to turn on pin 13 every time the loop method is run, which happens 16 million times a second (16 mhz)! Obviously this is much faster than the human eye can perceive so it will appear that the LED is continuously on.

Running your first Arduino sketch

At any point in your development process you can click on the Verify button (looks like a Play button, just below the File menu), which will compile your code and show you where any errors are. If everything checks out OK you still have to actually transfer your program onto your Arduino board using the USB cable. Everything should be connected and configured when you come in, so once you’ve written your program and clicked on the Verify button to compile your program, hit the Upload button (second from the right) and wait until you are given the message “Successfully uploaded.”

As soon as your program has been uploaded your Arduino will reboot itself and start running your program. If everything went smoothly you should see your LED light up!

Going the extra mile (optional)

With only a few small modifications you can build on your circuit through trial and error and a little creativity. Here are some ideas for things you can try to do for fun:

1) Make your LED switch on and off by using delay(1000); and the same digitalWrite line from before (only change HIGH to LOW). This will make your program wait 1000 milliseconds (1 second) when it hits the delay line, then switch your LED off. Be sure you use delay each time you use digitalWrite, otherwise it’ll turn the LED on/off so fast you won’t even see it!

2) Plug in more than one LED to your Arduino and try to make them do cool stuff like turning on and off in patterns or at different speeds. For this you will want to learn about the difference between the two wires coming out of an LED and how to connect them to your board (the anode, or positive lead, goes to the pin you want to use while the cathode, negative lead, goes to the ground pin of your Arduino (GND))

3) Take a motor out of a kid’s toy and put it in place of the LED and see what happens. Maybe you can find a way to control the speed of the motor?

Get your hands on an Arduino and make something cool!

This project is only the tip of the iceberg! Arduino projects are popping up everywhere and have been used to control everything from robots and self-controlled RC planes to musical instruments, wearable computers and much more! There are students and professors all over the world using the Arduino as a way of cutting down on some of the boring work that can sometimes come from programming and electronics. Artists, sculptors, programmers, musicians and more are all getting in on the fun, so if you have any interest in messing around some more with the Arduino, get one yourself and start making!

Our favorite supplier is SparkFun, here’s a link to a great Arduino kit they offer.
http://www.sparkfun.com/commerce/product_info.php?products_id=9952
– It comes with a USB cable and lots of awesome sensors and parts to play with!

If you want to see more cool projects using the Arduino and learn how to make some yourself check out some of these links:
http://www.instructables.com/tag/type-id/category-technology/channel-arduino/
http://hacknmod.com/hack/top-40-arduino-projects-of-the-web/

Or just do a Google search for “arduino projects”