Arduino crib rocker

2009-04-03

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.

simple amplifier
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, dx.com, 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

2009-04-06

The assembled unit, still in testing...

arduino microphone

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.

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

Video of the complete system

2009-06-21


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

2009-09-06

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.

Code

2009-05-09

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);
servo1.attach(servoPin1);
Serial.begin(9600);
servo1.write((stime));
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!
rockcradle(20);
soundcount=4; // leave counter at high value for quick restart
}
//Serial.println(soundcount); //debug
}
////////////////////////////////////////
void rockcradle(int numberofrocks)
{
for (rcount=0; rcount<numberofrocks; rcount++){
potv=analogRead(potpin);
servo1.write((stime+potv));
delay(300);
servo1.write((stime));
delay (300);
}
}
//////////////////////////////////////////
bool listen()
{
for (int i=0; i <= 250; i++){ // count to 250 is about 5 sec...
volu=analogRead(micPin);
Serial.println(volu); // serial print value for debugging...
if (volu<600){
digitalWrite(ledPin, HIGH);
delay (2);
digitalWrite(ledPin, LOW);
delay (40);
return true;}
delay(20);
}
//tillbaka till main loop
delay(20);
return false;
}
///////////////////////////////////////
void crock()
{ while (analogRead(swpin) > 500){
digitalWrite(ledPin, HIGH);
delay (1);
digitalWrite(ledPin, LOW);
delay (0);
potv=analogRead(potpin); // to control speed...
servo1.write((stime+potv));
Serial.println(stime+potv);
delay(500);
servo1.write((stime));
delay (500);
}
///////////////////////////////////////

Navigering

Arduino