Explore Upcoming Workshops Near You and Ignite Your Passion for Innovation . Reserve a Seat today!

tect-corner-img

Moonpreneur Traffic Light Kit

The Moonpreneur Traffic Light kit will help you understand how traffic lights work in a fun and creative way. Let us get our hands on this kit and understand how it works. We are going to have lots of fun working and learning on the traffic light kit today.  

Age: 8 – 10 Yrs.

Do you ever wonder how traffic lights work?

The Moonpreneur Traffic Light kit will help you understand how traffic lights work in a fun and creative way, let us get our hands on this kit and understand how it works. We are going to have lots of fun working and learning on the traffic light kit today.

Unpacking the Kit

List of Items

Here is the list of items you will find as soon as you unpack the kit.

Controller Board  – TL001

USB Cable – TL002

Mooncard – TL003

Traffic Light  Board x 1 – TL004

Connection Wires – TL005

Bread Board – TL006

LEDs ( 3 Quantity) – TL007

Resistors 5x – TL008

Push Button – TL009

User Manual – TL010

traffic-light-manual

Let’s Start

Step 1: Open the kit and you should be able to  find the Controller board ( TL001 – It is an Arduino Nano Compatible Board) and the Mooncard – (TL003) . The Controller board has the Software that will control the traffic light.

Step 2: Insert the Controller Board ( TL001) in the Mooncard (TL003) as indicated. Match the drawing in the Mooncard, aligning the connectors and pins, otherwise it will not work

Step 3 : Insert the combination of the Controller Board ( TL001) and Mooncard ( TL002) in the Bread Board( TL006) as indicated. Ensure that the controller board’s connector is at the edge of the breadboard and the pins are aligning as per the diagram.

Step 4 : Find the Traffic Light Board (TL004) in the kit, it has 4 colored pins at one end. In the next step we will be connecting the 4 pins with the controller board using the provided wires

Step 5: Insert the Traffic Light Board (TL004) in the breadboard, as indicated.

Step 6: Use a black (or any other color) wire and insert one end to an empty hole in the breadboard in front of the black mark on the controller board.

Insert the other end of the wire in the empty hole on the breadboard in front of the traffic light board’s black pin.

Make sure the end of the wire is inserted in front of the black color of the controller board.

Step 7: Repeat the previous process for the remaining pins.

The Red wire connects to the Red color on the controller board.

The Yellow wire connects to the Yellow color on the controller board.

The Green wire connects to the Green color on the controller board.

Wire Traffic Board Controller Board
Red Red Red
Yellow Yellow Yellow
Green Green Green
Black Black Black

 

This is the scheme of connection, note that the connection has to be made through the breadboard.

Step 8 : Insert USB Cable into the connector of the controller board. Connect the other end of the cable in the USB Port of your computer or laptop.

Did you see the traffic lights glow in a particular order?

Have you thought about what was inside the Controller board that made the traffic lights work? There is software inside the controller that can be changed, in order to show different results. Does that make you more curious? Do you wish to make changes in the Software? like changing the time period for which the Green light glows? Refer the next section for 10-13 year old’s.

Age: 10 – 13 Yrs.

Do you ever wonder how a traffic light works and the software behind it ?

The Moonshot Jr Traffic Light kit will help you understand how traffic lights work in a fun and creative way, let us get our hands on this kit and understand how it works. We are going to have lots of fun working and learning on the traffic light kit today.

Let’s Start

Step 1 : Insert the Controller Board ( TL001) and Traffic Light Board (TL004) in the Bread Board( TL006). Ensure that the USB connector is at the edge of the Bread Board  and the pins are aligning, as shown in the image below.

Step 2 : Use a black (or any other color) wire and insert one end to an empty hole in the breadboard in front of the GND pin of the controller board.

Insert the other end of the wire in the empty hole on the breadboard in front of the traffic light board’s black pin.

Note: Make sure the end of the wire is inserted in front of the GND pin of the controller board.

Step 3 : Repeat the previous process for the remaining pins.

The Red wire connects to pin D4 of the controller board.

The Yellow wire connects to pin D3 of the controller board.

The Green wire connects to pin D2 of the controller board.

 

Wire Traffic Board Controller Board
Red Red D4
Yellow Yellow D3
Green Green D2
Black Black GND

 

This is the scheme of connection, note that the connection has to be made through the breadboard.

Step 4 : Insert USB Cable into the connector of the controller board. Connect the other end of the cable in the USB Port of your computer or laptop. You will notice the traffic light starts working.

Have you thought about what was inside the Controller board that made the traffic lights work? So far you have just learned how to connect the components and make the Traffic Light work, in the following steps you will learn about the coding part of the Traffic Light.

Step 5: Go to https://www.arduino.cc/en/software and download the latest version of Arduino IDE, depending on which system you use (Windows, Mac).

Step 6 : After Installing the Arduino IDE, connect the Arduino board to your computer. After starting the Arduino IDE. Click on tools to reveal this menu:

  • Hover on Board, Select Arduino Nano
  • Select ATmega328P(Old Bootloader) as the Processor.
  • Select the correct Port ( e.g. COM4).
  • Make sure the Programmer is set to AVRISP mkII .

