Today we’re going to learn how to make DTMF Based Home Automation Using Arduino this is very intresting project As we know, the demand for home Automantion devices has increased over the past few years. There are so many products in our market.
DTMF Home Automation (Dual-tone multi-frequency signaling) you can Control your home electronics appliances like bulb and water pump or any electronics devices from anywhere. if you forgot to turn off the Bulb or other electronics appliances while going out, this DTMF Home Automation helps you to turn off the appliance with your phone call.
Required Material
- GSM Module 800l
- Arduino UNO
- Switch Button
- Relay
- Wires
- Bulb
- Holder
DTMF Based Home Automation Using Arduino Schematic Diagram
The Schematic diagram is very straightforward. You have to connect the SIM800L GSM module and Relay pins with Arduino pins as per the schematic diagram. The schematic diagram is shown below.
Programming
First, download the code attached below. Then download the following libraries and install them.
After installation, all the libraries, set the correct board and COM port, then upload the below code.
Source Code
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
#include <SoftwareSerial.h> #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 = ""; } |
Final Testing
Now you will be able to Control Electronics appliance.