Sunday, February 7, 2016

Lab 1: The Basics

The purpose of this lab was to introduce us to the basic structure and the most important functions of the Arduino. We worked with LED lights, text input/output, LCD display, and a pushbutton switch to complete the lab tasks.

What we learned overall in this lab:

1. The "upload" button writes the program onto the microcontroller forever.
2. The "compile" button checks to see if the program has any errors regarding syntax. Of course, if the code is written improperly, then the compile button may still show that there are no errors. In this case, it's just that the code runs differently from what is desired.
3. Proper capitalization will determine whether the program runs properly!
4. The improper resistor will not let the circuit work. We ran into an issue here during Part 1 because we did not see the "K" when we grabbed a 470K Ohm resistor rather than a 470 Ohm resistor. Lesson learned.


Part 1: Digital Output


Here, we made two LEDs flash in alteration and then increased the speed at which they flashed over time. We utilized a loop that began with the delay time i = 200 ms and then had the value of i change by -200 for each time the loop ran again. As a result, the LED blinked faster over time until there was no delay. The resistor strength we used is 510 ohms.

*We learned that the LED positive end (longer end) is what connects to the resistor and the negative end connects to the ground.

The code is attached here. The video is below.

Flashing LEDs


Figure 1 1: Single LED Circuit

Figure 2: Double LED Circuit

Part 2: Digital Input


Here we used the print() function so the Arduino could provide text output to the computer. Basically, we are going to connect a pushbutton to the microcontroller and read its state, whether it is pressed or not pressed. Then, if the pushbutton is pressed, the LED will light up.

You can find the text output through the Serial Monitor (Ctrl + Shift + M). This time we faced some issues, but not with resistors. We assigned the value of 1 to the buttonState in the for loop. Here, our syntax was off in that we should have done is use "= =" instead of "=" when assigning this value within the for loop.

Figure 3: Pushbutton circuit provided digital output to the computer



To make the LED light up when the push button is pressed, we added another simple circuit to incorporate the LED. We then adjusted the code by implementing the digitalRead function to determine whether the light is on.

Figure 4: When the pushbutton is not being pressed the LED is not lit.

Figure 5: When the pushbutton is pressed the LED lights up.

The code is attached here and the top section refers to the reading only the button state whereas the bottom section refers to the LED lighting up based on whether the button is pressed.


Part 3: Using the LCD


In this portion of the lab, we attached the LCD to the Arduino and then programmed a series of steps that require a countdown and change of display. The LCD display first wrote "Hello BE 470 Student!" and then began a countdown for ten seconds until writing "Blast Off!" The code is attached here. The video is below. Some photos of the circuit also follow.


Connections. There is a terminal block on the backpack with five connections. You will need to make four connections with your jumper wires:

  1. Connect GND on the backpack to GND on the Arduino or protoboard.
  2. Connect 5V on the backpack to 5V on the Arduino or protoboard
  3. Connect DAT on the backpack to A4 on the Arduino
  4. Connect CLK to A5 on the Arduino.

LCD Display:





Fortunately, we did not run into many blunders with this portion of the lab. However, we struggled to figure out a loop when running the countdown. To make sure the remainder of our code was appropriate, we did not put a loop into use, but re-wrote the code for every number (9, 8, 7, etc.).

After some time, we figured out the appropriate code and the loop made our code more elegant.


Part 4: Medical Devices


Medical Device 1: 


The first portion was to create a reaction-time device. Essentially, the LED would light up in a random amount of time between zero and three seconds. Then the subject would press the pushbutton. The LCD display would write the delay between the LED lighting up and the pushbutton being pressed.

We also compared the accuracy of the millis() function versus the delay() function. We discovered that the millis() function returns the number since the Arduino board first begins running the current program. It would be more accurate than using the delay() function.



Here are some images that show the circuit:





To show the reaction-time device's accuracy, we have uploaded two videos where one reaction time is short (fast reflex) and one where the reaction time is long (slow reflex). Creating the measured elapsed time was difficult because there were various bugs in our code. The code is attached here. The videos for a slow and a fast reaction time are below.

Slow video:

Fast video:



Medical Device 2:


The second portion of this lab was to create a distance-tracker device, similar to a Fitbit. This portion of the lab was not as difficult to program because the code was similar to the code used for making the LED light up when the pushbutton is pressed (earlier part of Lab 1). In this lab however, we had to add in a portion where the Arduino kept track of the number of times the pushbutton was pressed so that after a designated number, the LED would no longer light up and therefore let us know that the target number of "steps" was achieved. This was simply added by recording the number of times the pushbutton was pressed and using an if statement. The code shows that if the number of times the button was pressed is less than five, then the LED stays on and the LCD displays the number of steps taken. However, once the number reaches five, the LED is no longer lit.



The circuit was the same with this medical device as it was for the first device. The code is attached here. The video for the distance tracker is below.

Distance Tracker Device:

No comments:

Post a Comment

Disqus Shortname

Ads Inside Post

Comments system