We Speak PC
  • Home
  • Resources
  • Gallery

  •              Allen@wespeakpc.com
                 Call us: 972-704-5114

Arduino Programming and Electronics

Post Image

Project 2: Blinking an external light

Remember we said the Arduino digital pins can be used as both inputs and outputs.  So you can change your blink program to turn on an LED that is plugged into your Arduino.

This is where we bring your idea from the light bulb in your head to a light bulb outside your head.  later we can change that light bulb to a color changing light bulb, a motor…..A ROBOTIC HAND!!!

Please remember to follow any and all saftey rules when dealing with electricity.


Purpose:

To learn how to add external hardware to your Arduino.  This is an opportunity to  to learn about various electronic components as well.


Materials Needed:

1. Arduino Uno

2. Breadboard

  

inner Breadboard

This is what the inside of a bread board looks like. You can see the rows of pin connections separated by spaces.

 

3. LED

 

 

4. 300 ohm resistor

Safety:

Remember you are now working with electronics.  BE SAFE!!!
Before letting any electric current run through your project, make sure each component is not touching or near any other components.  Trim all ends long enough to be able to work on the breadboard and be flush to the breadboard whenever possible.

Here is how you need to wire it up.

How an engineer sees it:

Wiring explained:

1. Remember for electricity to flow, it has to have a place to go.  So there is a start (Or source like a battery) and an end (in this case the connection to Ground (GND). If you miss a connection the electricity won't flow. If your LED is plugged in wrong the electricity won't flow.

2. The digital pins acting like an output means electricity is coming out of there to whatever is plugged into it. In this case it is the Resistor.

3. The Resistor doesn’t care if the electricity flows from one side or the other. Its job is to resist the amount of electricity that comes in one end and out the other so that we don’t burn or explode our project too easily.

4.  The LED DOES CARE how you connect it.  It has a positive and negative side remember? In this case you want the longer leg with the Resistor and the shorter end to ground.

5. Finally, from the ground of the breadboard to the ground (GND) of the Arduino.

 

THE PROJECT: (LEDBLINK)

Plug in your Arduino and let’s start your first program.

  1. Double-click the Arduino icon on your desktop.
  2. Click on file, Save as , then give it the name ExtLEDBlink.
  3. Copy the following in red only (Remember to be exact. Even the smallest mistake might make your program not work).  We will break it down after you are done.

/*
My Project Name:  LEDBlink
What my project does: Makes my idea wink (or blink) at me by turning an LED light on and off
*/
int led = 10; // We could have used pin 13.
void setup ( ) {
pinMode  (led, OUTPUT);
} /* END SETUP */
void loop (){
digitalWrite (led, HIGH);
delay(500);
digitalWrite (led, LOW);
delay(500);
}

 

*******************************
**Program Breakdown*********
*******************************

Did you notice anything?!?!  Very similar to your first program right!? No real explanation needed other than the electronics.

 

Now it is time to see if it works.  Click in the check mark on the top left. If there are any errors it will start pointing them out to you.  if you just can’t figure it out please let me know and I will help you out.  once it says it is done, then click on the right arrow button next to it to copy your program from your computer to the Arduino board.

YOUR TURN!!!!

Activities:

  1. Can you adjust the program AND the hardware to turn on more than one LED?
  2. What happens if you use a 240 ohm resistor (red, purple, brown, Gold stripe resistor)?  Do you notice a difference in brightnes?  Why?
  3. Given an RGB LED (Red, Green Blue Light Emitting Diode) picture and schematics below, can you redesign your program AND hardware to make a stop light? (*** Try drawing the different symbols of each part, then cut it out and move them around to help you ***)

Eventually I will show you how not to take up so many pins with multiple LEDs.  For now focus on learning the basics.