├── README.md ├── nodemcu-gps-firebase-mit ├── firebase_google_maps.aia ├── nodemcu-gps-firebase-mit.ino └── wiring-diagram.png ├── sim800l-dht11 ├── nodemcu-dht-sim800l-wiring.png └── sim800l-dht11.ino ├── sim800l-gps ├── nodemcu-sim800l-gps.ino └── wiring-diagram.png └── sim800l-rain-alarm ├── nodemcu-rain-sim800l-wiring.png └── sim800l-rain-alarm.ino /README.md: -------------------------------------------------------------------------------- 1 | # nodemcu-arduino-ide -------------------------------------------------------------------------------- /nodemcu-gps-firebase-mit/firebase_google_maps.aia: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmadlogs/nodemcu-arduino-ide/5ac9a4e3d20e9ba56b32f685b88d656220533c24/nodemcu-gps-firebase-mit/firebase_google_maps.aia -------------------------------------------------------------------------------- /nodemcu-gps-firebase-mit/nodemcu-gps-firebase-mit.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Note: The latest JSON library might not work with the code. 3 | So you may need to downgrade the library to version v5.13.5 4 | 5 | Created by TAUSEEF AHMED 6 | 7 | YouTube: https://www.youtube.com/channel/UCOXYfOHgu-C-UfGyDcu5sYw/ 8 | 9 | Github: https://github.com/ahmadlogs/ 10 | 11 | */ 12 | 13 | //----------------------------------------------------------------------------------- 14 | //FirebaseESP8266.h must be included before ESP8266WiFi.h 15 | #include //https://github.com/mobizt/Firebase-ESP8266 16 | #include 17 | #include 18 | #include //https://github.com/mikalhart/TinyGPSPlus 19 | 20 | //Install ArduinoJson Library 21 | //Note: The latest JSON library might not work with the code. 22 | //So you may need to downgrade the library to version v5.13.5 23 | //----------------------------------------------------------------------------------- 24 | 25 | //----------------------------------------------------------------------------------- 26 | #define FIREBASE_HOST "ENTER_FIREBASE_PROJECT_NAME.firebaseio.com" 27 | #define FIREBASE_AUTH "ENTER_FIREBASE_SECRET" 28 | #define WIFI_SSID "ENTER_WIFI_SSID" 29 | #define WIFI_PASSWORD "ENTER_WIFI_PASSWORD" 30 | //----------------------------------------------------------------------------------- 31 | 32 | 33 | //----------------------------------------------------------------------------------- 34 | //Define FirebaseESP8266 data object 35 | FirebaseData firebaseData; 36 | 37 | FirebaseJson json; 38 | //----------------------------------------------------------------------------------- 39 | 40 | //----------------------------------------------------------------------------------- 41 | //GPS Module RX pin to NodeMCU D1 42 | //GPS Module TX pin to NodeMCU D2 43 | const int RXPin = 4, TXPin = 5; 44 | SoftwareSerial neo6m(RXPin, TXPin); 45 | TinyGPSPlus gps; 46 | //----------------------------------------------------------------------------------- 47 | 48 | 49 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 50 | void setup() 51 | { 52 | 53 | Serial.begin(115200); 54 | 55 | neo6m.begin(9600); 56 | 57 | wifiConnect(); 58 | 59 | Serial.println("Connecting Firebase....."); 60 | Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); 61 | Firebase.reconnectWiFi(true); 62 | Serial.println("Firebase OK."); 63 | 64 | } 65 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 66 | 67 | 68 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 69 | void loop() { 70 | 71 | smartdelay_gps(1000); 72 | 73 | if(gps.location.isValid()) 74 | { 75 | float latitude = gps.location.lat(); 76 | float longitude = gps.location.lng(); 77 | 78 | //------------------------------------------------------------- 79 | //Send to Serial Monitor for Debugging 80 | //Serial.print("LAT: "); 81 | //Serial.println(latitude); // float to x decimal places 82 | //Serial.print("LONG: "); 83 | //Serial.println(longitude); 84 | //------------------------------------------------------------- 85 | 86 | //------------------------------------------------------------- 87 | if(Firebase.setFloat(firebaseData, "/GPS/f_latitude", latitude)) 88 | {print_ok();} 89 | else 90 | {print_fail();} 91 | //------------------------------------------------------------- 92 | if(Firebase.setFloat(firebaseData, "/GPS/f_longitude", longitude)) 93 | {print_ok();} 94 | else 95 | {print_fail();} 96 | //------------------------------------------------------------- 97 | } 98 | else 99 | { 100 | Serial.println("No valid GPS data found."); 101 | } 102 | 103 | delay(5000); 104 | } 105 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 106 | 107 | 108 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 109 | static void smartdelay_gps(unsigned long ms) 110 | { 111 | unsigned long start = millis(); 112 | do 113 | { 114 | while (neo6m.available()) 115 | gps.encode(neo6m.read()); 116 | } while (millis() - start < ms); 117 | } 118 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 119 | 120 | 121 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 122 | void wifiConnect() 123 | { 124 | WiFi.begin(WIFI_SSID, WIFI_PASSWORD); 125 | Serial.print("Connecting to Wi-Fi"); 126 | while (WiFi.status() != WL_CONNECTED) 127 | { 128 | Serial.print("."); 129 | delay(300); 130 | } 131 | Serial.println(); 132 | Serial.print("Connected with IP: "); 133 | Serial.println(WiFi.localIP()); 134 | Serial.println(); 135 | } 136 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 137 | 138 | 139 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 140 | void print_ok() 141 | { 142 | Serial.println("------------------------------------"); 143 | Serial.println("OK"); 144 | Serial.println("PATH: " + firebaseData.dataPath()); 145 | Serial.println("TYPE: " + firebaseData.dataType()); 146 | Serial.println("ETag: " + firebaseData.ETag()); 147 | Serial.println("------------------------------------"); 148 | Serial.println(); 149 | } 150 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 151 | 152 | 153 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 154 | void print_fail() 155 | { 156 | Serial.println("------------------------------------"); 157 | Serial.println("FAILED"); 158 | Serial.println("REASON: " + firebaseData.errorReason()); 159 | Serial.println("------------------------------------"); 160 | Serial.println(); 161 | } 162 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 163 | 164 | void firebaseReconnect() 165 | { 166 | Serial.println("Trying to reconnect"); 167 | Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH); 168 | } 169 | -------------------------------------------------------------------------------- /nodemcu-gps-firebase-mit/wiring-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmadlogs/nodemcu-arduino-ide/5ac9a4e3d20e9ba56b32f685b88d656220533c24/nodemcu-gps-firebase-mit/wiring-diagram.png -------------------------------------------------------------------------------- /sim800l-dht11/nodemcu-dht-sim800l-wiring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmadlogs/nodemcu-arduino-ide/5ac9a4e3d20e9ba56b32f685b88d656220533c24/sim800l-dht11/nodemcu-dht-sim800l-wiring.png -------------------------------------------------------------------------------- /sim800l-dht11/sim800l-dht11.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Created By: Tauseef Ahmad 3 | * YouTube Channel: https://www.youtube.com/channel/UCOXYfOHgu-C-UfGyDcu5sYw 4 | * 5 | * **************************************** 6 | * Download Resources 7 | * **************************************** 8 | * Install ESP8266 Board 9 | * http://arduino.esp8266.com/stable/package_esp8266com_index.json 10 | * 11 | * INSTALL: DHT SENSOR LIBRARY 12 | * https://github.com/adafruit/DHT-sensor-library 13 | */ 14 | 15 | #include 16 | #include 17 | 18 | //Enter Receiver's Phone Number with Country Code 19 | //Note: Not enter the gsm module phone number here 20 | //i.e +923001234567 21 | const String PHONE = "ENTER_YOUR_PERSONAL_PHONE_NUMBER"; 22 | 23 | //GSM Module RX pin to NodeMCU D6 24 | //GSM Module TX pin to NodeMCU D5 25 | #define rxPin D5 26 | #define txPin D6 27 | SoftwareSerial sim800(rxPin,txPin); 28 | 29 | String smsStatus,senderNumber,receivedDate,msg; 30 | 31 | 32 | #define DHT11_PIN D2 33 | #define DHTTYPE DHT11 34 | 35 | DHT dht(DHT11_PIN, DHTTYPE); 36 | 37 | void setup() { 38 | 39 | Serial.begin(115200); 40 | Serial.println("Arduino serial initialize"); 41 | 42 | sim800.begin(9600); 43 | Serial.println("SIM800L serial initialize"); 44 | 45 | dht.begin(); 46 | Serial.println("initialize DHT11"); 47 | 48 | sim800.println("AT+CMGF=1"); 49 | 50 | delay(2000); 51 | } 52 | 53 | void loop() 54 | { 55 | //Serial.println(get_temprature()); 56 | //-------------------------------------- 57 | while(sim800.available()){ 58 | parseData(sim800.readString()); 59 | } 60 | //-------------------------------------- 61 | while(Serial.available()) { 62 | sim800.println(Serial.readString()); 63 | } 64 | //-------------------------------------- 65 | } //main loop ends 66 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 67 | 68 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 69 | void parseData(String buff){ 70 | Serial.println(buff); 71 | 72 | unsigned int len, index; 73 | //-------------------------------------------------------------------- 74 | //Remove sent "AT Command" from the response string. 75 | index = buff.indexOf("\r"); 76 | buff.remove(0, index+2); 77 | buff.trim(); 78 | //-------------------------------------------------------------------- 79 | 80 | //-------------------------------------------------------------------- 81 | if(buff != "OK"){ 82 | index = buff.indexOf(":"); 83 | String cmd = buff.substring(0, index); 84 | cmd.trim(); 85 | 86 | buff.remove(0, index+2); 87 | 88 | //____________________________________________________________ 89 | if(cmd == "+CMTI"){ 90 | //get newly arrived memory location and store it in temp 91 | index = buff.indexOf(","); 92 | String temp = buff.substring(index+1, buff.length()); 93 | temp = "AT+CMGR=" + temp + "\r"; 94 | //get the message stored at memory location "temp" 95 | sim800.println(temp); 96 | } 97 | //____________________________________________________________ 98 | else if(cmd == "+CMGR"){ 99 | extractSms(buff); 100 | Serial.println(msg); 101 | Serial.println(senderNumber); 102 | 103 | if(senderNumber == PHONE && msg == "get temperature"){ 104 | Reply(get_temprature()); 105 | } 106 | } 107 | //____________________________________________________________ 108 | //-------------------------------------------------------------------- 109 | } 110 | else{ 111 | //The result of AT Command is "OK" 112 | } 113 | } 114 | 115 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 116 | 117 | 118 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 119 | String get_temprature() 120 | { 121 | //Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) 122 | float h = dht.readHumidity(); 123 | 124 | //Read temperature as Celsius (the default) 125 | float t = dht.readTemperature(); 126 | 127 | // Check if any reads failed and exit early (to try again). 128 | if (isnan(h) || isnan(t)) { 129 | Serial.println(F("Failed to read from DHT sensor!")); 130 | return ""; 131 | } 132 | 133 | //Compute heat index in Celsius (isFahreheit = false) 134 | float hic = dht.computeHeatIndex(t, h, false); 135 | 136 | //°C 137 | String humidity = "Humidity: " + String(h) + "%"; 138 | String temperature = "Temperature: " + String(t) + " Celsius"; 139 | String heat_index = "Heat index: " + String(hic) + " Celsius"; 140 | 141 | Serial.println(humidity); 142 | Serial.println(temperature); 143 | Serial.println(heat_index); 144 | Serial.println("------------------------------------------"); 145 | 146 | return humidity + "\n" + temperature + "\n" + heat_index; 147 | } 148 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 149 | 150 | 151 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 152 | void Reply(String text) 153 | { 154 | if(text == "") {return;} 155 | 156 | sim800.print("AT+CMGF=1\r"); 157 | delay(1000); 158 | sim800.print("AT+CMGS=\""+PHONE+"\"\r"); 159 | delay(1000); 160 | sim800.print(text); 161 | delay(100); 162 | sim800.write(0x1A); //ascii code for ctrl-26 //sim800.println((char)26); //ascii code for ctrl-26 163 | delay(1000); 164 | Serial.println("SMS Sent Successfully."); 165 | } 166 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 167 | 168 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 169 | void extractSms(String buff){ 170 | unsigned int index; 171 | 172 | index = buff.indexOf(","); 173 | smsStatus = buff.substring(1, index-1); 174 | buff.remove(0, index+2); 175 | 176 | senderNumber = buff.substring(0, 13); 177 | buff.remove(0,19); 178 | 179 | receivedDate = buff.substring(0, 20); 180 | buff.remove(0,buff.indexOf("\r")); 181 | buff.trim(); 182 | 183 | index =buff.indexOf("\n\r"); 184 | buff = buff.substring(0, index); 185 | buff.trim(); 186 | msg = buff; 187 | buff = ""; 188 | msg.toLowerCase(); 189 | } 190 | 191 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 192 | -------------------------------------------------------------------------------- /sim800l-gps/nodemcu-sim800l-gps.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Created By: Tauseef Ahmad 3 | * YouTube Channel: https://www.youtube.com/channel/UCOXYfOHgu-C-UfGyDcu5sYw 4 | * 5 | * **************************************** 6 | * Download Resources 7 | * **************************************** 8 | * Install ESP8266 Board 9 | * http://arduino.esp8266.com/stable/package_esp8266com_index.json 10 | */ 11 | 12 | #include 13 | #include //http://arduiniana.org/libraries/tinygpsplus 14 | 15 | //sender phone number with country code 16 | //Note: Not enter the SIM800L Phone Number here 17 | const String PHONE = "ENTER_YOUR_PERSONAL_PHONE_NUMBER"; 18 | 19 | //GSM Module RX pin to NodeMCU D6 20 | //GSM Module TX pin to NodeMCU D5 21 | #define rxGSM D5 22 | #define txGSM D6 23 | SoftwareSerial sim800(rxGSM,txGSM); 24 | 25 | //GPS Module RX pin to NodeMCU D3 26 | //GPS Module TX pin to NodeMCU D2 27 | #define rxGPS D2 28 | #define txGPS D3 29 | SoftwareSerial neogps(rxGPS,txGPS); 30 | TinyGPSPlus gps; 31 | 32 | String smsStatus,senderNumber,receivedDate,msg; 33 | 34 | void setup() { 35 | 36 | Serial.begin(115200); 37 | Serial.println("Arduino serial initialize"); 38 | 39 | sim800.begin(9600); 40 | Serial.println("SIM800L serial initialize"); 41 | 42 | neogps.begin(9600); 43 | Serial.println("NodeMCU serial initialize"); 44 | 45 | sim800.listen(); 46 | neogps.listen(); 47 | 48 | smsStatus = ""; 49 | senderNumber=""; 50 | receivedDate=""; 51 | msg=""; 52 | 53 | sim800.print("AT+CMGF=1\r"); //SMS text mode 54 | delay(1000); 55 | } 56 | 57 | void loop() { 58 | //sim800.listen(); 59 | //-------------------------------------- 60 | while(sim800.available()){ 61 | parseData(sim800.readString()); 62 | } 63 | //-------------------------------------- 64 | while(Serial.available()) { 65 | //String s = Serial.readString(); 66 | //Serial.println(s); 67 | sim800.println(Serial.readString()); 68 | } 69 | //-------------------------------------- 70 | } //main loop ends 71 | 72 | 73 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 74 | void parseData(String buff){ 75 | Serial.println(buff); 76 | 77 | unsigned int len, index; 78 | //----------------------------------------------------- 79 | //Remove sent "AT Command" from the response string. 80 | index = buff.indexOf("\r"); 81 | buff.remove(0, index+2); 82 | buff.trim(); 83 | //----------------------------------------------------- 84 | 85 | //----------------------------------------------------- 86 | if(buff != "OK"){ 87 | index = buff.indexOf(":"); 88 | String cmd = buff.substring(0, index); 89 | cmd.trim(); 90 | 91 | buff.remove(0, index+2); 92 | 93 | if(cmd == "+CMTI"){ 94 | //get newly arrived memory location and store it in temp 95 | index = buff.indexOf(","); 96 | String temp = buff.substring(index+1, buff.length()); 97 | temp = "AT+CMGR=" + temp + "\r"; 98 | //get the message stored at memory location "temp" 99 | sim800.println(temp); 100 | } 101 | else if(cmd == "+CMGR"){ 102 | extractSms(buff); 103 | 104 | if(senderNumber == PHONE){ 105 | if(msg == "get location"){ 106 | sendLocation(); 107 | } 108 | } 109 | else {Serial.println(String(senderNumber)+": Phone not registered");} 110 | } 111 | //----------------------------------------------------- 112 | } 113 | else{ 114 | //The result of AT Command is "OK" 115 | } 116 | } 117 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 118 | 119 | 120 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 121 | void extractSms(String buff){ 122 | unsigned int index; 123 | 124 | index = buff.indexOf(","); 125 | smsStatus = buff.substring(1, index-1); 126 | buff.remove(0, index+2); 127 | 128 | senderNumber = buff.substring(0, 13); 129 | buff.remove(0,19); 130 | 131 | receivedDate = buff.substring(0, 20); 132 | buff.remove(0,buff.indexOf("\r")); 133 | buff.trim(); 134 | 135 | index =buff.indexOf("\n\r"); 136 | buff = buff.substring(0, index); 137 | buff.trim(); 138 | msg = buff; 139 | buff = ""; 140 | msg.toLowerCase(); 141 | 142 | //Serial.println("----------------------------------"); 143 | //Serial.println(smsStatus); 144 | //Serial.println(senderNumber); 145 | //Serial.println(receivedDate); 146 | //Serial.println(msg); 147 | //Serial.println("----------------------------------"); 148 | } 149 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 150 | 151 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 152 | void sendLocation() 153 | { 154 | //----------------------------------------------------------------- 155 | // Can take up to 60 seconds 156 | boolean newData = false; 157 | 158 | for (unsigned long start = millis(); millis() - start < 2000;) 159 | { 160 | while (neogps.available()) 161 | { 162 | if (gps.encode(neogps.read())) 163 | {newData = true;} 164 | } 165 | } 166 | //----------------------------------------------------------------- 167 | 168 | //----------------------------------------------------------------- 169 | //If newData is true 170 | if(newData) 171 | { 172 | Serial.print("Latitude= "); 173 | Serial.print(gps.location.lat(), 6); 174 | Serial.print(" Longitude= "); 175 | Serial.println(gps.location.lng(), 6); 176 | newData = false; 177 | delay(300); 178 | ///* 179 | sim800.print("AT+CMGF=1\r"); 180 | delay(1000); 181 | sim800.print("AT+CMGS=\""+PHONE+"\"\r"); 182 | delay(1000); 183 | sim800.print("http://maps.google.com/maps?q=loc:"); 184 | sim800.print(gps.location.lat(), 6); 185 | sim800.print(","); 186 | sim800.print(gps.location.lng(), 6); 187 | delay(100); 188 | sim800.write(0x1A); //ascii code for ctrl-26 //sim800.println((char)26); //ascii code for ctrl-26 189 | delay(1000); 190 | Serial.println("GPS Location SMS Sent Successfully."); 191 | //*/ 192 | } 193 | else {Serial.println("Invalid GPS data");} 194 | //----------------------------------------------------------------- 195 | } 196 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 197 | -------------------------------------------------------------------------------- /sim800l-gps/wiring-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmadlogs/nodemcu-arduino-ide/5ac9a4e3d20e9ba56b32f685b88d656220533c24/sim800l-gps/wiring-diagram.png -------------------------------------------------------------------------------- /sim800l-rain-alarm/nodemcu-rain-sim800l-wiring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmadlogs/nodemcu-arduino-ide/5ac9a4e3d20e9ba56b32f685b88d656220533c24/sim800l-rain-alarm/nodemcu-rain-sim800l-wiring.png -------------------------------------------------------------------------------- /sim800l-rain-alarm/sim800l-rain-alarm.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Created By: Tauseef Ahmad 3 | * YouTube Channel: https://www.youtube.com/channel/UCOXYfOHgu-C-UfGyDcu5sYw 4 | * 5 | * **************************************** 6 | * Download Resources 7 | * **************************************** 8 | * Install ESP8266 Board 9 | * http://arduino.esp8266.com/stable/package_esp8266com_index.json 10 | * 11 | */ 12 | 13 | #include 14 | 15 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 16 | #define RAIN_SENSOR A0 17 | //---------------------------------------------------------------- 18 | //when rain is detected, then rain_value will increase 19 | int rain_value = 0; 20 | //---------------------------------------------------------------- 21 | //when rain value is equal or above 10 then sends rain alarm 22 | int rain_default=10; 23 | //---------------------------------------------------------------- 24 | //rain_flag = 0 means rain not detected 25 | //rain_flag = 1 means rain is detected 26 | boolean rain_flag = 0; 27 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 28 | 29 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 30 | //Alarm reciever's phone number with country code 31 | //NOTE: Must be your personal phone number here 32 | //this is not gsm module phone number 33 | 34 | const String PHONE = "ENTER_YOUR_PERSONAL_PHONE_NUMBER"; 35 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 36 | 37 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 38 | #define rxPin D5 39 | #define txPin D6 40 | SoftwareSerial sim800L(rxPin,txPin); 41 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 42 | 43 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 44 | //#define BUZZER_PIN 8 45 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 46 | 47 | //______________________________________________________________________________________ 48 | void setup() 49 | { 50 | //---------------------------------------------------------------- 51 | //Begin serial communication: Arduino IDE (Serial Monitor) 52 | Serial.begin(115200); 53 | //---------------------------------------------------------------- 54 | //Begin serial communication: SIM800L 55 | sim800L.begin(9600); 56 | //---------------------------------------------------------------- 57 | pinMode(RAIN_SENSOR,INPUT); 58 | //---------------------------------------------------------------- 59 | //pinMode(BUZZER_PIN, OUTPUT); 60 | //by default the BUZZER is OFF 61 | //digitalWrite(BUZZER_PIN,LOW); 62 | //---------------------------------------------------------------- 63 | Serial.println("Initializing..."); 64 | //Once the handshake test is successful, it will back to OK 65 | sim800L.println("AT"); 66 | delay(1000); 67 | sim800L.println("AT+CMGF=1"); 68 | delay(1000); 69 | //---------------------------------------------------------------- 70 | } 71 | //______________________________________________________________________________________ 72 | 73 | //______________________________________________________________________________________ 74 | void loop() 75 | { 76 | while(sim800L.available()){ 77 | Serial.println(sim800L.readString()); 78 | } 79 | 80 | rain_value = analogRead(RAIN_SENSOR); 81 | rain_value = map(rain_value,0,1023,225,0); 82 | 83 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 84 | //The rain is detected, trigger Alarm and send sms 85 | if(rain_value>=rain_default) { 86 | //digitalWrite(BUZZER_PIN,HIGH); 87 | //---------------------------------------------------------------- 88 | if(rain_flag == 0) { 89 | Serial.println("Rain is Detected."); 90 | rain_flag == 1; 91 | send_sms(); 92 | make_call(); 93 | } 94 | //---------------------------------------------------------------- 95 | } 96 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 97 | //No laser tripwire is detected, turn OFF Alarm 98 | else { 99 | //digitalWrite(BUZZER_PIN,LOW); 100 | if(rain_flag == 1) {Serial.println("Rain is Detected.");} 101 | rain_flag = 0; 102 | } 103 | //MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 104 | } 105 | //______________________________________________________________________________________ 106 | 107 | //______________________________________________________________________________________ 108 | void make_call() 109 | { 110 | Serial.println("calling...."); 111 | sim800L.println("ATD"+PHONE+";"); 112 | delay(20000); //20 sec delay 113 | sim800L.println("ATH"); 114 | delay(1000); //1 sec delay 115 | } 116 | //______________________________________________________________________________________ 117 | 118 | //______________________________________________________________________________________ 119 | void send_sms() 120 | { 121 | Serial.println("sending sms...."); 122 | delay(50); 123 | sim800L.print("AT+CMGF=1\r"); 124 | delay(1000); 125 | sim800L.print("AT+CMGS=\""+PHONE+"\"\r"); 126 | delay(1000); 127 | sim800L.print("This is a rain Alarm"); 128 | delay(100); 129 | sim800L.write(0x1A); //ascii code for ctrl-26 //Serial2.println((char)26); //ascii code for ctrl-26 130 | delay(5000); 131 | } 132 | //______________________________________________________________________________________ 133 | --------------------------------------------------------------------------------