To make a vibration alarm and when there is vibration, the buzzer will set off alarm audio twice.
#define pushButton 4 //Vibration
#define speakPin 6 //Buzzer
if (millis() - time > 2000)
{
if (!digitalRead(pushButton))
shock = false;
time = millis();
}
if (shock)
{
for (int j = 0; j < 2; j++)
buzzer();
}
else
noTone(speakPin);
When knocking on the vibration sensor, the buzzer will make alarm twice and will stop when there is no vibration after the alarm. You can also build a beautiful shell with LEGO for the project since mCookie can be easily stacked with LEGO boards.
。