Arduino crib rocker


This is not intended as a howto, more a project description so that I know what I did...

I wanted something that could detect a baby screaming, and then gentle start to rock the bed for a while, giving me and my wife maybe just an extra half hour of sleep.
The Arduino can control a hobby servo just fine, so I needed some way to detect loud noise.

First step is a microphone but it can not be directly connected to the arduino. I searched for a super simple amplifier, and found one with only 5 components; one transistor (BC547), 3 resistors and a small cap, stuff that I already had. Polarity matters for the microphone, so do not just solder the wires in place.

Amplifier circuit.

The Arduino is reading the input from the simple a transistor amplifier, then deciding if it is time to start the servo.

The microphone and servo extention cables is from my favourite online store,, with Worldwide Free Shipping!

After the first tests a mode switch was added to use as a "get to sleep rocker", not having to wait for the baby to start crying and with a continius motion. 

It would be better with two pots, controlling both stroke and speed. Now I set everything up to get the right speed for the bed and then reprogram the pot as a stroke controller.

All the components


The assembled unit, still in testing...


Electronics in a box.

bed springs

Springs with bolts, springs 75 mm long, diameter 26 mm, M12 bolts.

bed springs
                on board
Springs hot glued to separator board.

                mic amp
The amplifyer and arduino wiring. A mode switch has been addes since the first pictures.

Video of the complete system


Things that I would do different if I did it all over again


The system is working, I am using it right now as I am writing this, but...

Two pots to adjust stroke and frequency independent.

Quiet, high quality servo. The cheap one is a little loud.

Get a real, high power, 5V adapter from the start. A USB charger can not feed a big servo and the arduino.



Arduino code, still in some development. This is v0.3

#include <ServoTimeTimer1.h>
#define servoPin1 10
ServoTimeTimer1 servo1;
int micPin = 0; //mic. amp to pin 0.
int ledPin = 7; // LED connected to digital pin 7
int potpin = 2; // 10K pot on pin 2
int swpin = 3; // mode switch
int potv = 0; // value from pot
int stime = 800; // servo timer in rest. 500 to 2500.
int rcount = 0; // rock count in loop
int volu = 0; // detected sound
int soundcount = 0; //number of detected sounds
int numberofrocks = 0; // rumber of rocks to be
boolean trigg=false;

void setup()
pinMode(ledPin, OUTPUT);
pinMode(potpin, INPUT);
pinMode(micPin, INPUT);
pinMode(swpin, INPUT);
digitalWrite(ledPin, LOW);
void loop()
if(analogRead(swpin)>500) crock(); // check if the input is HIGH, go to sub crock)
if (listen()==true)soundcount=soundcount+2;
//if the counter is above 0, reduse.
if (soundcount>0) soundcount=soundcount-1;
if (soundcount>=5) { //check counter, if high, rock the cradle!
soundcount=4; // leave counter at high value for quick restart
//Serial.println(soundcount); //debug
void rockcradle(int numberofrocks)
for (rcount=0; rcount<numberofrocks; rcount++){
delay (300);
bool listen()
for (int i=0; i <= 250; i++){ // count to 250 is about 5 sec...
Serial.println(volu); // serial print value for debugging...
if (volu<600){
digitalWrite(ledPin, HIGH);
delay (2);
digitalWrite(ledPin, LOW);
delay (40);
return true;}
//tillbaka till main loop
return false;
void crock()
{ while (analogRead(swpin) > 500){
digitalWrite(ledPin, HIGH);
delay (1);
digitalWrite(ledPin, LOW);
delay (0);
potv=analogRead(potpin); // to control speed...
delay (500);