Viviana Staicu
Accelerometer to Pedometer
Accelerometer to Pedometer
What I wanted to learn, and why it interested me:
I've been curious about these use cases for a while:
- detect if a device rightside up or upsidown
- detect how / if someone is flipping a device.
- detect if someone is tapping a table or a hard surface nearby the device.
“Registered tap” of sorts.
This is because last semester, I worked on a conceptual device that detected your presence and made it aware to people in other rooms via a little totem that you'd flip upsidown to 'clock out' per say. It was never fully realized with electronics.
Final outcome:
I want to build a pedometer that sends the text like step #83 (substituting the correct number) to the serial monitor every time a step is sensed. It will use a potentiometer to adjust sensitivity.
Doing this project will help me get a grip of managing the 'sensitivity' of the accelerometer, and be comfortable adapting it to other projects.
Images of final creative/exploratory output
LEFT: Final Video with caption annotations.
RIGHT: Screencap of me using the potentiometer to ater the step registration threshold (pink line).
Process images from development towards creative/exploratory output
Potentiometer controling the pink line (moving upwards) works! If the Y value of the accelerometer surpasses the pink line, set by the potentiometer, a 'step' is registered.
Process and reflection:
First, I started out by just trying to observe the behavior and sensitivity of my accelerometer.
It turned out that I had to whack it super hard in one axes until it registered as a 'step'.
I discovered that this was for two reasons:
I had a delay of 500ms. When you do such a long delay in your loop, arduino is only checking if a hit surpasessed the threshold every 500ms! Thats very slow frequency of checking if someone whacked the accelerometer. I removed the delay, and the issue was almost resolved.
I had to lower the threshold a bit to register a hit. 500 was too high, 430 was just right, and 420 meant no movement.
Then I hooked up the potentiometer to control the threshold level that registered a hit, and made a little counter for it.
I'm satisfied with where I ended up. I think it would've been cool to visualize the serial plotter on an oled though- its really satisfying to watch the visualization!
Technical details
Electrical schematic
/*
60-223 Intro to Physical Computing, fall 2025
Domain-specific Skill Building exercise: [Viviana's pedometer.]
Potentiometer controls a threshold.
The user should hit (hard tap on the top) the accelerometer holding it vertically on the Y axis.
If the Y value of the accelerometer surpasses the value set by the potentiometer, a 'step' is registered.
The the number of steps is counted and printed to the serial monitor. See the serial plotter for a more logical visualization.
Pin mapping:
Arduino pin | role | details
------------------------------
A0 input potentiometer
A1 input X axis > accelerometer
A2 input Y axis > accelerometer
A4 input Z axis > accelerometer
Released to the public domain by the author, January 2024
Robert Zacharias, rzachari@andrew.cmu.edu
*/
/*
* This program reads an accelerometer connected to ACCEL_X_PIN,
* ACCEL_Y_PIN, and ACCEL_Z_PIN and sends the data back to the
* computer via serial.
*
* Branched off of the example for the accelerometer on ioref site by Perry Naseck
*/
const int ACCEL_X_PIN = A1; // Analog input pin for X movement
const int ACCEL_Y_PIN = A2; // Analog input pin for Y movement
const int ACCEL_Z_PIN = A4; // Analog input pin for Z movement
const int POT_PIN = A0; // Analog input pin for the potentiometer
// Variables to keep track of the current positions
int accelXPos = 0;
int accelYPos = 0;
int accelZPos = 0;
int potThresh = 0;
int stepCount = 0;
bool wasStepping = false;
// Potentiometer setting threshold for step detection
// int readHighRes(int A2) {
// long sum = 0;
// for (int i = 0; i < 16; i++) {
// sum += analogRead(A2);
// }
// return sum / 16;
// }
void setup() {
// Setup serial port to send the accelerometer data back to the computer
Serial.begin(9600);
// Setup the accelerometer inputs
pinMode(ACCEL_X_PIN, INPUT);
pinMode(ACCEL_Y_PIN, INPUT);
pinMode(ACCEL_Z_PIN, INPUT);
}
void loop() {
// Get the current states
accelXPos = analogRead(ACCEL_X_PIN);
accelYPos = analogRead(ACCEL_Y_PIN);
// accelYPos = readHighRes(ACCEL_Y_PIN);
accelZPos = analogRead(ACCEL_Z_PIN);
potThresh = analogRead(POT_PIN);
// Send the data in Serial Plotter format (Label:Value separated by tabs)
Serial.print("X:");
Serial.print(accelXPos);
Serial.print("\t");
Serial.print("Y:");
Serial.print(accelYPos);
Serial.print("\t");
Serial.print("Z:");
Serial.print(accelZPos);
Serial.print("\t");
Serial.print("P:");
Serial.print(potThresh);
Serial.print("\t");
// Step detection: count on rising edge (transition from not stepping to stepping)
if (potThresh <= accelYPos) {
if (!wasStepping) {
stepCount++;
wasStepping = true;
}
Serial.print("STEPPED");
} else {
wasStepping = false;
Serial.print("No step");
}
Serial.print("\tSteps:");
Serial.println(stepCount);
// delay(1);
}