Arduino SA
  • Learn @ Arduino SA
  • Arduino Introduction
  • Support
    • Setup your Computer
    • Adding Libraries
    • Setting up a ESP32
  • Arduino Robot Car
    • Arduino Bluetooth Car
      • What you will need
      • Circuit Diagram
      • Assembly the Car
      • Upload the Code
      • Bluetooth setup and Test
    • 4WD Obstacle Avoidance
      • Introduction
      • Component List
      • Assembly
      • Component Description
      • Circuit Diagram
      • Computer Setup
      • Line Tracking Mode
      • Obstacle Avoidance Mode
  • Arduino Kits
    • Smart Plant Watering Kit
      • What you will need
      • Wiring Diagram
      • The Code
      • Pics
    • Basic Starter Kit
      • Component View
      • Installing the IDE
      • Add Libraries
      • Blink
      • Button Control LED Delay Switch
      • Active Buzzer
      • Passive Buzzer
      • Servo
      • IR Remote and Receiver
      • Stepper Motor
      • Eight LED with 74HC595
      • LCD
      • Digital tube with Traffic Light Experiment
      • Four digit tube display
      • LM35D Temperature Sensor
      • LDR 5516 experiment
      • Flame Sensor
      • 8 * 8 LED Module
      • Controlling Stepper Motor With Remote
    • Super Starter Kit
      • Tutorials
    • Best Beginner Kit for Arduino
      • Tutorials
    • Uno R3 RFID Kit
    • WIFI ESP32 IOT Kit
    • Arduino School STEM Kit
    • Arduino Ultimate Starter Kit
  • Blocking Coding Lessons
    • Beginner Lessons
      • Setting up mBlock
      • Blinking an LED
      • LED Switching
      • LED Chasing
      • Traffic Signal
      • Buzzer
      • Buzzer + Push Button
      • LED + Push Button
  • Sensor Kits
    • 37-in-1 Sensor Kit
      • Joystick
      • Relay
      • Big Sound
      • Small Sound
      • Tracking
      • Avoid
      • Flame
      • Linear Hall Sensor
      • Touch
      • Digital Temperature
      • Buzzer
      • Passive Buzzer
      • RGB LED
      • SMD RGB
      • Two-Color 5mm
      • Two Color 3mm
      • Reed Switch
      • Mini Reed
      • Heartbeat
      • 7 color flash
      • Laser emitter
      • PCB mounted push Button
      • Shock switch
      • Rotary encoder
      • Light Cup
      • Tilt Switch
      • Rolling ball tilt switch
      • Photoresistor
      • Temp and Humidity
      • Analog Hall
      • Hall Magnetic
      • Temp
      • Analog Temp
      • IR Emission
      • IR Receiver
      • Tap Module
      • Light blocking
Powered by GitBook
On this page
  • Component Required
  • Component Introduction
  • Connection Diagram:
  • Wiring schematic:
  • Physical wiring diagram:

Was this helpful?

  1. Arduino Kits
  2. Basic Starter Kit

Digital tube with Traffic Light Experiment

This lesson will use the 74HC595 shift register in combination with the red and green LEDs and the yellow LED to create a traffic light.

PreviousLCDNextFour digit tube display

Last updated 3 years ago

Was this helpful?

Component Required

  • 1 x Uno R3

  • 1 x 830 tie-points breadboard

  • 1 x 1 Digit 7-Segment Display

  • 10 X 220 ohm resistors

  • 20 x M-M wire (Male to Male jumper wire)

  • 1 x Red LED

  • 1 x Yellow LED

  • 1 x Green LED

Component Introduction

Seven segment display

Below is the seven-segment pin diagram.

0-9 ten digits correspond with each segment are as follows (the following table applies common cathode seven segment display device, if you are using a common anode, the table should be replaced every 1 0 0 should all replaced by 1):

Display

dp

a

b

c

d

e

f

g

digital

0

0

1

1

1

1

1

1

0

1

0

0

1

1

0

0

0

0

2

0

1

1

0

1

1

0

1

3

0

1

1

1

1

0

0

1

4

0

0

1

1

0

0

1

1

5

0

1

0

1

1

0

1

1

6

0

1

0

1

1

1

1

1

7

0

1

1

1

0

0

0

0

8

0

1

1

1

1

1

1

1

9

0

1

1

1

1

0

1

1

Connection Diagram:

Wiring schematic:

