Wednesday, 11 January 2017

Tilt switch arduino (with sound)

About a week ago a video gone viral in which two toddler were trapped (almost died) under a dresser  and mum said she was sleeping in another room and didn't hear the sound of falling dresser.

Well, there were so many people saying that the parents (specially the mum) of the toddlers are careless, and some said it's not possible to look after kids 24/7. OK it's true that it is hard to look after them 24/7 but at least the mum should have setup walkie talkies to the kids room, but it seems like she didn't wanted to get destructed by the sound.

So here is and idea which big companies can make the dressers smarter for careless people. I know they can make even smaller but this is just an idea and anyone can make it with arduino.

What you need?
1x Catalex mp3 player for arduino with a micro sd card.
1x  Any arduino board.
1x Tilt switch.
1x 10k ohm resistor.
Few jumper wires and the sketch below.

#include <SoftwareSerial.h>
#define ARDUINO_RX 5 //should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 6 //connect to RX of the module
SoftwareSerial mySerial(ARDUINO_RX, ARDUINO_TX);
static int8_t Send_buf[8] = {0} ;

#define CMD_SEL_DEV 0X09
#define DEV_TF 0X02
#define CMD_PLAY_W_VOL 0X22

const int buttonPin1 = 8;
int buttonState1 = 0;

void setup() {
      delay(500);//Wait chip initialization is complete
        sendCommand(CMD_SEL_DEV, DEV_TF);//select the TF card
      delay(200);//wait for 200ms

void loop() {
 buttonState1 = digitalRead(buttonPin1);

   if (buttonState1 == HIGH) {
sendCommand(CMD_PLAY_W_VOL, 0X0F01);//This is file you want to play.
      delay(1000);//waiting time for the file above.
  } else {
  sendCommand(CMD_PLAY_W_VOL, 0X16);

void sendCommand(int8_t command, int16_t dat)
  Send_buf[0] = 0x7e;
  Send_buf[1] = 0xff;
  Send_buf[2] = 0x06;
  Send_buf[3] = command;
  Send_buf[4] = 0x00;//0x00 = no feedback, 0x01 = feedback
  Send_buf[5] = (int8_t)(dat >> 8);//datah
  Send_buf[6] = (int8_t)(dat); //datal
  Send_buf[7] = 0xef; //ending byte
  for(uint8_t i=0; i<8; i++)//
    mySerial.write(Send_buf[i]) ;

Watch the video to see the sketch in action

If you need more help to play sound then you see my other post here where I've explained in detail.

No comments:

Post a Comment