You are on page 1of 18

Arduino

Traffi c Light and


Seven Segment display

KDU University College Confidential & Proprietary | ©


Copyright 2013
Lesson on Today:

Expected outcome on Today:


1) Arduino C program for
• Traffic light control
• Seven Segment Display
Pass lessons
 PinMode(pin,Output);
 PinMode(pin,Input);
 digitalWrite(pin,1);
 delayms(10);
 digitalRead
 !=, ==
 If—else
 attachInterrupt()
 Pull-up , pull-down
Function program

digitalWrite(12,0);

digitalWrite(8,HIGH);

The control of the program jumps back to the main() function once


code inside the function definition is executed.
Function program

digitalWrite(12,0);

digitalWrite(8,HIGH);

The control of the program jumps back to the main() function once


code inside the function definition is executed.
Traffic Light Control
 A simple USA-style traffic light consists of a
red, amber, and green light. The typical
sequence is as follows:
 Green (safe to proceed)
 Amber (slow down, red light soon)
 Red (stop)
Traffic Light Control

Let’s assume that Busy Lane has to have its green traffic light
on for 10 seconds from west to east and west to south. While
another not busy lane has to have its green traffic light on for 5
seconds from South to East and South to West.

For both streets, it is permissible to have the amber traffic light


on for 3 seconds before turn into Red color. For the red traffic
lights, the green and amber cycle times will directly influence
this.
10 Seconds
West to East and West to South

South to West and South to East

West to East and West to South


3 Seconds
South to West and South to East

West to East and West to South


5 Seconds
South to West and South to East
Sequenc West Traffic Light South Traffic Light Remarks
e
0 Green Red 10 seconds

1 Yellow Red 3 seconds


2 Red Red For safety
purpose
Delay for 1
second
3 Red Green 5 seconds

4 Red Yellow 3 seconds

5 Red Red For safety


purpose
Delay for 1
D2 D3 D4 D5 D6 D7
Seven Segment display
digitalWrite (pin, HIGH)
digitalWrite (pin, LOW)

+(1)
+(1)
+(1)
+(1)
-(0)
-(0)
+(1)
-(0)
Common Cathode
Question?
 Design a circuit of an interface a seven
segment LED display to an Arduino
microcontroller. Then write a C program to
display digits from 0 to 9 with the interval of
1 second.
Remaarks
D2 D3 D4 D5 D6 D7 D8
Digits
a b c d e f g

0 1(on) 1(on) 1(on) 1(on) 1(on) 1(on) 0(off)

1 1(on) 1(on)

2 1(on) 1(on) 1(on) 1(on) 1(on)


3 0(off) 0(off)

4 0(off) 0(off) 0(off)


5

8
Example of call a function
Seven Segment Display

You might also like