Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Siddharth Sali
Published © GPL3+

Automated Traffic Light System

Using Bolt WiFi Module, an easy to use, low cost and simple Automated Traffic Light System has been developed in this prototype.

IntermediateFull instructions provided1 hour843
Automated Traffic Light System

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×6
Resistor 330 ohm
Resistor 330 ohm
×3
5 mm LED: Red
5 mm LED: Red
Representing our RED Light
×1
5 mm LED: Yellow
5 mm LED: Yellow
Representing our YELLOW Light
×1
5 mm LED: Green
5 mm LED: Green
Representing our GREEN Light
×1
Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud
Ubuntu

Story

Read more

Code

Automated Traffic Light

Python
0 pin is for RED Light
1 pin is for YELLOW Light
2 pin is for GREEN Light
Loop is executed 3 times here.
Can be varied according to user.
from boltiot import Bolt                        #Importing Bolt Libraries
import time                                     #Importing Time Module
from time import sleep                          #Importing Sleep Module
api_key = "xxxxxxxxxxxxxxxxxxxx"                #Insert your API-KEY
device_id = "BOLTXXXXXXX"                       #Insert your device ID
mybolt = Bolt(api_key, device_id)

def red():                                    #Function FOR Red Light
    print(mybolt.digitalWrite('2', 'LOW'))    #Switch OFF Green
    print(mybolt.digitalWrite('0', 'HIGH'))   #Switch ON RED
    print(mybolt.digitalWrite('1', 'LOW'))    #Switch OFF Yellow
def yellow():
    print(mybolt.digitalWrite('0', 'LOW'))    #Switch OFF RED
    print(mybolt.digitalWrite('1', 'HIGH'))   #Switch ON Yellow
    print(mybolt.digitalWrite('2', 'LOW'))    #Switch OFF Green
def green():
    print(mybolt.digitalWrite('0', 'LOW'))    #Switch OFF RED
    print(mybolt.digitalWrite('1', 'LOW'))    #Switch OFF Yellow
    print(mybolt.digitalWrite('2', 'HIGH'))   #Switch ON Green
def stop():                                   #Switch off All lights(optional)
    print(mybolt.digitalWrite('0', 'LOW'))
    print(mybolt.digitalWrite('1', 'LOW'))
    print(mybolt.digitalWrite('2', 'LOW'))
def start():                                  #Our Sequence function R-Y-G
    i=0
    while i<3:                                #Executing Sequence for 3 times
            red()                             #RED LIGHT
            time.sleep(5)                     #Hold five seconds
            yellow()                          #YELLOW LIGHT
            time.sleep(3)                     #HOLD three seconds
            green()                           #GREEN LIGHT
            time.sleep(5)                     #Hold five seconds
            i=i+1                         
    else:
            stop()                            #Switch off lights after loop
start()                                       #main program

Credits

Siddharth Sali
1 project • 0 followers

Comments