Abstract:
This lab introduced me to the basics of Arduino and circuitry. I learned how to power up LEDs, an LCD, use a pushbutton, and integrate with the Arduino. The lab itself was broken up into small, independent subcomponents.
Part I: Writing Your First Programs
Serial Output
- Change the program, changing “setup” to “Setup.” What happens?
“Error compiling board for Arduino”
- Try the below program
The program prints “my first arduino sketch “ endlessly
- Try these little experiments:
- Change Serial.print to Serial.println
This prints each statement on a new line
- Change Serial.begin to serial.begin
This causes an error: “serial was not declared in this scope”
- Change Serial.begin(9600) to Serial.begin(4800)
This prints the below odd characters
- Leave off the “;” at the end of a line.
Error: “Expected ‘;’ before ‘}’ token”
Variables and Numbers
Input:
Output:
These two programs have the same output as above
This program adds a 200 millisecond delay between each loop
- Now, try making a program where x changes at each iteration (x = 1, 2, 3, 4, etc). Have it increment by 1,2,10, or some other number. Try a large number, sucas 100. What happens? (You might not want to print out “my number is” all the time. Try commenting it out by adding two forward slashes (“//”) in front of it.
Input:
Output:
Digital Output
Blinking LED
Video: https://drive.google.com/file/d/1BimiJ-olYdppzwJCyMqCO2CtyvwNmb9c/view?usp=sharing
Faster flashing
Video: https://drive.google.com/file/d/1ICSzGOPNn7mLOv14dg6VXsCYnkRba9aW/view?usp=sharing
2 LEDs alternating
https://drive.google.com/file/d/1ZU9wsz_szElPw4G-HbldJQZBmgVAbmNM/view?usp=sharing
Digital Input
Using If Statements
https://drive.google.com/file/d/18BPOiJIjxc29U-onBSEWuzNj_-J_Y8Vg/view?usp=sharing
int buttonState = 1;
void setup() {
Serial.begin(9600);
pinMode(8, INPUT);
pinMode(7, OUTPUT);
}
void loop() {
buttonState = digitalRead(8);
if(buttonState == 0){
digitalWrite(7, HIGH);
} else {
digitalWrite(7, LOW);
}
Serial.print(buttonState);
}
Your First LCD Project
Video: https://drive.google.com/file/d/1KWtQSsBJva-ZFv-HhUdGEPnRvIRAmOTP/view?usp=sharing
Your First Medical Device
Printed two statements with 30 second (30000ms) delay, stopwatch recorded 31.87 and 31.65 seconds for an average of 31.76s. This represents a 5.7% difference.
Millis input
Millis output
Part II: Our First Medical Devices
Abstract: This block covered two simple medical devices, described below.
Reaction Time:
The first experiment measured reaction time. I had the Arduino light up an LED and after it lit up the user would have to press the pushbutton (which the Arduino would read as a 1) and then their reaction time would be reported. Below is the code and video for the device.
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(2, INPUT);
delay(300);
digitalWrite(13, HIGH);
millis();
while(digitalRead(2) == 0){
continue;
}
Serial.println(millis());
digitalWrite(13, LOW);
}
void loop() {
}
https://drive.google.com/file/d/1Qu80YgSQ6G7MBQJO75EOHh8apeCow18k/view?usp=sharing
Step counter: The second device was a step counter. The Arduino measured how many times a pushbutton was pressed in a given time and reported it via the Serial Monitor. Below is the code and video.
int count = 0;
void setup() {
Serial.begin(9600);
pinMode(2, INPUT);
Serial.println(“Start!”);
}
void loop() {
millis();
while(millis() < 5000){
if(digitalRead(2) == 1){
count = count + 1;
while(digitalRead(2) == 1){
continue;
}
}
}
Serial.print(count);
Serial.println(” steps taken!”);
delay(5000);
count = 0;
}
Video: https://drive.google.com/file/d/1-idzt424F55KLm-j63S72kY4G9cO8fWV/view?usp=sharing