Controlling 2 LEDs

Goal 

The goal is to build a circuit with 2 LEDs. Each LED has to be able to be controlled independently using the Arduino.

Circuit

For this to work you have to build 2 independent circuits, one for each LED. Notice how both LEDs share the same ground (GND) but the plus side of each LED is connected to a different digital port on the Arduino. It’s important that each LED is connected to its own digital port on the plus side, this is the only way to control each LED individually. When pin 7 is set to HIGH current will flow through the LED and the resistor to ground and it won’t have any effect on the LED connected to pin 8.

Screen Shot 2018-09-11 at 10.30.47

CodeScreen Shot 2018-09-11 at 10.58.53

Setup is used to declare pin 7 and pin 8 as outputs so we can use them to control the LEDs.

The loop is used to make the LEDs blink, when the first LED is on, the second LED is off and vice versa. LEDs are on for half a second before switching. There is no delay between turning off pin 7 and turning on pin 8, this makes it seem like it’s happening at the same time.

Have a good look at the code and make sure you understand what happens when the code ends the loop and starts over again.

Extra

  • Make both LEDs blink at the same time
  • Add more LEDs and make patterns
  • Add more LEDs and make them go on and off randomly
  • Make a set of (safe) traffic lights

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s