Accelerometer
Accelerometer
What I wanted to learn, and why it interested me: I wanted to learn about the accelerometer because it represents changes that we all physically experience: tilt, vibration, acceleration, etc.
Final outcome: I have an accelerometer and an LED on my breadboard wired up to the Arduino. When I have the breadboard simply lying flat, the serial monitor displays vibration level as 0 and the LED is not lit. When I start to shake it, the vibration level goes up (can go all the way up to 10) and the LED gradually gets brighter.
Images of final creative/exploratory output
The mechanism includes an accelerometer and an LED.
When I pick up the accelerometer and shake it, the LED grows brighter as the movement intensity increases.
Process images from development towards creative/exploratory output
Process of wiring up the accelerometer to the Arduino.
Testing the accelerometer and how its movement is logged on all 3 axes in the serial monitor.
Process and reflection:
I started by using what I learned in the technical skill-building, which was knowing how the accelerometer tracked orientation using the X, Y, and Z axes. Then, I began by wiring up the accelerometer to pins A0, A1, and A2 to to read information for all 3 axes. After the accelerometer, I wired up the LED as usual, with connections to ground and 5V along with a resistor. After, I began doing the coding portion by defining all the pins and pin modes. Most of the pins were input while the LED is wired up to an output pin. The coding wasn't too complex, and mainly revolved around the logic of defining the difference between its original position and its current position. The logic is as follows: as the difference gets greater, the vibration level increases, and the LED gets brighter. While there were a few hiccups, I was able to get through the coding portion rather smoothly, and I'm pretty satisfied with where I ended up.
Technical details
Electrical Schematic
/*
60-223 Intro to Physical Computing, fall 2025
Domain-specific Skill Building exercise: Accelerometer
This sketch connects to an accelerometer and an LED to measure vibration and generate
an output to the LED in response to it. Its function is to measure the movemente of the
accelerometer relative to its original position, map that vibration to a level from 1 to 10,
and control the brightness of the LED based on how strong vibration is.
Pin mapping:
Arduino pin | role | details
------------------------------
A0 input XPin
A1 input YPin
A2 input ZPin
5 output LED
*/
const int XPIN = A0;
const int YPIN = A1;
const int ZPIN = A2;
const int LEDPIN = 5;
int restingY = 0;
void setup() {
pinMode(YPIN, INPUT);
pinMode(LEDPIN, OUTPUT);
Serial.begin(9600);
// resting val when board is still
restingY = analogRead(YPIN);
}
void loop() {
// tests the different from original to current ypin value (vibration)
int diff = abs(analogRead(YPIN) - restingY);
// mapping
int vibLevel = map(diff, 0, 60, 0, 10);
vibLevel = constrain(vibLevel, 0, 10);
// led brightness based on vibration level
int brightness = map(vibLevel, 0, 10, 0, 255);
analogWrite(LEDPIN, brightness);
// debugging output
Serial.print("X=");
Serial.print(analogRead(XPIN));
Serial.print("Y=");
Serial.print(analogRead(YPIN));
Serial.print("Z=");
Serial.print(analogRead(ZPIN));
Serial.print(" vib=");
Serial.print(vibLevel);
Serial.print(" LED=");
Serial.println(brightness);
delay(100);
}