Intro to Arduino Programming

Objective: familiarize with coding in Arduino and programming the Make Your Uno board

Personally, I have very little experience with coding, so this lab was an excellent learning experience for me. I began with coding a simple Hello World function. The task was to print the phrase "Hello World!" just once, therefore I typed the code under void setup (). I used Serial.Begin(9600) to initialize the board, and Serial.Print("Hello World!") to print the phrase in the serial monitor.
The next task was to print the phrase "Hello World!" in a loop. To do so, I used the Serial.println function under void loop(). Using println tells the program to print the next phrase in the loop one line down, rather than on the same line. 
After gaining a basic familiarity via the Hello World statements, the next task was to make an LED blink in an SOS pattern. First, following the directions in the Arduino Blink tutorial, I created a simple resistor and LED in series circuit, pictured below, which was plugged in to digital pin 7. I created the following code to blink the LED in an SOS pattern. I used the pinmode function to establish the LED as an output plugged into pin 7. Then under the loop, I created a series of digitalwrite(LED_BUILTIN, HIGH), digitalwrite(LED_BUILTIN, LOW), and delay functions at different intervals to flash the LED in an SOS pattern.


The next task was to record and print the analog output from a potentiometer. The code for this was fairly simple, only involving a line under the loop function assigning "val" as the integer read from analog pin 0 along with a serial println function to print said value. The circuit connected the three leads of the potentiometer to their respective ports: 5V, ground, and analog pin 0. This allowed the potentiometer to vary the output from 0V to 5V.

After successfully printing the varying outputs through the potentiometer, the next step was to connect an LED to shine at a varying output based on the resistance from the potentiometer. The same code from the previous step was used, just with two more lines added. The first line added was an analogwrite function which instructed the board to write the input from analog pin 0 in to pin 11, which the LED was wired in series with a resistor to. Additionally, a map function was added to allow the LED to smoothly vary from dim to bright. This map function scaled the output (0-1023) from the potentiometer circuit to the LED's range (0-255). 


The biggest learning curve for me by far was learning the language to code in Arduino. As previously stated, I have little to no previous experience with coding, so this was all a new experience. However after completing this lab I feel I have a solid base understanding of coding and how the program communicates with the UNO board. 

Comments

Popular Posts