Académique Documents
Professionnel Documents
Culture Documents
BREADBOARD EDITION
By allhandsactive in TechnologyArduino
109,623
56
11
DownloadFavorite
About: Dream It! Build It! Teach It! AHA is a community workspace with shared tools and knowledge
for Coders to Crafters to Makers to Hackers. We are among the oldest continually operating
Makerspaces in the nati... More About allhandsactive »
Build a simple Arduino powered Traffic Light with us! This instructable
is meant to walk you through almost every step, but there are a few
assumptions. Read over the intro and the first step to make sure you
are fully prepared! This is the breadboard version, a more realistic
traffic light will be generated soon. Please leave comments - tell us
if things are confusing!
Supplies Needed:
1 x Computer with Internet Access
1 x Arduino Uno
1 x USB A/B Cable for connecting the Arduino to your PC
1 x Breadboard (Half-Size, with Voltage Rails)
1 x Red LED
1 x Yellow LED
1 x Green LED
3 x 100 Ohm Resistors (Brown Black Brown)
4 x Breadboard Wires (22 AWG, approx. 6+ inches in length)
Missing Something?
- Check out hackerspaces.org for a local place for tools, supplies, etc.
- Near Ann Arbor, MI? We have all the supplies needed to do this
instructable at our hackerspace "All Hands Active"
- Radioshack, AdaFruit, SparkFun, Jameco, are just a few resources
that will have all the needed items.
2 More Images
Situate your Arduino on the left, and your breadboard on the right! If
you have not used a breadboard before, it's a bit like playing
Battleship. If you haven't played Battleship, that's okay : )
Onward!
Breadoards are great, and they come in all shapes and sizes. They
make it easy for you to prototype an electrical circuit without having to
solder connections together. Don't worry if yours is a little different. If it
comes with voltage rails, then it should be pretty easy to follow along.
If it doesn't, you will have to figure out an alternate way to supply
power.
Voltage rails are the two columns that run along the left and right sides
of the breadboard pictured above. These are used to make it easier to
bring power to various points throughout your breadboard. We will
ground all of our connections along the right, or "blue" labeled voltage
rail. In the step above, w connect a black wire running from the
"GND" pin of the Arduino, to a voltage rail..
Digital, Analog The Arduino has 14 Digital pins, and 6 Analog pins. A
Digital pin can operate in two ways: On, also known as "HIGH", and
Off, otherwise known as "LOW". When a Digital Pin is set to On, 5
volts of electricity are running through it. When it's set to Off, no
voltage runs through it. This will make it easy for us to turn an LED on
or off. These pins are represented as "DIGITAL", pins 0 through 13 at
the top right of the Arduino pictured above.
Resistors do exactly as they say, they resist! But what? Electrons! Too
much power, or current and we can ruin our LED, so we include a
resistor in line with it. We measure resistance in units called "Ohms".
The resistor we are using provides 100 Ohms of resistance. The
colored strips Brown (1), Black (0), Brown (add 1 more 0), are how we
identify what the value of our resistor is.
Follow the images to complete this step, then move on to the next
step to get your LED turned on!
Add TipAsk QuestionCommentDownload
Step 3: Turn on Your Green LED
You will write your code in two basic sections: the "setup" section and
the "loop" section. These sections are known as functions. We will
learn more about what a function is later on!
The Setup function runs once when the arduino is turned on.
The Loop function runs continuously after the setup function runs
once.
Second, you must tell the pin to be in HIGH mode. HIGH mode sends
a high electrical signal through the pin. LOW mode sends a low
electrical signal. You can set your pin on high mode by using
the digitalWrite function.
// basic functions
voidsetup()
{
// setup LED modes
// we're specifying that we're going to send information to this LED
pinMode(3, OUTPUT);
}
voidloop()
{
// High turns things on
digitalWrite(3, HIGH);
}
Variables allow you to give names to things. There are lots of different
types of variables.
For instance: int GREEN = 3; has a type of int, a name of GREEN, and a
value of 3.
Anywhere you want to use a "3," you can now write "GREEN."
* Remember: You have to make a variable before you can use it!
* Variables exist in different areas known as scopes. A scope is the
area between a starting curly bracket { and its matching ending curly
bracket }. In our case, we're going to declare the variables all at the
top of the code. These variables are known as global variables.
A global variable can be used anywhere in the document.
Example:
// variables
int GREEN = 3;
// basic functions
voidsetup()
{
// setup LED modes
// we're specifying that we're going to send information to this LED
pinMode(GREEN, OUTPUT);
}
voidloop()
{
// High turns things on
digitalWrite(1, HIGH);
}
The Arduino library provides another useful little function called delay.
The delay function takes in the length of the delay -- an int (integer)
value in milliseconds.
Example:
// variables
int GREEN = 3;
int DELAY = 1000;
// basic functions
voidsetup()
{
// setup LED modes
// we're specifying that we're going to send information to this LED
pinMode(GREEN, OUTPUT);
}
voidloop()
{
// High turns things on
digitalWrite(GREEN, HIGH);
delay(DELAY);
// low turns things off
digitalWrite(GREEN, LOW);
In this step we will be adding a second LED. You will be 2/3rds of the
way to having a completed Traffic Signal!
For this step, you will need:
1 x 100 Ohm Resistor (Brown Black Brown)
1 x Breadboard or Jumper Wires (22 awg, approx. 6" in length)
1 x Yellow LED
Add TipAsk QuestionCommentDownload
Step 7: Make Both LEDs Blink!
You want to set up your lights so that instead of just blinking on and
off your Green LED, you now switch between LEDs.
For this step, repeat the same steps as the step to set up the Green
LED.
Can you set it up so that your Green LED stays on for 5 seconds and
your Yellow LED for only 2 seconds?
Example:
// variables
int GREEN = 3;
int YELLOW = 4;
int DELAY_GREEN = 1000;
int DELAY_YELLOW = 1000;
// basic functions
voidsetup()
{
// setup LED modes
// we're specifying that we're going to send information to this LED
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
}
voidloop()
{
// High turns things on
// Low turns things off
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
// how long we want the green led on
delay(DELAY_GREEN);
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
// how long we want the yellow led on
delay(DELAY_YELLOW);
}
We'll be wiring up your final LED in this step. Hopefully you have a
good idea at this point how we'll go about doing this! Mouse-over the
caption box in the image for details on where to connect everything.
Now set it up so that your lights go from Green --> Yellow --> Red!
For this step, set up the Red LED the same way as the Yellow LED.
Can you set it up so that your Green LED stays on for 5 seconds and
your Yellow LED for 2 seconds and then your Red LED for 5
seconds?
Example:
// variables
int GREEN = 3;
int YELLOW = 4;
int RED = 5;
int DELAY_GREEN = 1000;
int DELAY_YELLOW = 1000;
int DELAY_RED = 1000;
// basic functions
voidsetup()
{
// setup LED modes
// we're specifying that we're going to send information to this LED
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
}
voidloop()
{
// High turns things on
// Low turns things off
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
// how long we want the green led on
delay(DELAY_GREEN);
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, LOW);
// how long we want the yellow led on
delay(DELAY_YELLOW);
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
// how long we want the red led on
delay(DELAY_RED);
}
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
Functions are just like variables. Once your create them, you can
replace the sets of instructions you put into the function in the rest of
your program.
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
Into this:
void loop()
green_light();
void green_light()
{
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
* Remember: You have to make a variable before you can use it!
* Variables exist in different areas known as scopes. A scope is the
area between a starting curly bracket { and its matching ending curly
bracket }. In our case, we're going to declare the variables all at the
top of the code. These variables are known as global variables.
A global variable can be used anywhere in the document.
Example:
// variables
int GREEN = 2;
int YELLOW = 3;
int RED = 4;
// basic functions
voidsetup()
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
voidloop()
green_light();
delay(DELAY_GREEN);
delay(DELAY_YELLOW);
delay(DELAY_RED);
void green_light()
digitalWrite(GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
void yellow_light()
void red_light()
//