Physical wiring diagram:

int a = 7;
int b = 6;
int c = 5;
int d = 11;
int e = 10;
int f = 8;
int g = 9;

int ledG = 14;
int ledY = 15;
int ledR = 16;

//Display number 1
void digital_1(void)
{
  unsigned char j;
  digitalWrite(c, HIGH); //Lower the level of the digital 5 pin and light up segment c
  digitalWrite(b, HIGH); //Light section b
  for (j = 7; j <= 11; j++) //blanking
    digitalWrite(j, LOW);
}
//Display number 2
void digital_2(void)
{
  unsigned char j;
  digitalWrite(b, HIGH);
  digitalWrite(a, HIGH);
  for (j = 9; j <= 11; j++)
    digitalWrite(j, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(f, LOW);
}
//Display number 3
void digital_3(void)
{
  unsigned char j;
  digitalWrite(g, HIGH);
  digitalWrite(d, HIGH);
  for (j = 5; j <= 7; j++)
    digitalWrite(j, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(e, LOW);
}


//Display number 4
void digital_4(void)
{
  digitalWrite(c, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(a, LOW);
  digitalWrite(e, LOW);
  digitalWrite(d, LOW);
}
//Display number 5
void digital_5(void)
{
  unsigned char j;
  for (j = 7; j <= 9; j++)
    digitalWrite(j, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(e, LOW);
}
//Display number 6
void digital_6(void)
{
  unsigned char j;
  for (j = 7; j <= 11; j++)
    digitalWrite(j, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(b, LOW);
}
//Display number 7
void digital_7(void)
{
  unsigned char j;
  for (j = 5; j <= 7; j++)
    digitalWrite(j, HIGH);
  for (j = 8; j <= 11; j++)
    digitalWrite(j, LOW);
}

//Display number 8
void digital_8(void)
{
  unsigned char j;
  for (j = 5; j <= 11; j++)
    digitalWrite(j, HIGH);
}
//Display number 9
void digital_9(void)
{
  digitalWrite(c, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(a, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(d, HIGH);
}
//Pin setting and initialization
void setup()
{
  int i;//defined variable
  for (i = 5; i <= 16; i++)
    pinMode(i, OUTPUT); //Set pins 5 ~ 16 to output mode

}

void loop()
{
  while (1)
  {
    //red light
    digitalWrite(ledR, LOW);
    digitalWrite(ledY, HIGH);
    digitalWrite(ledG, HIGH);

    digital_9();  // Show 9
    delay(1000);   //Delay 1 s
    digital_8();  // Show 8
    delay(1000);   //Delay 1 s
    digital_7();  // Show 7
    delay(1000);   //Delay 1 s
    digital_6();  // Show 6
    delay(1000);   //Delay 1 s
    digital_5();  // Show 5
    delay(1000);   //Delay 1 s
    digital_4();  // Show 4
    delay(1000);   //Delay 1 s
    digital_3();  // Show 3
    delay(1000);   //Delay 1 s
    digital_2();  // Show 2
    delay(1000);   //Delay 1 s
    digital_1();  // Show 1
    delay(1000);   //Delay 1 s
    //green light
    digitalWrite(ledR, HIGH);
    digitalWrite(ledY, HIGH);
    digitalWrite(ledG, LOW);

    digital_9();  // Show 9
    delay(1000);   //Delay 1 s
    digital_8();  // Show 8
    delay(1000);   //Delay 1 s
    digital_7();  // Show 7
    delay(1000);   //Delay 1 s
    digital_6();  // Show 6
    delay(1000);   //Delay 1 s
    digital_5();  // Show 5
    delay(1000);   //Delay 1 s
    digital_4();  // Show 4
    delay(1000);   //Delay 1 s
    digital_3();  // Show 3
    delay(1000);   //Delay 1 s
    digital_2();  // Show 2
    delay(1000);   //Delay 1 s
    digital_1();  // Show 1
    delay(1000);   //Delay 1 s
    //yellow light
    digitalWrite(ledR, HIGH);
    digitalWrite(ledY, LOW);
    digitalWrite(ledG, HIGH);
    digital_3();  // Show 3
    delay(1000);   //Delay 1 s
    digital_2();  // Show 2
    delay(1000);   //Delay 1 s
    digital_1();  // Show 1
    delay(1000);   //Delay 1 s
  }
}
4KB
digialtube-traffic-light.ino