Tuesday, March 1, 2016

Arduino Introduction Part 1

Day 10 (2/26/16)

Today we were introduced to Arduinos. Arduinos are very cool micro-controllers that can be used for many different functions. They have many different components and they look like this:


After we set up the Arduino and downloaded the software on the the computer, we then had to complete several mini-challenges to learn how the Arduinos work and to learn the structure of the code. Luckily for me, I have prior experience coding, so I understand the thought process and the progression through the code. That experience helped me to understand where the code needed adjusting to accomplish a specific task. I also have experience using breadboards and putting together circuits, so that came in handy as well. The mini-challenges are documented below:

Challenge #1 "Blink with delay of 10"

Our first challenge involved only the Arduino, an LED light and the computer. We were tasked with programing the LED to blink with a "delay of 10" which in the code means 10 milliseconds. We accomplished this by opening up a preprogrammed sketch and then just adjusting one parameter, the delay. Our code looked like this:




Lines 26 and 28 are where we specify the delay time. For this situation, we changed the delay time to 10 milliseconds inside the parentheses. When you run this code, the light appears to be on continuously. Don't let that fool you though, it is really flashing in pulses of 10 milliseconds but that speed is not visible to the human eye.



Challenge #2 "Pattern with at least 3 LEDs of different colors using the delay() function"

Our next task was to adjust our code and set up our circuits to command three different color LED lights to turn on in a cool pattern. To do this Meba and I just copied and pasted the sections of our code for each individual LED light. We then renamed the pin to the corresponding pin number for each LED. Since the information was coded in a loop, the process would go through all of the individual blocks of code for each light and created a pattern of changing lights. Here is what our resulting code looked like:


In this code we initialize digital pins 11, 12, and 13 and then we run the loop with all three LED functions that specify different delay times for each. We played around a lot with the different delay times for each LED light and here is a video of one of our favorite patterns:



Challenge #3 "Use potentiometer to change the LED behavior based on the resistance"


For the third challenge, we had to set up the circuit so that the potentiometer would control some function of the LED light. We designed our code and our circuit to change blinking speeds based on the resistance of the potentiometer. In order to do this, we had to first define position of the two components, the potentiometer (Pin_pot) and the LED (Pin_LED). The potentiometer was connected to A0 so we defined the integer Pin_pot as A0 and the LED was connected to pin 12 so we defined the integer Pin_LED as 12. We then defined the potentiometer value to be an integer (Pot_Value). Next we went in to the setup function to initialize the program and defined the LED to be an output. Finally in our loop we set the integer Pot_Value to the analog value received by the Arduino from the potentiometer. This value will depend on the position of the potentiometer. Finally we added the code to make the LED turn on and off. Our resulting code looked like this:


We set up our circuit so that the LED was connected to pin 12 and the potentiometer was connected to pin A0, the power and groundOur resulting circuit looked like this (ignore the other two LEDs connected, we did not set them up in our code so they wont do anything):




And here is a video of the speed of the flashing of the LED changing depending on the position of the potentiometer:


Challenge #4 "Pattern with 3 LEDs of different colors that does not use the delay() function"

Our fourth and final challenge was to create a pattern of three different LED lights that does not use the delay function as we did previously in challenge #2. This way, we could make a pattern where the program does not have to do only one function at a time. With this new function we can tell the program to turn on multiple lights at the same time or do different functions simultaneously.

For this new pattern, we set up the code so that the red and blue light would turn on when the green light turned off and vice versa. Here is what our code looked like:


The final pattern of the LED lights looked like this:




Overall, I have really enjoyed learning how to use the Arduino and learning the language. I think coding is a lot of fun and I am very excited to see what incredible things can be accomplished with the Arduino. It is such a useful tool that we, as students, are very lucky to have access to.



No comments:

Post a Comment