Mini Monster Box
This circuit is live in Circuit Canvas. Open it to explore every part and wire, or make your own copy to change values, swap parts and build your own version. Free, right in your browser.
This is my mini monster box: Knock on the box, and a grumpy little monster pops out to see who's there.
A microphone hears the knock, a one-transistor amplifier makes the signal big enough for an Arduino, and a servo opens the lid.
The lid opens at a random speed, stays open for a random time and closes at a random speed. Sometimes the monster peeks out carefully, and sometimes it pops up and slams the lid. That randomness is what makes it feel alive.
Check out more details on how the circuit works and how the values are calculated from https://www.build-electronic-circuits.com/mini-monster-box-halloween-project/
Mini Monster Box Schematic
An electret microphone needs a resistor up to plus to work. That's the job of R1.
But the signal out from the microphone is weak, so it needs some amplification. The transistor Q1 makes up an amplifier together with C1, R2, and R3.
When a big enough signal comes in from the mic, the signal gets amplified to a few volts so that it can easily be detected by the Arduino's analog input.
The Arduino reads the amplified signal on A0 and keeps a running average of the readings. When a knock pushes it over the threshold, it waits a moment and then runs the servo with a random opening speed, open time and closing speed.
Mini Monster Box Parts List
How to Build the Mini Monster Box
The amplifier only needs a handful of components, so it fits easily on a small piece of a stripboard next to the Arduino.
Things to watch out for:
- The electret microphone has polarity. The leg connected to its metal case is GND.
- Connect the amplifier output to A0 and the servo signal wire to pin D9.
- Connect the GND of the amplifier, the servo and the Arduino together.
Code
#include <Servo.h>
#define RUNNING_AVG_SIZE 10
#define CLOSED_POSITION 165
#define OPEN_POSITION 90
Servo myservo;
const int servoPin = 9;
const int soundPin = A0;
float averaged_value = 0;
int pos = 0; // variable to store the servo position
void setup() {
Serial.begin(9600);
myservo.attach(servoPin); // attaches the servo on pin 9 to the servo object
closeLid(70);
}
void loop() {
int sensorValue = analogRead(soundPin);
// Averaging
float alpha = 0.1; // factor to tune
averaged_value = alpha * sensorValue + (1-alpha) * averaged_value;
Serial.print("sensor = ");
Serial.println(sensorValue);
Serial.print("averaged_value = ");
Serial.println(averaged_value);
if (averaged_value > 500) {
delay(1000);
openLid(random(1, 5));
delay(random(50, 2000));
closeLid(random(1, 5));
delay(2000);
averaged_value = 0;
}
}
void closeLid(int speed) {
for (int pos = 90; pos < CLOSED_POSITION; pos += speed) { // goes from 0 degrees to 180 degrees
// Make sure we don't go above CLOSED_POSITION:
pos = min(pos, CLOSED_POSITION);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
void openLid(int speed) {
for (int pos = 165; pos > OPEN_POSITION; pos -= speed) { // goes from 180 degrees to 0 degrees
// Make sure we don't go below OPEN_POSITION:
pos = max(pos, OPEN_POSITION);
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Make it your own
Every circuit here is a live project in Circuit Canvas, not just a picture. Copy this one and change a value, swap a part or move it to a stripboard: the schematic and the breadboard layout are linked, so a part added to one appears in the other.
Or start from a blank canvas and draw your own circuit, with thousands of ready-made parts.