i have a baby and i wanna shake her bed when we cries, what i am missing? thank

i have a baby and i wanna shake her bed when we cries, what i am missing? thank you friend

i have sound sensor and servo motor(mg996r) and arduino mega

i try many code but i did not success can you help me

i wanna sound sensor hear voice then servo shake 2 minute , if there is no vioce servo is stopping

So what is the problem? what have you tried and what is the result?

I have setup something similar where it detects sound and turns power off to my device.. and if its past a certain time range, then i keep the power off until next morning..

Post example of your code or results of what has happened so others can help

firstly i tried

////////////////////////////////
int soundDetectedPin = 10; // Use Pin 10 as our Input
int soundDetectedVal = HIGH; // This is where we record our Sound Measurement
#include <Servo.h>

Servo servo1;
int pos1 = 0;

boolean bAlarm = false;

unsigned long lastSoundDetectTime; // Record the time that we measured a sound

int soundAlarmTime = 500; // Number of milli seconds to keep the sound alarm high

void setup ()
{
Serial.begin(9600);
pinMode (soundDetectedPin, INPUT) ;
servo1.attach(9); // input from the Sound Detection Module
}
void loop ()
{
soundDetectedVal = digitalRead (soundDetectedPin) ; // read the sound alarm time

if (soundDetectedVal == HIGH) // If we hear a sound
{

lastSoundDetectTime = millis(); // record the time of the sound alarm
// The following is so you don’t scroll on the output screen
if (!bAlarm){
for(pos1 = 0; pos1 < 180; pos1 += 1)
{
servo1.write(pos1);
delay(10);
}
bAlarm = true;
}
}
else
{
if( (millis()-lastSoundDetectTime) > soundAlarmTime && bAlarm){
for(pos1 = 180; pos1>=0; pos1-=0)
{
servo1.write(pos1);
delay(10);
}
bAlarm = false;
}
}
}
////////////////////////////////

then i tried

#include <Servo.h>
Servo servo1;
int pos1 = 0;
int volume;
int threshold = 50;
void setup()
{
Serial.begin(9600); // For debugging
servo1.attach(9);
}
void loop()
{
volume = analogRead(A0); // Reads the value from the Analog PIN A0
if(volume>=threshold){
for(pos1=0; pos1<180;pos1++)
servo1.write(pos1);
delay(50);
}
else{
for(pos1=179; pos1<0;pos1–)
servo1.write(pos1);
delay(50);
}
}

but nothing happen.

i need to know when sensor passed treshold what we write for servo fonk

 Serial.begin(9600); // For debugging

Never actually uses Serial for debugging in the whole code

O....kay?

Ill try to remember and post my code i used when i get home, but i dont have the Arduino IDE installed at work, so cant look help to much at the moment, but i what i did first was setup the sound detector, write it out to the serial monitor so i could see what it was picking up just by running, then i created some loud sounds, clapping, shouting, banging on the desk to get different reading, for my project i wanted it to work when it was extremely loud.. i didn't want just any small noise to trigger it.. so once i got those different base lines, i was able to right the code to only trigger at certain levels of sound..

when i get home, ill plug your code into a project and run against my hardware and see what it does for me..

ill post my code for you to review and work from if it helps..

cubangt:
Ill try to remember and post my code i used when i get home, but i dont have the Arduino IDE installed at work, so cant look help to much at the moment, but i what i did first was setup the sound detector, write it out to the serial monitor so i could see what it was picking up just by running, then i created some loud sounds, clapping, shouting, banging on the desk to get different reading, for my project i wanted it to work when it was extremely loud.. i didn't want just any small noise to trigger it.. so once i got those different base lines, i was able to right the code to only trigger at certain levels of sound..

when i get home, ill plug your code into a project and run against my hardware and see what it does for me..

ill post my code for you to review and work from if it helps..

Please read the 'how to use' post at the top of the thread listing, and use the code tags for your code.

Hello,

Sorry to be so brutally critical, but to Keep it nice, that code is not going to work.

