Part 1: Arduino stoplight setup and code

Your mission is to setup the board and Arduino to match the photos below.  Then copy/paste the code into Arduino.  Compile and upload.  Troubleshoot.

Here’s what you need:
Arduino
black cable
breadboard
8 jumper wires
4 red-red-brown resistors
1 brown-black-orange resistor
1 red LED
1 yellow LED
1 green LED
1 pushbutton

Then take the the code and comment each line to tell us what is happening. Comment like this:

//this tells the yellow light to turn on

The breadboard/Arduino controller setup

arduinoswitch1arduinoswitch2

and the code – copy paste ALL of this into a new sketch in Arduino:

2015Arduinostoplight1_bbvoid setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(2, INPUT);

}

void loop() {
if(digitalRead(2) == HIGH){

digitalWrite(11, LOW);
digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(3000);
digitalWrite(13,LOW);
digitalWrite(11,HIGH);
} else{
digitalWrite(11, HIGH);
delay(100);
}

}

Leave a Reply

Your email address will not be published. Required fields are marked *