Make Traffic Light System Using Scratch & Python

Make Traffic Light System Using Scratch & Python

0 comments

Why PiTraffic

Raspberry Pi is a small portable, affordable, and popular computer that you can use to learn to program and develop your own ideas.

If you are getting started with Raspberry Pi, PiTraffic is here to give you a boost.

In the world of embedded electronics, where we aim to automate the world we all need a point to start. PiTraffic can be your gateway to the embedded world.

We all see traffic lights in our day to day life, but when we belong to the same domain we want to know how it works. PiTraffic is a great start for Raspberry Pi learners and trainers.

PiTraffic is a low-cost hardware shield that allows Raspberry Pi users to take their first steps into interfacing with the real world. With PiTraffic, one can try his/her hands on python and get familiarized with the elements used in it & use them their way. There are endless possibilities to try with.

Stop wasting time on hardware, spend more time on development and creating ideas. It is often seen that people generally get confused on how to get started or assemble hardware. However, PiTraffic makes it simple by plugging components directly onto pre-set positions on the Raspberry Shield Hat.

What Official Raspberry Pi magazine ‘The MagPi’ has to say about PiTraffic

“A great starter HAT that takes much of the tangle out of a classic project. Students can test out traffic light code and see their results running in a miniature recreation.”

 

Things you will learn

  • Basic Python and Scratch programming,
  • Using Class and Functions,
  • Using Raspberry Pi GPIOs,
  • Controlling LEDs and buzzer

Things you need

Hardware Setup

By plugging PiTraffic directly on to the Raspberry Pi GPIO header, no extra cables or wires are needed. Unlike many other add-on boards, PiTraffic does not block GPIO pins of the shield, keeping them open for other multiple usages.

PiTraffic is fitted with 4 standard Pins, allowing up to four PiTraffic stands to be controlled independently.

There is a buzzer which can be used to alert on change of light.

Here are some steps to connect your Raspberry Pi with PiTraffic:

1. Place PiTraffic shield on Raspberry Pi.

PiTraffic

 

2. Plug Traffic stand on the PiTraffic shield.
PiTraffic

Play with PiTraffic

Required codes can be downloaded from

https://github.com/sbcshop/PiTraffic

OR

Clone with

git clone https://github.com/sbcshop/PiTraffic.git

PiTraffic with python

Test your PiTraffic by running ‘TrafficTest.py’ with python.

To develop your own patterns you can use the ‘PiTraffic.py’ module:

Begin by importing PiTraffic file:

Import PiTraffic
Control LEDs by specifying the direction and color of LED:
SouthRed = PiTraffic.Traffic("SOUTH", "RED")

Switch LED ON or OFF with:

SouthRED.on()
SouthRED.off()

Control buzzer with:

Buzz = PiTraffic.Buzzer()


Create sound with buzzer by:

Import time
Buzz.on()
time.sleep(2)
Buzz.off()
PiTraffic from Scratch

Run our scratch files,

PiTraffic

Or build your own blocks.

Play with the code, make your own code or edit ours.

Want your own PiTraffic Kit? Click here


Safeguard your Arduino with elegant and innovative cases

The First Look of Raspberry Pi 4 Model B

Leave a comment

Please note, comments need to be approved before they are published.