Electronics for iPhone Developers Tutorial: Create an Arduino Traffic Light!
- What is an Arduino?
- Why is this something interesting to iOS developers?
- What is this tutorial about?
- Materials Needed
- Hey! I’m just an iOS developer. What’s with all that hardware?
- Let’s watch the video!
- Wait – how did that work?
- Calculating Resistance
- The Resistor of Many Colors
- The Final Piece
- Where to Go From Here?
Every day while going to school, work, or anywhere else you see traffic lights. They are everywhere, and they tell you when to stop and when to go.
Traffic lights are POWERFUL! But have you ever wondered how are they built and programmed?
It’s easy to build up traffic lights. I mean.. the software part.
A simple program can simulate that, but the real deal is how can you integrate this into hardware. And that’s exactly what we’re going to demonstrate in this tutorial!
This tutorial is for iPhone developers who want to learn more about how electronics work. You’ll use an open-source micro-controller called the Arduino to make a “traffic light” with red, yellow, and green LEDs. You will then write a program to control the traffic light.
In the process, you’ll get a good grounding in electronics and how the Arduino works. Then in a follow-up tutorial, you’ll see how you can control an Arduino device from your iPhone!
Keep reading to find out more about what an Arduino is, what materials you’ll need for this tutorial, and finally – building your own traffic light!
What is an Arduino?
The Arduino is a popular open-source single-board micro-controller.
Okay wait! Lots of new terms! An Arduino is:
- Open-source: An Arduino can be purchased preassembled, or built by hand with some instructions that are available online. All of the software that runs on the Arduino is open-source (i.e. free!)
- Single-board: The whole thing is on one board that can fit in your hand.
- But what wait a minute: What is a micro-controller?
A micro-controller is a small computer on a single integrated circuit. It contains:
- A processor.
- Programmable input/output peripherals.
This is a lovely picture for the Arduino family that consists of different micro-controllers models.
Why is this something interesting to iOS developers?
- As an iOS developer, you may think that all what you can do with an iOS device is developing an app. Well, you’re wrong!
- Your iOS device can control hardware. You could create an app that turns on the lights, changes the TV channel, or maybe turns off the fan. The possibilities are unlimited.
- One way you can control hardware is with the help of the Arduino! Let’s learn how.
What is this tutorial about?
This is a 2 parts tutorial that aims to give you an overview of how to control hardware through your iPhone.
- The first tutorial shows you how to build up traffic lights with an Arduino Uno (A member of the Arduino family), just to introduce you to the Arduino and how to program it.
- The second tutorial is where things get serious. You’ll learn how to control a LED through your iPhone, with the help of the Arduino Uno & the Ethernet Shield (a module that can be added onto the Arduino Uno to make it connect to the internet).
Let’s start with building up traffic lights.
This is a tutorial on hardware, so to go through this tutorial you will obviously need some hardware to work with :]
You will need the following hardware to proceed with this tutorial:
- Arduino Uno.
- 200 or 330 ohm resistor (x3).
- LED (1 red, 1 amber, 1 green).
You can get most of these materials from any electronics shop. As for the Arduino Uno, here’s a link to their official distributors page.
Note from Ray: When testing out this tutorial, I ended up buying all of my components from Sparkfun Electronics. I bought:
- A Sparkfun Inventor’s Kit. This contains almost everything you need for this tutorial and the next, along with a fun instruction book with other fun projects you can try.
- A green LED (not included in the kit), which you need for this tutorial.
- A Arduino Ethernet Shield which you need for the next tutorial.
In total it ended up costing $141.25. A decent chunk of change, but it provides tons of hours of fun and learning!
Hey! I’m just an iOS developer. What’s with all that hardware?
Ok, don’t panic. I’m gonna give you an overview of all that hardware.
You can skip this part if you already have a background about all that stuff.
A breadboard looks like the picture to the right. It’s just a way to allow you to easily connect wires. You see, it consists of hundreds of holes, where wires can fit in.
Some holes are connected to each others and some are not. The easiest way to explain which holes are connected to which is a picture – so check it out, on the right.
The wires are used to connect the LEDs with the resistors on a breadboard.
But what is a resistor?
You can think of a resistor as a little thing that protects the LED from burning out due to excess electricity by absorbing some of the current that is passing through.
Now we come to the most important piece, which is of course the Arduino Uno.
You can think of it as a small computer that continuously executes a small program as long as it is on.
To turn it on, connect it to your computer with a USB cable, or give it external source of power (9v battery).
You’re gonna write a short “C language” program that simulates a traffic lights system, and then upload it to the Arduino Uno.
For those iOS developers that don’t know how to program in C, don’t worry it’s pretty easy and is very similar to programming in Objective-C.
C is basically objective-C without the Object-Oriented part. So all commands are just the same starting from the datatypes (int, float, char, ..), passing through the conditional statements (if, if else, switch, …), continuing with counter & logic controlled loops such as the (for & while loops), and ending up with functions!
Everything is just the exact same way, so you’re gonna find it so easy to understand.