May 1st, 2019 by cedcraftscodes
In this tutorial, we will learn how to connect Real-time clock, PIR Sensor and SIM800L module to send us a notification whenever motion is detected. This is a great way to monitor if unauthorize person/burglar enters your house.
Arduino
Sim800L GSM Module
DS1302 Real-time Clock Module 2
DS1302.zip (1102 downloads) Library
PIR Sensor
Jumper Wires
Breadboard
GSM Module
VCC | 5V |
GND | GND |
RX | Digital Pin 2 |
TX | Digital Pin 3 |
RTC Module
VCC | 5V |
GND | GND |
CLK | Digital Pin 4 |
DAT | Digital Pin 5 |
RST | Digital Pin 6 |
PIR Sensor
VCC | 5V |
GND | GND |
OUT | Digital Pin 13 |
Open up your Arduino IDE. Click on “Sketch -> Include Library -> Add .ZIP Library” and browse your downloaded DS1302.zip (1102 downloads) Library.
Upload the following source code to your Arduino.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #include <DS1302.h> #include <SoftwareSerial.h> SoftwareSerial mySerial(3, 2); DS1302 rtc(6, 5, 4); int sensor = 13; int val = 0; void setup() { // Set the clock to run-mode, and disable the write protection rtc.halt(false); rtc.writeProtect(false); Serial.begin(9600); // Sets the time of your RTC module // rtc.setDOW(WEDNESDAY); // rtc.setTime(16, 36, 0); //Set the time 4:30 PM; Military Time // rtc.setDate(01, 05, 2018); //dd, MM, yyyy format } void loop() { val = digitalRead(sensor); if (val == HIGH) { sendMotionDetectionMsg(); } delay(1000); } void sendMotionDetectionMsg() { String dowStr = rtc.getDOWStr(); String dateStr = rtc.getDateStr(); String timeStr = rtc.getTimeStr(); String message = String("Motion Detected: ") + dowStr + String(" ") + dateStr + String(" ") + timeStr; Serial.println(message); sendSms(message, "+YYXXXXXXXXXX"); } void sendSms(String message, String number) { mySerial.begin(9600); delay(1000); mySerial.println("AT"); delay(500); mySerial.println("AT+CMGF=1"); delay(500); mySerial.println("AT+CMGS=\""+ number +"\"\r"); delay(500); mySerial.print(message); delay(500); mySerial.write(26); } |
Change the YY to your country code proceeding with your number. (e.g 914564321) where 91 is country code for India, followed by 10 Digit code.
If you have not set the time in your RTC module, you can uncomment and change the values. Follow the form
1 2 3 4 | // Sets the time of your RTC module // rtc.setDOW(WEDNESDAY); // rtc.setTime(16, 36, 0); //Set the time 4:30 PM; Military Time // rtc.setDate(01, 05, 2018); //dd, MM, yyyy format |
If you like this tutorial, please share by clicking the social media icons below 🙂
If you have inquiries, feel free to comment down below.
Melvin
March 7, 2020 at 11:20 pmBetter still what do I have to change (in the codes) if I’m to use DS3231 RTC
John
September 22, 2020 at 2:39 pmDo you find a result for DS3231 RTC?
Thanks