Kirollos Magdi Sobhy
Published

Crying Baby Detector Using 1Sheeld

Baby monitor that can also help put your baby back to sleep.

Full instructions provided14,174
Crying Baby Detector Using 1Sheeld

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
1Sheeld
1Sheeld
×1
Android device
Android device
×1
LED (generic)
LED (generic)
Green-Yellow
×2
5V Relay
×1
NPN Transistor 2N2222
×1
Resistor 10k ohm
Resistor 10k ohm
×1
1N4004 Diode
×1
Baby Toy
×1
9V Battery and a clip
×1
Box
×1
Switch
×1

Story

Read more

Code

code.txt

C/C++
include<one.sheeld.h>
String account = "imtheparent2015";// The parent account on twitter
String Message0 ="Arduino Now is on Monitoring Mode , Stay tuned for any updates";
String Message1 = "The baby is crying ,The Arduino is on SleepingMode right now stay Tuned For any updates";// The Arduino message for the parent at the Sleeping Mode
String Message2 = "The baby is awake ,The Arduino is on WakingMode right now , and playing some songs";// The Arduino message for the parent at the Waking Mode
String Message3 = "The baby is now asleep ,You Are Safe :D";// The Arduino message for the parent at the Sleeping Mode
String Message4 ="The Baby is still crying ,Stay tuned for any updates";
int green=13;//Green LED (Checking LED)
int red=12;//Red LED (Alert LED)
int toy=10;//Toy relay pin
int cry=0;//Checking if the baby is crying,If cry ==10 so the baby is crying
int x=0;//For checking if the program passes through sleepingMode 1
int y=1;//For checking if the program passes through sleepingMode 2
int z=0;//For checking if the program passes through WakingMode
boolean mon=true;//For the monitoring mode to run it only one time
////////////////////////////////////////////
void setup() 
{
  pinMode(toy,OUTPUT);//Toy relay circuit
  pinMode(green,OUTPUT);//Green for Monitoring Mode
  pinMode(red,OUTPUT);//red for alert
  OneSheeld.begin();//Begining of 1SHEELD
}
////////////////////////////////////////////
bool Crying()//Responsible for getting the value of the Mic(Crying Sound) 
{
   //Getting the sound
  if(Mic.getValue() >=80)// Sound of the crying baby (Measured by dBs)
  return true; // True = Baby is crying
  else 
  return false; //False = Baby is sleeping
}
///////////////////////////////////////////
void MonitoringMode()//send the message to confirm that arduino is working
{
  if(mon==true)
  {
  Twitter.sendMessage(account,Message0);//sending message
  mon=false;//to insure that the program doesn't run it again
  }
}
///////////////////////////////////////////
void SleepingMode()//First function that the program passes by`if the baby is crying
{
  MusicPlayer.play();//Playing some quiet music for the baby
  Twitter.sendMessage(account,Message1);// Sending a message on twitter for the parents
  delay(30000);//Delay for playing Quiet music for 5 Mins
  MusicPlayer.pause(); //Pause the music to check whether the baby slept or not
  x=1;//Confirm that the program passes thourght this function
  y=0;//to avoid looping
  delay(5000);//Silent delay to check whether the baby still crying or not
}
///////////////////////////////////////////
void WakingMode()//Third Fn that the program passes by if the baby still crying
{
  digitalWrite(green,LOW);//Turn off the green light
  Twitter.sendMessage(account,Message2);// Sending a message on twitter for the parents
   MusicPlayer.next();//switch to WakingMode songs (Ex:Old MacDonald Had A Farm )
   MusicPlayer.play();//Playing songs for the baby
   digitalWrite(toy,HIGH);//turn on the Children toy
   delay(30000);//Delay for the songs
   MusicPlayer.previous();//Back to the previous Song(Quiet songs)
   MusicPlayer.stop();//stops the MusicPlayer
   digitalWrite(toy,LOW);//turn it off
   cry=0;//Reset the value to the intial value
   z=0;//Reset the value to the intial value
   y=1;//Reset the value to the intial value
   x=0;//Reset the value to the intial value
}
//////////////////////////////////////////
void SleepingMode2()//Second Fn that the program passes by if the baby still crying
{
  digitalWrite(green,LOW);//turn off the monitoring LED
  Twitter.sendMessage(account,Message4);//Sending a message on twitter for the parents
  MusicPlayer.play();//Continuing the quiet music for the baby
  delay(30000);//Delay for music
  MusicPlayer.pause();//Pause the music for checking
  z=1;////Confirm that the program passes thourght this function
  x=0//for preventing the program to run these function again
}
//////////////////////////////////////////\
void loop() 
{
  MonitoringMode();
  ////////////////////////////////////////////
  if(y==1)//If the baby is sleeping
  {
  digitalWrite(green,HIGH);//Turning on the Green LED(Checking LED)
  ////////////////////////////////////////////
  if(Crying())//If the baby is crying
  {
    digitalWrite(red,HIGH);//Turn on the Sound LED
    delay(100);
    digitalWrite(red,LOW);//Turn off the Sound LED
    cry++;//Increment the cry value  intial value =0,The program starts at cry =10
    delay(300);//Delay to cancel the noise
  }
  }
  ///////////////////////////////////////////
  if ((Crying())&&(z))//if baby is crying and the program passes through sleepingMode 2
   {
    WakingMode();//starts the WakingMode
    delay(5000);//Delay before looping 
   }
  //////////////////////////////////////////
  if((Crying())&&(x==1))//if baby is crying and the program passed through sleepingMode 1
   SleepingMode2();//Starts the SleepingMode2
  else if((!Crying())&&(x==1))//if the baby isn't crying and the program passed through sleepingMode 1
  {
   Twitter.sendMessage(account,Message3);// Send a message on twitter for the parents \
   cry=0;//Reset the value to the intial value
   z=0;//Reset the value to the intial value
   y=1;//Reset the value to the intial value
   x=0;//Reset the value to the intial value
  }
 ///////////////////////////////////////////
  if(cry==10)//If the cry=10 means the baby is crying 
  {
  digitalWrite(green,LOW);//Turn off the green LED
  SleepingMode();//starts the SleepingMode 1
  } 
}

Credits

Kirollos Magdi Sobhy

Kirollos Magdi Sobhy

1 project • 2 followers

Comments