“for(pos1=179; pos1<0;pos1–)” is going to execute once at most.
Completely Independent of the Sound Level:
else{
for(pos1=179; pos1<0;pos1–)
servo1.write(pos1);
delay(50);
would constantly be trying to (assuming the for command were corrected) go from Position 179 to 0.

I would recommend that you start of in very small increments and work slowly toward your end Goal. Start by detecting the Sound. If it is over the threshhold, turn an LED on for a few seconds, then turn it off.

Once that is working, Change the code that lights the LED on for a few seconds and then back off to code that moves the servo one time from Position 0 to 180, one time from 180 to 0. and leave it there.

Once that works, put the code that moves the servo in a for Loop that executes a few times. Play with the number of executions until it takes two minutes.

Please remember that 180 degrees in one direction basically turns the babies bed upside down.

If you get stuck at any of these steps, post the code and we will see what we can do to help you.

cubangt:
Ill try to remember and post my code i used when i get home, but i dont have the Arduino IDE installed at work, so cant look help to much at the moment, but i what i did first was setup the sound detector, write it out to the serial monitor so i could see what it was picking up just by running, then i created some loud sounds, clapping, shouting, banging on the desk to get different reading, for my project i wanted it to work when it was extremely loud.. i didn't want just any small noise to trigger it.. so once i got those different base lines, i was able to right the code to only trigger at certain levels of sound..

when i get home, ill plug your code into a project and run against my hardware and see what it does for me..

ill post my code for you to review and work from if it helps..

ok i am waiting for your code. thank you so much

JaBa:
Hello,

Sorry to be so brutally critical, but to Keep it nice, that code is not going to work.

“for(pos1=179; pos1<0;pos1–)” is going to execute once at most.
Completely Independent of the Sound Level:
else{
for(pos1=179; pos1<0;pos1–)
servo1.write(pos1);
delay(50);
would constantly be trying to (assuming the for command were corrected) go from Position 179 to 0.

I would recommend that you start of in very small increments and work slowly toward your end Goal. Start by detecting the Sound. If it is over the threshhold, turn an LED on for a few seconds, then turn it off.

Once that is working, Change the code that lights the LED on for a few seconds and then back off to code that moves the servo one time from Position 0 to 180, one time from 180 to 0. and leave it there.

Once that works, put the code that moves the servo in a for Loop that executes a few times. Play with the number of executions until it takes two minutes.

Please remember that 180 degrees in one direction basically turns the babies bed upside down.

If you get stuck at any of these steps, post the code and we will see what we can do to help you.

in fact i am a math teacher and i am trying to write code but i did not. please help me, if you know how u write code it tooks 2 minute for you. thank you for helping

Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

TomGeorge:
Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile:

ok i will thank you

Something to get you started that works.

#include <Servo.h> 
 
Servo myservo;  // create servo object to control a servo 
                // twelve servo objects can be created on most boards
 
int pos = 0;    // variable to store the servo position 
 
void setup() 
{ 
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
} 
void loop() {
   myservo.write(pos);              // tell servo not to sling the baby 
   while (analogRead(0) >= 500) {  // set this with your baby and him crying 
    
    rockBaby();
  }
}
void rockBaby() 
{ 
  for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees 
  {                                  // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=0; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(15);                       // waits 15ms for the servo to reach the position 
  } 
}

ChrisTenone:
Please read the ‘how to use’ post at the top of the thread listing, and use the code tags for your code.

Not sure why this is directed at me, but I haven’t posted any code in this post and when I do I do use the code tags.

ercinoyman here is what I used for my project, I kept it simple, I’m sure it can be improved on, but give you an idea and works great for me… with mine I used a RTC to determine the time of day to prevent the power from being turned off when I’m actually outside working…

void setup()
{
  // Setup Serial connection
  Serial.begin(115200);
  // Uncomment the next line if you are using an Arduino Leonardo
  //while (!Serial) {}
  
  // Initialize the rtc object
  rtc.begin();
  
  // The following lines can be uncommented to set the date and time
  //rtc.setDOW(WEDNESDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(1, 1, 2014);   // Set the date to January 1st, 2014

  // Configure Relay as output
  pinMode(RELAY1, OUTPUT);

  // Configure LED pin as output
  pinMode(PIN_LED_OUT, OUTPUT);

  // configure input to interrupt
  pinMode(PIN_GATE_IN, INPUT);
  attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);  
}

void loop()
{

  // Get time from Board
  t = rtc.getTime();
  
  // Send Day-of-Week
  //Serial.print(rtc.getDOWStr());
  
  // Send date
  //Serial.print(rtc.getDateStr());

  // Send time
  //Serial.println(rtc.getTimeStr());

  // Sound Detector Value
  int value;

  // Check the envelope input
  value = analogRead(PIN_ANALOG_IN);

  // Determine if its to loud
  if (value >= 150)
  {
    TOLOUD = true;
  }
  else
  {
    TOLOUD = false;
  }

  // Determines if it is quiet time 9pm to 9am
  if(t.hour >= 21 || t.hour <= 9)
  {
    if(TOLOUD)
    {
      digitalWrite(RELAY1,1);
    }
  }

  // Determines if it is work time 9am to 9pm
  if(t.hour >= 9 || t.hour <= 21)
  {
    digitalWrite(RELAY1,0);
  }  
  
  // Wait one second before repeating :)
  delay (1000);
}

i have a baby and i wanna shake her bed when we cries, what i am missing?

'You' should check why she cries.

.

LarryD:
'You' should check why she cries.

.

Haha I was thinking the same thing. It's like when someone posts a "How do I make an automatic stabbing machine?" type question. I'm intrigued by the problem and a part of me wants to help, but I suppress that part of me and move on.

These new kids with babys shake there babys till they need a shaker. Rocker was what I used and I held them till they was asleep and that was at bed time and there still not spoiled even now that there grown up enough to save there own money. But even we may need a shaker now days.

cubangt:
Not sure why this is directed at me, but I haven't posted any code in this post and when I do I do use the code tags.

Sorry man. I got your post mingled with the original post. with the inline code.

Quote from: LarryD on Today at 12:16 am

'You' should check why she cries.

.

Haha I was thinking the same thing. It's like when someone posts a "How do I make an automatic stabbing machine?" type question. I'm intrigued by the problem and a part of me wants to help, but I suppress that part of me and move on.

i have a baby and i wanna shake her bed when we cries, what i am missing? thank "

an my first thought was :

parenting skills.

you might want to add an gas/odor detector to the mix.