A few days ago I bought a three-color tower light with buzzer for visual and audible alerts. And because I’m a big kid, I thought to build as the first application a game of lights in the style of a police car. The result will be seen at the bottom of this article.
Before entering into the connection and programming area, I give you some details about the product. The tower light has three colors and a buzzer. The tower can be easily controlled by an Arduino board, four N-channel MOSFETs or NPN transistors, and four resistors.
The light tower is branded Adafruit and produced in China. At least this is written on the product that I use in this tutorial. Also, there is a schema somewhere on it with Chinese letters. Thank you Adafruit!
Everywhere I’ve been looking for information about how it works and how I can control it, I’ve given this tutorial. The tutorial is dedicated to the RGB LED strips and less to a light tower. Generally, Adafruit produces good tutorials, so I think that I don’t have to make a great effort to turn ON the lights. But this time I was a bit misguided by the schema with connections found in the tutorial. For the NPN Bipolar Transistors (PN2222), I recommend you carefully look how the three pins of the transistor are located or use the schema from this article. When I connected the light tower just like in the Adafruit’s tutorial (the NPN schema), the result was a tower light that just makes some noise and has two lights on. Obviously, the pins of the transistors were wrongly connected.
Let’s get to the practical side.
Components:
- 1 X Tower Light – Red Yellow Green Alert Light & Buzzer (I buy it from here, but you can buy it also from Amazon)
- 4 X NPN Bipolar Transistors (PN2222) (link on Amazon)
- 4 X 100-220 Ohm resistors (link on Amazon)
- 1 X Arduino board (I think you already have one, but in case I’m wrong, you can take one from here)
- some wires (link on Amazon)
The schema:
Tower light and Arduino Schema
The Arduino code:
//Constants #define REDPIN 9 #define YELLOWPIN 10 #define GREENPIN 11 #define BUZZ 12 //Variables int ledDelay=50; long previousMillisLights = 0; long intervalLights = 500; long previousMillisTemperature = 0; long intervalTemperature = 1000; void setup() { Serial.begin(9600); pinMode(REDPIN, OUTPUT); pinMode(YELLOWPIN, OUTPUT); pinMode(GREENPIN, OUTPUT); pinMode(BUZZ, OUTPUT); } void loop() { unsigned long currentMillis = millis(); if ((unsigned long)(currentMillis - previousMillisLights) >= intervalLights) { redPoliceLights(); yellowPoliceLights(); greenPoliceLights(); //add here the code if you want the turn on the buzzer //analogWrite(BUZZ, HIGH); intervalLights = currentMillis; } } //turn ON and OFF the red light void redPoliceLights(){ analogWrite(REDPIN, HIGH); delay(ledDelay); analogWrite(REDPIN, LOW); delay(ledDelay); analogWrite(REDPIN, HIGH); delay(ledDelay); analogWrite(REDPIN, LOW); delay(ledDelay); analogWrite(REDPIN, HIGH); delay(ledDelay); analogWrite(REDPIN, LOW); delay(ledDelay); } //turn ON and OFF the yellow light void yellowPoliceLights(){ analogWrite(YELLOWPIN, HIGH); delay(ledDelay); analogWrite(YELLOWPIN, LOW); delay(ledDelay); analogWrite(YELLOWPIN, HIGH); delay(ledDelay); analogWrite(YELLOWPIN, LOW); delay(ledDelay); analogWrite(YELLOWPIN, HIGH); delay(ledDelay); analogWrite(YELLOWPIN, LOW); delay(ledDelay); } //turn ON and OFF the green light void greenPoliceLights(){ analogWrite(GREENPIN, HIGH); delay(ledDelay); analogWrite(GREENPIN, LOW); delay(ledDelay); analogWrite(GREENPIN, HIGH); delay(ledDelay); analogWrite(GREENPIN, LOW); delay(ledDelay); analogWrite(GREENPIN, HIGH); delay(ledDelay); analogWrite(GREENPIN, LOW); delay(ledDelay); }
Tower Light Demo: