millerman4487
Published © CC BY-NC-SA

DIY Shock Sensor with a Speaker

A standard speaker can be used to detect vibrations and send data to a microcontroller.

BeginnerProtip30 minutes11,430
DIY Shock Sensor with a Speaker

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Speaker: 0.25W, 8 ohms
Speaker: 0.25W, 8 ohms
×1
5 mm LED: Red
5 mm LED: Red
×1
Resistor 330 ohm
Resistor 330 ohm
×2

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Code

Code snippet #1

Plain text
int shockMin = 996;  //you might need to change these
int shockMax = 1010;  //you might need to change these

void setup() {
  pinMode(11, OUTPUT);
  // Serial.begin(9600); //uncomment this to help with calibration
}

void loop() {
  int shock = analogRead(A0);
  int lightval = map(shock, shockMin, shockMax, 0, 255);
  if (lightval > 0) {
    analogWrite(11, lightval);
  }
  else {
    analogWrite(11, 0);
  }
  // Serial.println(shock); //uncomment this to help with calibration
}

Credits

millerman4487

millerman4487

10 projects • 82 followers

Comments