# Lesson 20 Simple Creation – Traffic Light

##### Share for us

Introduction

In this lesson, we will continue to make amusing experiment – simulate a traffic light. The colored lights of a traffic light are typically red for stop, green for go, and yellow for proceed with caution. We’ll use LEDs for the indicators. Let’s get started!

Components

– 1 * SunFounder Uno board

– 6 * LED (2 red, 2 yellow, and 2 green)

– 7 * Resistor (220Ω)

– 1 * 7-segment display

– 1* 74HC595

– 1 * USB cable

– Jumper wires

Principle

The schematic diagram

In this experiment, we use a 7-segment display to count down and set two groups of traffic lights to represent two directions, let’s say, north-south (NS) and east-west (EW), as shown in the following figure in Procedures. First, count down from 9s, and the red light in the NS and the green one in the EW light up. As time goes by, after 9s, the 7-segment begins to count down from 3s, the green LED in the EW goes out when the yellow lights up, the NS red light keeps on. 3s later, the 7-segment counts down from 9s again. At the same time, the red light in the EW and the green in the NS light up. After 9s, the 7-segment counts down from 3s again, when the yellow light in the NS lights up and the red in the EW keeps on. This process simulates the working of traffic lights.

Note:  The 7-segment display is controlled by 74HC595 as shown in Lesson 11 previously. There is no current limiting resistor between the pins of 7-segment display and Q0-Q7 but one to the GND. It can also protect the 7-segment display when making a simplified circuit.

Experimental Procedures

Step 1: Build the circuit

Step 2: Open the code file

Step 3: Select correct Board and Port

Step 4: Upload the sketch to the SunFounder Uno board

You can see what is similar to the traffic light now. First, the 7-segment display counts down from 9s, and the red light in the NS and the green one in the EW light up. Then it counts down from 3, and the green LED in the EW goes out when the yellow lights up, with the NS red light still on. 3s later, the 7-segment counts down from 9s again. Meanwhile, the red light in the EW and the green in the NS light up. After 9s, it counts down from 3s, when the yellow light in the NS lights up and the red in the EW keeps on.

Code