Sunday, March 8, 2015

Arduino Day 1

The Assignment:
In order to explore the ideas of Feedback and control, we were challenged to create a code to control a series of LED lights to blink in a pattern, first using the Blink with delay program and then the Blink with no delay.

Relevant Physics:
The Arduino program utilizes a coding software that can control a bread board. Some basic physics concerning Electricity is needed before building circuits. The biggest equation to remember for circuits, is the equation V=IR where V = voltage (volts) I = current (amps) and R = resistance (ohms).  How this equation is applied changes depending on whether the resistors in the circuit are in series or parallel. In the drawing below, the top arrangement is in series, while the bottom is in parallel. 




Step One:
The first step in this process was to see if our arduino would execute the Blink with Delay program using the embedded in LED square on pin 13. This was simple enough since all we had to do was hook the arduino up and upload the program.


Step Two:
Next we experimented with the program by altering the delay times. we found that without a certain amount of time delay, the light would tune on and off so quickly that we wouldn't be able to tell that it was turning off at all. The result is that the light simply looks light it is always on.


Step Three:
We then altered the program so that the LED light would stay on for 2 second (2000 ms) and stay off for 1/2 second (500 ms) so that the blinking pattern was now slow enough that our eyes could register it.


Step Four:
After completing step three, we left in the LED and resistor that was in pin 12 already. We then rewrote the Blink with delay code so that it would make both the LED in pin 12 and the LED built into the board light up in a pattern. The pattern we wanted to emulate was that of a drummer in a 4 beat rhythm pictured below. Each circle denoted the LED is on, the dash denotes that the LED is off. The delay times for each symbol is 250 ms (1/4 second). Notice how we didn't include the last line of the 4 beat pattern since the program will simply repeat itself.
Writing a program for this pattern proved to be more difficult than we initially thought. At first we tried to address each pin separately with its own delay pattern. We found that doing it that way made one pin go and then the next without actually executing the pattern(the defective code is shown below).

We fixed this by grouping the code into delay segments then telling both pins what to do within that delay period. This code functioned how we wanted it to!



Step Five:
After we got our pattern for two LED's to function correctly it was fairly straight forward to rewrite the program to include more pins. We added more LED's and resistors to our bread board in order to create a more complex patter using the Blink with delay program. The pattern we wanted to make this time was scale that traveled up and down the line of LED lights.


At first, only our first two lights would light up brightly, while the others lit up very dimly. At first we though there was a problem with they way we had connected the LED's to the bread board. After playing around with it, we realized that this was not the case. We then looked back through our code and found that the reason that two of the lights wouldn't light up brightly was because we forgot to name the other pins as an output early on in the code.

This video shows how the LED's behave if their corresponding pins are not named as outputs.

 This video shows how the LED's behave once their corresponding pins are named as outputs.

Since we were ahead of the class we decided to make another cool pattern before moving on to the blink with out delay program. Our new pattern used 5 pins and sought to make the lights look as if they were crossing each other.
 The code is as follows...

And her is the video!

Step Six:
Our last challenge of the day was to use the Blink without delay program that Arduino supplies and to rewrite it to include more pins and to create a new pattern. This type of code allows the program to operate on different levels by not suspending the code with a delay. since we are unfamiliar with the language of the code, we had difficulty trying to write more complex codes like the two we did in set five. We tried to Google different codes and tutorials, but many of the tutorials assumed that we would know and understand the code language enough to follow without a thorough explanation.



This is the Blink without delay program only altered to include five pins.

To make the pattern more complex we simply changed the times.





Reflection:
After working with even this simple code, I became distinctly aware that coding language is a complex language all its own. The limit to the patterns we were able to create depended on our knowledge of the coding language, much of which we did not know. It was also apparent that when writing code, one must be acutely aware of the details involved so as not to make a small error that could prevent the entire code from functioning correctly. 

1 comment:

  1. This blog is very thoroughly written and I really liked how you provided diagrams to explain the concepts behind the Arduino programming. I was able to understand the code more and learned something new too!

    ReplyDelete