Step 7 : Copy the code given below

// C++ code
//Define Pins to avoid confusion
const byte GREEN = 2;
const byte YELLOW = 3;
const byte RED = 4;

//Initialize the pins (give an initial value)
void setup()//The setup function defines the initial state of the Arduino upon boot and runs only once.
{
  pinMode(GREEN, OUTPUT);//pin number 8 Green) configured for output
  pinMode(YELLOW, OUTPUT);//pin number 7 (Yellow) configured for output
  pinMode(RED, OUTPUT);//pin number 2 (Red) configured for output
}
//Run code (write code that will keep on executing throughout the loop)
void loop()
/*The loop describes the main logic of your circuit, runs again and again as its name suggests,
and is executed after the setup has finished executing.*/
{
  digitalWrite(RED, HIGH);//When Set to HIGH current is supplied to the pin (5v) and the LED lights up
  digitalWrite(YELLOW, LOW);//When Set to LOW current supplied to the pin is 0v and the LED doesn't light up
  digitalWrite(GREEN, LOW);
  delay(4000); // 1 second = 1000 milliseconds, wait for 4 seconds.
  digitalWrite(GREEN, HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(YELLOW, LOW);
  delay(4000); // Wait for 4000 millisecond(s)
  digitalWrite(YELLOW, HIGH);
  digitalWrite(GREEN, LOW);
  digitalWrite(RED, LOW);
  delay(1500); // Wait for 1500 millisecond(s)
}

 

Step 8 : Paste the code in the editor and upload the code on the Arduino Board,

The code will be compiled and uploaded on the board. After the code has been uploaded on the arduino board the traffic light starts functioning.

Did you notice the green light stays on for a longer period of time?

Age: 13 – 15 Yrs.

Do you ever wonder how a traffic light works, the software behind it and how we can modify  the software ?

The Moonshot Jr Traffic Light kit will help you understand traffic lights and the programming which helps it function. Let us get our hands on this kit and understand how it works. We will also understand the code and how it works to be able to modify it as we progress.

Let’s Start

Step 1 : Insert the Controller Board ( TL001) and Traffic Light Board (TL004) in the Bread Board( TL006). Ensure that the USB connector is at the edge of the Bread Board  and the pins are aligning, as shown in the image below.

Step 2 : Use a black (or any other color) wire and insert one end to an empty hole in the breadboard in front of the GND pin of the controller board.

Insert the other end of the wire in the empty hole on the breadboard in front of the traffic light board’s black pin.

Note: Make sure the end of the wire is inserted in front of the GND pin of the controller board.

Step 3 : Repeat the previous process for the remaining pins.

The Red wire connects to pin D4 of the controller board.

The Yellow wire connects to pin D3 of the controller board.

The Green wire connects to pin D2 of the controller board.

 

Wire Traffic Board Controller Board
Red Red D4
Yellow Yellow D3
Green Green D2
Black Black GND

 

This is the scheme of connection, note that the connection has to be made through the breadboard.

Step 4 : Insert USB Cable into the connector of the controller board. Connect the other end of the cable in the USB Port of your computer or laptop. You will notice the traffic light starts working.

Have you thought about what was inside the Controller board that made the traffic lights work? So far you have just learned how to connect the components and make the Traffic Light work, in the following steps you will learn about the coding part of the Traffic Light.

Step 5: Go to https://www.arduino.cc/en/software and download the latest version of Arduino IDE, depending on which system you use (Windows, Mac).

Step 6 : After Installing the Arduino IDE, connect the Arduino board to your computer. After starting the Arduino IDE. Click on tools to reveal this menu:

  • Hover on Board, Select Arduino Nano
  • Select ATmega328P(Old Bootloader) as the Processor.
  • Select the correct Port ( e.g. COM4).
  • Make sure the Programmer is set to AVRISP mkII .

Step 7 : Copy the code given below

// C++ code
//Define Pins to avoid confusion
const byte GREEN = 2;
const byte YELLOW = 3;
const byte RED = 4;

//Initialize the pins (give an initial value)
void setup()//The setup function defines the initial state of the Arduino upon boot and runs only once.
{
  pinMode(GREEN, OUTPUT);//pin number 8 Green) configured for output
  pinMode(YELLOW, OUTPUT);//pin number 7 (Yellow) configured for output
  pinMode(RED, OUTPUT);//pin number 2 (Red) configured for output
}
//Run code (write code that will keep on executing throughout the loop)
void loop()
/*The loop describes the main logic of your circuit, runs again and again as its name suggests,
and is executed after the setup has finished executing.*/
{
  digitalWrite(RED, HIGH);//When Set to HIGH current is supplied to the pin (5v) and the LED lights up
  digitalWrite(YELLOW, LOW);//When Set to LOW current supplied to the pin is 0v and the LED doesn't light up
  digitalWrite(GREEN, LOW);
  delay(4000); // 1 second = 1000 milliseconds, wait for 4 seconds.
  digitalWrite(GREEN, HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(YELLOW, LOW);
  delay(4000); // Wait for 4000 millisecond(s)
  digitalWrite(YELLOW, HIGH);
  digitalWrite(GREEN, LOW);
  digitalWrite(RED, LOW);
  delay(1500); // Wait for 1500 millisecond(s)
}

Understanding the Code

1. All lines that begin with // are comments.  Comments are skipped while when the code is executed, they enhance the understanding of the code. Following two lines are comments, for example.

// C++ code
//Define Pins to avoid confusion

2. In the block of code below, we define the pin numbers that we are going to use with a simple name to avoid confusion and make the code easy to understand.

const byte GREEN = 2;
const byte YELLOW = 3;
const byte RED = 4;

3. In the block of code below, the setup is used to  initialize or give initial values to the pins, which will decide how these pins will function throughout the execution of the code.

void setup()//The setup function defines the initial state of the Arduino upon boot and runs only once.
{
  pinMode(GREEN, OUTPUT);//pin number 8 Green) configured for output
  pinMode(YELLOW, OUTPUT);//pin number 7 (Yellow) configured for output
  pinMode(RED, OUTPUT);//pin number 2 (Red) configured for output
}

4. Inside the loop resides the code that will keep on executing endlessly. The line of code given below turns on the Red LED while turning the other LED off, it waits for 4 seconds and then turns on only the Green LED while keeping other LEDs off. It again waits for 4 seconds and turns only the Yellow LED on, waits for 1.5 seconds and then starts over with the Red LED.

void loop()
/*The loop describes the main logic of your circuit, runs again and again as its name suggests,
and is executed after the setup has finished executing.*/
{
  digitalWrite(RED, HIGH);//When Set to HIGH current is supplied to the pin (5v) and the LED lights up
  digitalWrite(YELLOW, LOW);//When Set to LOW current supplied to the pin is 0v and the LED doesn't light up
  digitalWrite(GREEN, LOW);
  delay(4000); // 1 second = 1000 milliseconds, wait for 4 seconds.
  digitalWrite(GREEN, HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(YELLOW, LOW);
  delay(4000); // Wait for 4000 millisecond(s)
  digitalWrite(YELLOW, HIGH);
  digitalWrite(GREEN, LOW);
  digitalWrite(RED, LOW);
  delay(1500); // Wait for 1500 millisecond(s)
}

With the explanation given above, you can experiment with the code and make your own changes. If you wanted to change how fast traffic lights switch, you could change the value of delay.

Additional Exercise

Once you have understood how the above code works, add a button to stop the traffic lights on button press on the already implemented traffic light project. 

Here is how you will achieve the above project

Step 1: Disconnect and take your working traffic light project. Connect a button on the breadboard as shown.

Step 2: Take a wire connect one end of it in front of the GND pin of the controller board

Insert the other end of the wire in the empty hole on the breadboard in front of the button’s left pin.

Step 3: Take another wire and connect one end in front of pin D5 of the controller board, connect the other end in front of the button’s right pin.

This is the scheme of connection, note that the connection has to be made through the breadboard.

Step 4: Copy the code given below

int buttonState = 0;
int buttonPin = 5;

const int GREEN = 2;
const int YELLOW = 3;
const int RED = 4;
void setup() {
  pinMode(GREEN, OUTPUT);//pin number 8 Green) configured for output
  pinMode(YELLOW, OUTPUT);//pin number 7 (Yellow) configured for output
  pinMode(RED, OUTPUT);//pin number 2 (Red) configured for output
  pinMode(buttonPin,INPUT_PULLUP);
}

void loop() {
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {
    // turn LED on:
    buttonNotPressed();
  } else {
    buttonPressed();
  }
}

void buttonNotPressed(){
  digitalWrite(RED, HIGH);//When Set to HIGH current is supplied to the pin (5v) and the LED lights up
  digitalWrite(YELLOW, LOW);//When Set to LOW current supplied to the pin is 0v and the LED doesn't light up
  digitalWrite(GREEN, LOW);
  delay(4000); // 1 second = 1000 milliseconds, wait for 4 seconds.
  digitalWrite(GREEN, HIGH);
  digitalWrite(RED, LOW);
  digitalWrite(YELLOW, LOW);
  delay(4000); // Wait for 4000 millisecond(s)
  digitalWrite(YELLOW, HIGH);
  digitalWrite(GREEN, LOW);
  digitalWrite(RED, LOW);
  delay(1500); // Wait for 1500 millisecond(s)
}

void buttonPressed(){
  digitalWrite(RED, LOW);
  digitalWrite(YELLOW, LOW);
  digitalWrite(GREEN, LOW);
}

 

Step 5: Open the Arduino IDE, connect the controller board, paste the code and upload it on the board. Notice that, when you press the button the Traffic Light stops, when you release the button the traffic light starts working again.

Author Bio

author-image

Vikas Shukla, an innovator at heart whose undivided attention is dedicated to technology. His inquisitiveness to create has led to several innovations in the field of hardware and software. He is the architect behind several successful learning products for students. These tool kits are a part of the curriculum at Moonpreneur.

Category