Lab #1: Arduino Basics

The first lab was to get us acclimated to Arduino and provide us with the foundations to start developing medical devices.

Part 1:

The first part of this lab was simply downloading the program and then mounting the LCD to a "backpack" so that building a circuit with the LCD would not be a mess of wires every time we used it. Mounting the LCD to the backpack involved some soldering - which was a little hard to get used to!
The LCD mounted onto the backpack. As you can see, there are only 4 wires required to connect to the Arduino. 

The underside of the LCD. If you look closely, you can see the great job Maddie did at soldering.

Part 2


Serial Output: 
This portion of the lab introduced us to "sketches" and how Arduino libraries work. This is necessary for later when we need Adafruit.LiquidCrystal to use the LCD screen.

The first coding we did involved printing a phrase to the Serial Monitor.

Then, we moved onto using variables - still all within the Serial Monitor.














This image has an empty alt attribute; its file name is image-4.png
As you can see, the code says to print the string "my number is" and then the variable "x" - which is equal to 44, in this case.
The next step involved having our variables change with each iteration of the loop.




























In this code the "for" loop has the variable "i" which changes upon each iteration. In hindsight, the "int x = 44" was unnecessary but this was left over from the previous exercise. 















A screenshot of the Serial Monitor printing the above code. As you can see, the loop counts up one at a time until it reaches 15 and then begins again from 0.

My First Hardware Project - Digital Output
This is our completed LED circuit with a red LED light and a 470-ohm resistor in series to limit the current.


This image has an empty alt attribute; its file name is messages-image1459707308.png
The above is the code used to blink the LED on and off.




LED Blinks Faster




LED Blinking in Alternation


Second Hardware Project - Digital Input

The next hardware project was to build a circuit with a pushbutton and to read its state of being pressed vs non-pressed.
This is our circuit with the 10k Ohm resister. The resister is there to limit current flow from +5V directly to ground when the pushbutton is pressed.













This is the code we used to read the button state (of being pushed or not). The digitalRead of a button when unpressed is "1," and when it is pressed it is "0."




Next, we began looking at if-else loops.

Using the LCD

In order to use the LCD, we downloaded the Adafruit Liquid Crystal library. In order to include the library when coding, it is imperative that we include lines such as 
    #include "Wire.h"
    #include "Adafruit_LiquidCrystal.h"











Counting Time

We first used the delay function as suggested. However, we noticed that there was too much of a delay when the numbers were printing to the Serial monitor.

Our code when we counted milliseconds using the millis() function. This proved to be much more accurate. 
Reaction-Time Measuring Device

Our next objective was to make a reaction-time measuring device where a microcontroller would turn an LED on, and then measure and display how long it took for the subject to press a pushbutton. The reaction time would then be displayed on the LCD. For this lab we knew we would have to use the Adafruit Liquid Crystal library, so we were sure to immediately include that library and wires when writing the code.

With this code, we had a pushbutton and an LED connected. The LED would turn on to signal to the user to press the push button, at which point there would be a digital read  of the button state. If the button was pressed, the elapsed time, or reaction time, would display on the LCD. 

We had some issues with our LCD, even after adjusting the potentiometer, leading us to believe there may have been an issue with the soldering. 








Activity Monitoring Device

For this lab, we used the pushbutton to act as a sort of pedometer that would monitor the number of steps taken in a time interval and to alert the user if the number recorded is less than the desired one.

int ledPin=10;
int buttonPin=8;
int timer=0;
int steps=0;
int threshold = 10;
int buttonState;

void setup() {
Serial.begin(9600);
// put your setup code here, to run once
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
buttonState=digitalRead(buttonPin);
timer=millis();        //Keeps track of time (ms)

if (timer<=5000)
if (buttonState==0) //button is pressed
{
steps=steps++;     
digitalWrite(ledPin,LOW);
Serial.print(steps);
Serial.print("\n");
}
else
{
digitalWrite(ledPin,HIGH);
Serial.print("Button not pressed");
Serial.print("\n");
delay(500);
}

else
{
if (steps>=threshold)
{
digitalWrite(ledPin,LOW);
Serial.print("Good job!");
Serial.print("\n");
}
else
{
digitalWrite(ledPin,HIGH);
Serial.print("Not enough steps!");
Serial.print("\n");
delay(2000);
}
}}


We uploaded this code as text because there was too much to screenshot. We do not have a video of this accurately working as we ran into some problems with the if/else loops. We used the same circuit as we did for the reaction time monitor above with the exception of switching over to using the Serial Monitor rather than LCD as there were problems with the display.








Comments

Popular posts from this blog

Lab #3: ColorPAL

Lab #4: Non-volatile memory, Servo Motors and MATLAB

Lab #5: Bio-Signals