Please try not to use adblocker for this small site. Thanks

Friday, 22 January 2016

How to make contactless doorbell with Arduino




Well in this post I want share with you how you can make a contactless doorbell. It is very simple, you just need few things.
  • One loud speaker
  • One Serial MP3 player for Arduino
  • One Ultrasonic Sensor
  • One Green LED
  • One 10k ohm resistor
  • One micro SD card (this is where your doorbell sound track will go make sure you name the sound track 001)
  • Few jumper wires
  • And a Arduino board
After connecting everything as shown in the diagram above upload the sketch below, and that's all.


#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

int led = 4;
int trigPin1 = 8;
int echoPin1 = 9;

void setup()
{
  pinMode(led, OUTPUT);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
      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
}

void loop() {
delay(500);
Serial.println("\n");
 int duration1, distance1;
  digitalWrite (trigPin1, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin1, LOW);
  duration1 = pulseIn (echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;

      Serial.print("1st Sensor: ");
      Serial.print(distance1);
      Serial.print("cm  ");

  if (distance1 < 30) {  // Change the number for long or short distances.
 digitalWrite(led, LOW);
 sendCommand(CMD_PLAY_W_VOL, 0X1E001);//Play the sound track
   delay(5000);
  } else {
    digitalWrite(led, HIGH);
  } 
}

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]) ;
  }
}


2 comments:

  1. Hey bro. I was wondering how I upload a sketch into an Arduino? I have never used them before, but need to use this idea to make something similar. Thanks!

    ReplyDelete
  2. You make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. ring doorbell pro review

    ReplyDelete