Wednesday, 18 November 2015

Arduino doorbell with custom tunes and buttons


You might think what's so special about this doorbell.
Well, it might be not that special but think of it this way, you have three doorbell buttons and different tunes for each button. One is for your friends and family, one is for postman and one is for normal people.
Every time when postman comes he pushes the dedicated button, you will know that that's a postman, because of the different sound it (arduino doorbell) will make. So for example, you got something coming by post, you will be happy and rush to the door to open it.
Ad

You might aswel think what if post man hits the other button?
Com on, most of the time people don't play around like that, specially adults. So that means you will get the right kind of doorbell sounds most of the time.

Forget the doorbell for a moment, you can even use this sketch as a door or window alert. Something like if someone opens a door or window then it will notify you which door is open or which window is open. So this sketch could be helpful in many ways.

What do you need to make it work?
* 1× Arduino board.
* 1× Catalex Serial mp3 player with micro sd card.
* 3× Push button switches.
* 3× 10k ohm resistors.
* Some jumper wires.
* And finally the sketch, which you can find right below.
Note:
Remember you need to have three soundtracks in your sd card and rename it by 001, 002 and 003.

The sketch
#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;

const int buttonPin2 = 9;     // the number of the pushbutton pin
int buttonState2 = 0;         // variable for reading the pushbutton status

const int buttonPin3 = 10;
int buttonState3 = 0;

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

     pinMode(buttonPin1, INPUT);
     pinMode(buttonPin2, INPUT);
     pinMode(buttonPin3, INPUT);
}

void loop() {
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3); 

  if (buttonState1 == HIGH) {
sendCommand(CMD_PLAY_W_VOL, 0X1E01);//This doorbell is for friends and family.
  }
 
else if (buttonState2 == HIGH) {
sendCommand(CMD_PLAY_W_VOL, 0X1E02);//This doorbell is for post men.
  }

else if (buttonState3 == HIGH) {
sendCommand(CMD_PLAY_W_VOL, 0X1E03);//This doorbell for is normal people.
  } 
}

void sendCommand(int8_t command, int16_t dat)
{
  delay(20);
  Send_buf[0] = 0x7e; //starting byte
  Send_buf[1] = 0xff; //version
  Send_buf[2] = 0x06; //the number of bytes of the command without starting byte and ending byte
  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]) ;
  }
}

That's all for this post, hopefully it helps you. :)

Ad



7 comments:

  1. I dont think this circuit works? When you hit the buttons it will short out the power to GND. Can you confirm the buttons are correct.

    ReplyDelete
    Replies
    1. Thanks for your comment. I've used the buttons switches as I saw on https://www.arduino.cc/en/Tutorial/Button and when I made the circuit it worked fine. Just try with one switch first then add more, I hope that will work for you.

      Delete
  2. Hi ,

    This project is exactly what I am looking to do with my Arduino .I have downloaded this code and wired the UNO as you have shown but unfortunately this code does nor work for me . If I disable your 2nd and 3rd buttons I can get the first audio track to play but I have to hold the button down . I know this is an old post but I was hoping you might be able to check your code with your project again , maybe something was left out of your posted code ? Thanks for your help and great posts .

    T

    ReplyDelete
    Replies
    1. I'm really sorry my friend. I'm already disappointed with everything (because I've tried very hard to something but I've failed on every corner of my life and became unwanted.) I could have helped you if I was feeling better but unfortunately I'm not. All I can help you in this is that try to remove all the commands except one. Once you find one is working fine then ad another command and then another. I hope that helps you. once upon a time I used to love this kind of stuffs but everything faded now. I'm really sorry about that. :(

      Delete
    2. Sorry to hear about your situation , I hope things improve for you quickly . Thank you for the quick reply and the projects you have already shared .

      All the best ,
      Tom

      Delete
    3. Thanks a lot for your kind words.

      Delete