LED Traffic Light Module
LED Traffic Light Module
Thank you for purchasing our AZ-Delivery LED Traffic Light Module. On the
following pages, you will be introduced to how to use and set up this handy
device.
Have fun!
Table of Contents
Introduction....................................................................................................3
Specifications................................................................................................4
The pinout.....................................................................................................5
How to set-up Arduino IDE............................................................................6
How to set-up the Raspberry Pi and Python...............................................10
Connecting the module with Uno.................................................................11
Sketch example.......................................................................................12
Connecting the module with Raspberry Pi..................................................13
Python script............................................................................................14
-2-
Introduction
LED traffic light module is a mini-traffic light, easy to manage and suitable
for the production of traffic light system model.
The module consist of single board with three 8mm LEDs (Light Emitting
Diodes) - red, yellow and green - and built-in current limiting resistors. There
are only four pins on the device, one for the anode of each LED and a
common cathode. This way the connection to microcontrollers is simplified.
When using PWM (pulse width modulation) the LEDs can produce fade-in,
fade-out effect or can be dimmed to the desired brightness level from the
respective microcontroller pin.
-3-
Specifications
-4-
The pinout
The LED Traffic Light Module has 4 pins. The pinout is shown in the
following image:
-5-
How to set-up Arduino IDE
If the Arduino IDE is not installed, follow the link and download the
installation file for the operating system of choice. The Arduino IDE version
used for this eBook is 1.8.12.
For Windows users, double click on the downloaded .exe file and follow
the instructions in the installation window.
-6-
For Linux users, download a file with the extension .tar.xz, which has to
be extracted. When it is extracted, go to the extracted directory and open
the terminal in that directory. Two .sh scripts have to be executed, the first
called arduino-linux-setup.sh and the second called install.sh.
To run the first script in the terminal, open the terminal in the extracted
directory and run the following command:
sh arduino-linux-setup.sh user_name
user_name - is the name of a superuser in Linux operating system. A
password for the superuser has to be entered when the command is
started. Wait for a few minutes for the script to complete everything.
The second script, called install.sh, has to be used after the installation
of the first script. Run the following command in the terminal (extracted
directory): sh install.sh
After the installation of these scripts, go to the All Apps, where the
Arduino IDE is installed.
-7-
Almost all operating systems come with a text editor preinstalled (for
example, Windows comes with Notepad, Linux Ubuntu comes with
Gedit, Linux Raspbian comes with Leafpad, etc.). All of these text
editors are perfectly fine for the purpose of the eBook.
Next thing is to check if your PC can detect an Arduino board. Open freshly
installed Arduino IDE, and go to:
Tools > Board > {your board name here}
{your board name here} should be the Arduino/Genuino Uno, as it can
be seen on the following image:
The port to which the Arduino board is connected has to be selected. Go to:
Tools > Port > {port name goes here}
and when the Arduino board is connected to the USB port, the port name
can be seen in the drop-down menu on the previous image.
-8-
If the Arduino IDE is used on Windows, port names are as follows:
-9-
How to set-up the Raspberry Pi and Python
For the Raspberry Pi, first the operating system has to be installed, then
everything has to be set-up so that it can be used in the Headless mode.
The Headless mode enables remote connection to the Raspberry Pi,
without the need for a PC screen Monitor, mouse or keyboard. The only
things that are used in this mode are the Raspberry Pi itself, power supply
and internet connection. All of this is explained minutely in the free eBook:
Raspberry Pi Quick Startup Guide
- 10 -
Connecting the module with Uno
Connect the module with the Uno as shown n the following connection
diagram:
- 11 -
Sketch example
int GREEN = 4;
int YELLOW = 3;
int RED = 2;
void setup()
{
pinMode(GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
}
void loop()
{
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, HIGH);
delay(3000);
digitalWrite(YELLOW, HIGH);
delay(1000);
digitalWrite(RED, LOW);
digitalWrite(YELLOW, LOW);
digitalWrite(GREEN, HIGH);
delay(3000);
digitalWrite(GREEN, LOW);
digitalWrite(YELLOW, HIGH);
delay(1000);
}
- 12 -
Connecting the module with Raspberry Pi
- 13 -
Python script
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.OUT) # green LED
GPIO.setup(27, GPIO.OUT) # yellow LED
GPIO.setup(22, GPIO.OUT) # red LED
signal.signal(signal.SIGINT, allLightsOff)
print('[Press CTRL + C to end the script!]')
while True:
GPIO.output(22, True) # red on
time.sleep(3)
- 14 -
GPIO.output(27, False) # yellow off
GPIO.output(22, False) # red off
GPIO.output(17, True) # green on
time.sleep(5)
- 15 -
Save the script under the name trafficLight.py. To run the script open
the terminal in the directory where the script is saved and run the following
command: python3 trafficLight.py
- 16 -
Now it is the time to learn and make your own projects. You can do that with
the help of many example scripts and other tutorials, which can be found on
the Internet.
If you are looking for the high quality products for Arduino and
Raspberry Pi, AZ-Delivery Vertriebs GmbH is the right company to get
them from. You will be provided with numerous application examples,
full installation guides, eBooks, libraries and assistance from our
technical experts.
https://az-delivery.de
Have Fun!
Impressum
https://az-delivery.de/pages/about-us
- 17 -