Turn your Arduino into KITT from Knight Rider! This tutorial is on how to program and assemble an LED chase effect Arduino project. This is a beginner project and can be used as a stepping stone for more complicated projects down the line.
Materials:
Note: The Arduino IDE uses the Java programming language. We will be using the conventions and syntax of Java throughout this tutorial.
To make things easier on ourselves later on in the program, it will be best if we create variables for numbers or items we will be referring to a lot throughout the program. Let's break down the different lines:
We will now use a function that will only run once at the very beginning of our code. This is called the setup. Again, let's break this down line by line.
Up until this point, we have been using built-in functions. Now, it's time to build our own so we can switch our LEDs on and off as well as move the light back and forth. Let's break it down:
We're almost done with the coding portion of this project! All that's left is to add the function that will put everything together. So far, we have set up our LEDs and written a function to make the light move, but we have never called it so that it can be run. We will do that in the loop function. Here's the loop function broken down:
Congratulations! We have finished with the coding portion. In order to make sure there are no mistakes, click the Verify button (the checkmark) in the upper left corner. If you come across an error, make sure you have no spelling errors and that every line ends with {, }, or ;.
Now that all of the programming is out of the way, it is time to grab the breadboard and start adding our hardware. The above diagram shows exactly how everything should be set up. The color of the wires does not matter except for the black one. In electrical fields, black wires denotes the ground, which is a very important thing to have when working with circuits and, in our case, an Arduino.
Once you have everything set up, take your USB-A to USB-B cord and connect your Arduino board to your computer. You can then press the Upload button (a right facing arrow) in the upper right corner. Once it finishes, uploading, it should immediately start running the code and your light should be racing from one side of your LEDs to the other. Congratulations!
If you are having issues, here are a few common troubleshooting tips once the code has been verified: