Home
About Us
Achievement
Home
Raspberry-Pi Projects
_Raspberry Pi 4 Complete Guide
Arduino Project
_All Projects
Esp8266 Project
_All Projects
Esp32 Project
_Automation-with-feedback
GSM Based Home Automation
Just Do Electronics
January 01, 2022
Circuit Diagram :-
Code :-
//Prateek //wwww.prateeks.in //https://www.youtube.com/c/JustDoElectronics/videos #include
#include "Adafruit_FONA.h" #define FONA_RX 2 #define FONA_TX 3 #define FONA_RST 4 const String PHONE = "+91xxxxxxxxxx"; //sender phone number here with country code String smsStatus, senderNumber, receivedDate, msg, buff; boolean isReply = false; String dtmf_cmd; boolean is_call = false; #define FONA_RI_INTERRUPT 0 SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); Adafruit_FONA fona = Adafruit_FONA(FONA_RST); #define button1_pin 4 #define button2_pin 5 #define button3_pin 6 #define button4_pin 7 #define relay1_pin 8 #define relay2_pin 9 #define relay3_pin 10 #define relay4_pin 11 boolean relay1_state = 1; boolean relay2_state = 1; boolean relay3_state = 1; boolean relay4_state = 1; void setup() { pinMode(button1_pin, INPUT); pinMode(button2_pin, INPUT); pinMode(button3_pin, INPUT); pinMode(button4_pin, INPUT); pinMode(relay1_pin, OUTPUT); pinMode(relay2_pin, OUTPUT); pinMode(relay3_pin, OUTPUT); pinMode(relay4_pin, OUTPUT); digitalWrite(relay1_pin, relay1_state); digitalWrite(relay2_pin, relay2_state); digitalWrite(relay3_pin, relay3_state); digitalWrite(relay4_pin, relay4_state); Serial.begin(115200); fonaSS.begin(9600); if (! fona.begin(fonaSS)) { Serial.println(F("Couldn't find FONA")); while (1); } Serial.println(F("FONA is OK")); fona.println("AT"); delay(500); fona.print ("AT+CSMP=17,167,0,0\r"); fona.println("AT+DDET=1"); delay(500); smsStatus = ""; senderNumber = ""; receivedDate = ""; msg = ""; } void loop() { while (fona.available()) { buff = fona.readString(); handle_sim800_response(); } while (Serial.available()) { fona.println(Serial.readString()); } // listen_iir(); listen_push_buttons(); } void handle_sim800_response() { Serial.println(buff); if (is_call == true) { if (int index = buff.indexOf("+DTMF:") > -1 ) { index = buff.indexOf(":"); dtmf_cmd = buff.substring(index + 1, buff.length()); dtmf_cmd.trim(); Serial.println("dtmf_cmd: " + dtmf_cmd); if (dtmf_cmd == "1") control_relay(1); else if (dtmf_cmd == "2") control_relay(2); else if (dtmf_cmd == "3") control_relay(3); else if (dtmf_cmd == "4") control_relay(4); } if (buff.indexOf("NO CARRIER") > -1) { fona.println("ATH"); is_call = false; } } else if (buff.indexOf("RING") > -1) { delay(2000); fona.println("ATA"); is_call = true; } else if (buff.indexOf("+CMTI") > -1) { unsigned int index = buff.indexOf(","); String temp = buff.substring(index + 1, buff.length()); temp = "AT+CMGR=" + temp + "\r"; fona.println(temp); } else if (buff.indexOf("+CMGR") > -1) { extractSms(); if (msg == "1") control_relay(1); else if (msg == "2") control_relay(2); else if (msg == "3") control_relay(3); else if (msg == "4") control_relay(4); else if (msg.indexOf(".status") > -1) send_relay_status(msg.substring(0, 1)); else if (msg.indexOf("del all") > -1) delete_all_sms(); } } void extractSms() { unsigned int len, index; index = buff.indexOf("\r"); buff.remove(0, index + 2); buff.trim(); index = buff.indexOf(":"); buff.substring(0, index); buff.remove(0, index + 2); index = buff.indexOf(","); smsStatus = buff.substring(1, index - 1); buff.remove(0, index + 2); senderNumber = buff.substring(0, 13); buff.remove(0, 19); receivedDate = buff.substring(0, 20); buff.remove(0, buff.indexOf("\r")); buff.trim(); index = buff.indexOf("\n\r"); buff = buff.substring(0, index); buff.trim(); msg = buff; buff = ""; msg.toLowerCase(); } void listen_push_buttons() { if (digitalRead(button1_pin) == LOW) { delay(200); control_relay(1); } else if (digitalRead(button2_pin) == LOW) { delay(200); control_relay(2); } else if (digitalRead(button3_pin) == LOW) { delay(200); control_relay(3); } else if (digitalRead(button4_pin) == LOW) { delay(200); control_relay(4); } } void control_relay(int relay) { if (relay == 1) { relay1_state = !relay1_state; digitalWrite(relay1_pin, relay1_state); Serial.print("RelayState = "); Serial.println(relay1_state); delay(50); } else if (relay == 2) { relay2_state = !relay2_state; digitalWrite(relay2_pin, relay2_state); delay(50); } else if (relay == 3) { relay3_state = !relay3_state; digitalWrite(relay3_pin, relay3_state); delay(50); } else if (relay == 4) { relay4_state = !relay4_state; digitalWrite(relay4_pin, relay4_state); delay(50); } } void send_relay_status(String relay) { Serial.println("Relay Number: " + relay); //(relay1_state):"ON"?"OFF" String sms_text = ""; if (relay == "1") { sms_text = (relay1_state) ? "OFF" : "ON"; sms_text = "Relay 1 is " + sms_text; } else if (relay == "2") { sms_text = (relay2_state) ? "OFF" : "ON"; sms_text = "Relay 2 is " + sms_text; } else if (relay == "3") { sms_text = (relay3_state) ? "OFF" : "ON"; sms_text = "Relay 3 is " + sms_text; } else if (relay == "4") { sms_text = (relay4_state) ? "OFF" : "ON"; sms_text = "Relay 4 is " + sms_text; } Reply(sms_text); } void delete_all_sms() { fona.println("AT+CMGD=1,4"); delay(5000); while (fona.available()) { String response = fona.readString(); if (response.indexOf("OK") > -1 ) { Reply("All sms are deleted"); } else { Reply(response); } } } void Reply(String text) { Serial.println(text); fona.print("AT+CMGF=1\r"); delay(1000); fona.print ("AT+CSMP=17,167,0,0\r"); fona.print("AT+CMGS=\"" + PHONE + "\"\r"); delay(1000); fona.print(text); delay(100); fona.write(0x1A); //sim800.println((char)26); delay(1000); Serial.println("SMS Sent Successfully."); msg = ""; }
Video :-
1 Comments
Anonymous
11 April 2023 at 23:53
The project is not working also call is not recieved by gsm module
Reply
Delete
Replies
Reply
Add comment
Load more...
Newer
Older
ESP32 Interfacing With LDR Sensor
How To Make RFID & Keypad Based Door Lock
IoT Based Fingerprint Biometric Attendance System Using NodeMCU (Esp8266)
Esp32 Cam Based Face Unlock
NRF Based Servo Motor Control
Ultrasonic Sensor as a Counter with Arduino
ESP32 Led Blink With Push Button
How to Make a Conveyor Belt System | Counter Machine
IoT Based Patient Health Monitoring System Using Blynk App
Arduino ebook
YouTube
Like on Facebook
Follow on Twitter
Follow on Google+
Follow on Instagram
Subscribe on Youtube
Hi WelCome To My Website If you have a creative mind and want to learn Electronics even without studying it then FRIENDS this Website And Youtube Channel is for you, I am crazy creators who love making Electronics things. I have a bunch of more than 130 Tutorial Videos on My YouTube Channel and I upload a new Tutorial every Sunday.
Tags
Arduino Project
Esp32 Project
Esp8266 Project
1 Comments
The project is not working also call is not recieved by gsm module
ReplyDelete