In this tutorial, we are going to make a police light using Arduino nano. This project is based on the concept of led blinking. Police light is a good beginner project to understand how microcontrollers work with simple programs.
The components required to make this project are
- Arduino nano / uno
- 2 x blue led
- 2 x red led
- 220-ohm resistor
- Breadboard
- Jumper wires
As long as your desktop is connected to Arduino through cable. we don’t need any external power supply for Arduino.
Connection
Connect the pins of Arduino with the led as mentioned in the table below
Arduino pins | Led pins |
|
|
D9 | Blue led 1 +ve |
D10 | Blue led 2 +ve |
D11 | Red led 1 +ve |
D12 | Red led 2 +ve |
Gnd | -ve of all led’s |
Arduino code for police light using arduino nano
The code for police light using Arduino nano is given below with an explanation in the comments.
void setup() // setup code
{
pinMode (9,OUTPUT); // declaring pin D9 for output mode
pinMode (10,OUTPUT); // declaring pin D10 for output mode
pinMode (11,OUTPUT); // declaring pin D11 for output mode
pinMode (12,OUTPUT); // declaring pin D12 for output mode
}
void loop() // to run code repeatedly
{
digitalWrite(9,HIGH); // Putting pin D9 high, led connected to D9 will glow.
digitalWrite(10,HIGH); // Putting pin D10 high, led connected to D10 will glow.
delay(1000); // delay code for 1 second
digitalWrite(9,LOW); // Putting pin D9 low, led connected to D9 will off.
digitalWrite(10,LOW); // Putting pin D10 low, led connected to D10 will off.
digitalWrite(11,HIGH); // Putting pin D11 high, led connected to D11 will glow.
digitalWrite(12,HIGH); // Putting pin D9 high, led connected to D12 will glow.
delay(1000); // delay code for 1 second
digitalWrite(11,LOW); // Putting pin D11 low, led connected to D9 will off.
digitalWrite(12,LOW); // Putting pin D12 low, led connected to D9 will off.
}
More led can be put in parallel for a single pin of Arduino. Up to 3 led in parallel is good. A single command in a program can run multiple led in parallel.
Author
Akash Sharma
More projects on Arduino nano
Nice project 👍👍