Arduino Police Car
Updated: Feb 16
Since learning the basics of how to make multiple LED's flash on and off at the same time, I knew my next step was to make the LED's flash at a different rate.
I began to think of a real world situation where flashing lights could be used. I thought I would try and replicate the lights of a police car, where headlights would be on as constantly, and the red and blue lights would be flashing at alternate times.
I put the red and blue LED's in separate pins on the breadboard, and the two white headlight pins in two separate pins too. This allowed me to have individual control of each LED, rather than one pin controlling multiple LED's simultaneously.
To do this, I turned on the two white headlight LED Pins first. After this, I turned the blue light on, added a delay, then turned it back off. The turned the red light on, added a delay, then turned it off. This command was all within the 'loop' function, so the Arduino repeated this command over and over, replicating a police car with flashing lights.
This is a screenshot of the code that was used to run this program:
I checked for any errors in my code, and then loaded the code to the board. This was the end result:
My next step for this will be to change the code so that it can be changed and edited quicker, allowing a user to quickly change the speed of the delay (without changing the whole code).