This week, I am building a bracelet wearable prototype for my self-tracking headache-diary project. Surprising how difficult it is to just wire up and code 7 buttons and an LED!
This is the working circuit for the 7 buttons I will use to record certain instances (when I drink water, have a meal, and my location):
I met with Ben Light this past Tuesday to discuss my wearable project. He helped me debug my code (see end of post) as my LED was flickering although no button was pressed (turns out I had a semi-colon in a few places where I didn’t need a semi-colon — details, details!) Ben encouraged me to make a more solid and smaller prototype to present to class, which I thought was a good next step with the project. So I bought a couple printed circuit boards and Ben showed me how to solder the board together today.
I am hoping to meet with Ben again either Thursday or Friday to test out my circuit now that the board is partially wired up!
I also need to figure out how bracelet-like I can make my prototype before class (velcro strap anyone?) and a good way to label my buttons. Not sure yet if I should label the buttons on my board on the left side, or save that space for my Air Pressure and Ambient Light Sensors!
This is the Arduino code, which lights up the LED whenever a button is pressed, eventually I will write code to record data:
// Set my switches as pin inputs!
const int buttonOne = 2; // pushbutton connected to digital pin 2
const int buttonTwo = 3; // pushbutton connected to digital pin 3
const int buttonThree = 4; // pushbutton connected to digital pin 4
const int buttonFour = 5; // pushbutton connected to digital pin 5
const int buttonFive = 6; // pushbutton connected to digital pin 6
const int buttonSix = 7; // pushbutton connected to digital pin 7
const int buttonSeven = 8; // pushbutton connected to digital pin 8
const int ledPin = 9; // LED connected to digital pin 9
void setup() {
// Begin serial communications
Serial.begin(9600);
// Set my digital pins as inputs or outputs
pinMode(buttonOne, INPUT);
pinMode(buttonTwo, INPUT);
pinMode(buttonThree, INPUT);
pinMode(buttonFour, INPUT);
pinMode(buttonFive, INPUT);
pinMode(buttonSix, INPUT);
pinMode(buttonSeven, INPUT);
pinMode(ledPin, OUTPUT);
}
// Begin my program to turn on the LED when a button is pressed
void loop() {
// If Button One is pressed
if (digitalRead(buttonOne) == HIGH) {
// Turn the LED on
digitalWrite(ledPin, HIGH);
Serial.println(“Button one is pressed”);
}
// If Button Two is pressed
if (digitalRead(buttonTwo) == HIGH) {
// Turn the LED on
digitalWrite(ledPin, HIGH);
Serial.println(“Button two is pressed”);
}
// If Button Three is pressed
if (digitalRead(buttonThree) == HIGH) {
// Turn the LED on
digitalWrite(ledPin, HIGH);
Serial.println(“Button three is pressed”);
}
// If Button Four is pressed
if (digitalRead(buttonFour) == HIGH) {
// Turn the LED on
digitalWrite(ledPin, HIGH);
Serial.println(“Button four is pressed”);
}
// If Button Five is pressed
if (digitalRead(buttonFive) == HIGH) {
// Turn the LED on
digitalWrite(ledPin, HIGH);
Serial.println(“Button five is pressed”);
}
//If Button Six is pressed
if (digitalRead(buttonSix) == HIGH) {
// Turn the LED on
digitalWrite(ledPin, HIGH);
Serial.println(“Button six is pressed”);
}
// If button seven is pressed
if (digitalRead(buttonSeven) == HIGH) {
// Turn the LED on
digitalWrite(ledPin, HIGH);
Serial.println(“Button seven is pressed”);
}
else {
//Led button is not on
digitalWrite(ledPin, LOW);
}
}