- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
As those who read my previous article about M590 GSM/GPRS module know, it's not very reliable for GPRS operation. Recognizing this downside of M590s, I still wanted to use them (heaps of
UPDATE 25 Apr. 2018:
Essential documents for M590
Neoway M590E GPRS Module Hardware User Guide v 1.0
Neoway M590 Hardware Design Manual Version 1.1
Neoway M590 AT command sets v. 3.0
This blog post is a part of series about really cheap GSM/GPRS module Neoway M590:
- Neoway M590 GPRS Tutorial: sending and receiving files from/to SD card
- SMS GPS-tracker with Neoway M590 and ublox NEO-6 part 1. Gathering parts and testing
- SMS GPS-tracker with Neoway M590 and ublox NEO-6 part 2. Assembling the device
Heating part:
Beside that I only had to source a 1 m. piece of round ventilation duct and a fan. The heater has to be positioned roughly at the center of duct. I also sawed out rectangular pieces from the duct so that the plastic fan wouldn't melt, to further protect it from overheating I installed an NC thermal switch that opens when the temperature is around 90°C.
You should be able to easily replicate my setup just by looking at the pictures below:
- You can use anything that won't melt for suspension - steel or copper wire is what you'll probably find lying around in no time.
- Hanging the heater was the dumbest thing done in this project. When you heat air it goes UP whereas the cold air stays down below. The fastest and the most efficient way to heat air is to install this on the floor.
Electronics part:
I also went full ghetto with the enclosure, which is a plastic box from some power tool painted black. It gives off the air of something quickly put together from scraps and that's what I like about it - I'm all about improvisation :-)
Schematics:
- Arduino UNO (can be a nameless clone, make sure to donate to Arduino foundation if you buy one)
- Neoway M590 kit (or assembled module)
- Two 12V relay modules
- Two copper bus bars
- Contactor with AC coil. You can buy one from China, if you dare😈
- 3-position switch (ON-OFF-ON). Something rugged like this or this
- 12V PSU and 5V PSU. You can get them separate: 12V 1A or greater curent rating and 5V 2A or greater current rating, or try to find something combined
Ready to be connected! |
|
|
---|---|
|
Arduino sketch:
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 | #define DEBUG #include <SoftwareSerial.h> #include <Bounce2.h> // Mode of operation #define AUTO 0 #define ON 1 #define OFF 2 /* Timeout in hours. If the heater is switched on in AUTO mode and ON mode is not switched on after this amount of time, heater turns off. */ const int heaterTimeoutHrs = 3; // hours /* Fan will continue to blow after the heater is switched off for this amount of seconds to cool down the system */ const int fanTimeoutSecs = 120 ; // seconds // Pin definitions #define SRX 2 #define STX 3 #define FAN 4 #define HEATER 5 #define AUTO_SW 6 #define ON_SW 7 SoftwareSerial m590Serial(SRX, STX); Bounce debouncerAuto = Bounce(); Bounce debouncerOn = Bounce(); int ch = 0 ; String val = "" ; String phoneNumber = "" ; const char * phoneNumbers[] = { "71234567890" , "70987654321" }; int numberPoolSize = sizeof(phoneNumbers) / sizeof(phoneNumbers[ 0 ]); unsigned long timestamp; unsigned long heaterTimeout = (unsigned long )heaterTimeoutHrs * 60 * 60 * 1000 ; unsigned long fanTimeout = (unsigned long )fanTimeoutSecs * 1000 ; bool heaterOn; bool fanOn; uint8_t mode; bool modeAuto, modeOn; void setup() { pinMode(HEATER, OUTPUT); pinMode(FAN, OUTPUT); pinMode(AUTO_SW, INPUT_PULLUP); pinMode(ON_SW, INPUT_PULLUP); digitalWrite(HEATER, 0 ); digitalWrite(FAN, 0 ); heaterOn = false ; fanOn = false ; debouncerAuto.attach(AUTO_SW); debouncerAuto.interval( 5 ); debouncerOn.attach(ON_SW); debouncerOn.interval( 5 ); InitModem(); #ifdef DEBUG Serial.print( "Heater timeout in millis:" ); Serial.print(heaterTimeout); Serial.println( "." ); Serial.print( "Fan timeout in millis:" ); Serial.print(fanTimeout); Serial.println( "." ); #endif } void loop() { debouncerAuto.update(); debouncerOn.update(); modeAuto = !debouncerAuto.read(); modeOn = !debouncerOn.read(); if ((modeAuto) && (mode != AUTO)) { mode = AUTO; #ifdef DEBUG Serial.println( "Switching to AUTO." ); #endif } if ((modeOn) && (mode != ON)) { mode = ON; #ifdef DEBUG Serial.println( "Switching to ON." ); #endif } if ((!(modeAuto || modeOn)) && ( mode != OFF)) { mode = OFF; #ifdef DEBUG Serial.println( "Switching to OFF." ); #endif } switch (mode) { case AUTO: if (m590Serial.available()) { while (m590Serial.available()) { ch = m590Serial.read(); val += char (ch); delay( 20 ); } if (val.indexOf( "+PBREADY" ) > - 1 ) InitModem(); if (val.indexOf( "RING" ) > - 1 ) { if (CheckPhone()) { m590Serial.println( "ATH0" ); #ifdef DEBUG Serial.println( "--- MASTER CALL DETECTED ---" ); #endif MasterCall(); } else { #ifdef DEBUG Serial.println( "--- UNKNOWN CALL DETECTED ---" ); #endif m590Serial.println( "ATH0" ); } } else if (val.indexOf( "+CMT" ) > - 1 ) { if (CheckPhone() == 1 ) { #ifdef DEBUG Serial.println( "--- MASTER SMS DETECTED ---" ); #endif MasterSms(); } } // else // Serial.println(val); val = "" ; } if (Serial.available()) { while (Serial.available()) { ch = Serial.read(); val += char (ch); delay( 20 ); } ConsolePrint(); val = "" ; } if ((heaterOn) && (millis() - timestamp > heaterTimeout)) { digitalWrite(HEATER, 0 ); heaterOn = false ; timestamp = millis(); #ifdef DEBUG Serial.print( "Heater switched off due to timeout (" ); Serial.print(heaterTimeoutHrs); Serial.println( " hrs.)" ); #endif } if ((fanOn) && !(heaterOn)) { if (millis() - timestamp > fanTimeout) { digitalWrite(FAN, 0 ); fanOn = false ; #ifdef DEBUG Serial.print( "Fan switched off in AUTO mode due to timeout (" ); Serial.print(fanTimeoutSecs); Serial.println( " s.)" ); #endif } } break ; // AUTO MODE case ON: if (!heaterOn) { digitalWrite(HEATER, 1 ); digitalWrite(FAN, 1 ); heaterOn = true ; fanOn = true ; } break ; // ON MODE case OFF: if (heaterOn) { digitalWrite(HEATER, 0 ); timestamp = millis(); heaterOn = false ; } if (fanOn) { if (millis() - timestamp > fanTimeout) { digitalWrite(FAN, 0 ); fanOn = false ; #ifdef DEBUG Serial.print( "Fan switched off due to timeout (" ); Serial.print(fanTimeoutSecs); Serial.println( " s.)" ); #endif } } break ; // OFF MODE } } void InitModem() { delay( 2000 ); m590Serial.begin( 9600 ); m590Serial.println( "AT+CLIP=1" ); delay( 100 ); m590Serial.println( "AT+CMGF=1" ); delay( 100 ); m590Serial.println( "AT+CSCS=\"GSM\"" ); delay( 100 ); m590Serial.println( "AT+CNMI=2,2" ); delay( 100 ); #ifdef DEBUG Serial.begin( 9600 ); Serial.println( "M590 Modem initialized!" ); #endif } bool CheckPhone() { for ( int i = 0 ; i < numberPoolSize; i++) { if (val.indexOf(phoneNumbers[i]) > - 1 ) { phoneNumber = phoneNumbers[i]; #ifdef DEBUG Serial.println( "Phone number: +" + phoneNumber); #endif return true ; } } return false ; } void MasterCall() { } void MasterSms() { if ((val.indexOf( "on" ) > - 1 ) or (val.indexOf( "ON" ) > - 1 ) or (val.indexOf( "On" ) > - 1 ) or (val.indexOf( "oN" ) > - 1 )) { digitalWrite(HEATER, 1 ); digitalWrite(FAN, 1 ); heaterOn = true ; fanOn = true ; timestamp = millis(); #ifdef DEBUG Serial.println( "Heater switched on in AUTO mode (SMS from " + phoneNumber + ")." ); #endif } if ((val.indexOf( "Off" ) > - 1 ) or (val.indexOf( "off" ) > - 1 ) or (val.indexOf( "oFF" ) > - 1 ) or (val.indexOf( "OFF" ) > - 1 )) { digitalWrite(HEATER, 0 ); heaterOn = false ; #ifdef DEBUG Serial.println( "Heater switched off in AUTO mode (SMS from " + phoneNumber + ")." ); #endif } } void ConsolePrint() { MasterSms(); if ((val.indexOf( "clear" ) > - 1 ) or (val.indexOf( "Clear" ) > - 1 ) or (val.indexOf( "CLEAR" ) > - 1 )) { #ifdef DEBUG Serial.println( "Clear: All messages removed" ); #endif m590Serial.println( "AT+CMGD=0,4" ); } } |
I'm using an official Arduino Bounce library for debouncing (I'm that lazy). The heater has 3 modes: ON, OFF and AUTO, which are switched by the switch on the main panel. When switched off, the controller turns off the heater but lets fan blow off the heat for a preset time (120 seconds in my case). In AUTO mode you can send SMS to switch the heating on or off, but there's a timeout of 3 hrs. for safety reasons. So, if I were to switch on the heater and forget about it completely it would not waste tons of energy waiting for me to come to the garage.
Seeing how impressed my friends were when they saw this thing controlled by an SMS I immediately felt it was worth making. And with cold season coming it's going to become my greatest asset.
|
|
---|---|
UPDATE:
After a month of use I decided this heater needs to be turned on and off on a schedule, so I added an RTC module (based upon DS1302 chip). Nothing much to add to the schematics - just hook up 5V from Arduino to RTC and connect 3 data lines to pins 7-9.This is the library I used to interface the chip. Not sure if it's unreliable library or something I messed up while connecting the module, but most of the time rtc.time() function spews out some date in year 2011, so I had to poll it to get the right date.
See updated code below:
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 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | #define DEBUG #include <SoftwareSerial.h> #include <Bounce2.h> #include <stdio.h> #include <DS1302.h> // Mode of operation #define AUTO 0 #define ON 1 #define OFF 2 /* Fan will continue to blow after the heater is switched off for this amount of seconds to cool down the system */ const int fanTimeoutSecs = 120 ; // seconds // Pin definitions #define SRX 2 #define STX 3 #define FAN 4 #define HEATER 5 #define AUTO_SW 6 #define ON_SW 7 //DS1302 RTC pins const int RST = 8 ; // Chip Enable const int DAT = 9 ; // Input/Output const int CLK = 10 ; // Serial Clock SoftwareSerial m590Serial(SRX, STX); Bounce debouncerAuto = Bounce(); Bounce debouncerOn = Bounce(); DS1302 rtc(RST, DAT, CLK); int ch = 0 ; String val = "" ; String phoneNumber = "" ; const char * phoneNumbers[] = { "79518821388" , "79297770895" }; int numberPoolSize = sizeof(phoneNumbers) / sizeof(phoneNumbers[ 0 ]); unsigned long timestamp; unsigned long fanTimeout = (unsigned long )fanTimeoutSecs * 1000 ; bool heaterOn; bool fanOn; uint8_t mode; bool modeAuto, modeOn; String dayAsString( const Time::Day day) { switch (day) { case Time::kSunday: return "Sunday" ; case Time::kMonday: return "Monday" ; case Time::kTuesday: return "Tuesday" ; case Time::kWednesday: return "Wednesday" ; case Time::kThursday: return "Thursday" ; case Time::kFriday: return "Friday" ; case Time::kSaturday: return "Saturday" ; } return "(unknown day)" ; } void printTime() { // Get the current time and date from the chip. Time t = rtc.time(); do { t = rtc.time(); } while (t.yr < 2016 ); // Name the day of the week. const String day = dayAsString(t.day); // Format the time and date and insert into the temporary buffer. char buf[ 50 ]; snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d" , day.c_str(), t.yr, t.mon, t.date, t.hr, t.min, t.sec); // Print the formatted string to serial so we can see the time. Serial.println(buf); } void setup() { pinMode(HEATER, OUTPUT); pinMode(FAN, OUTPUT); pinMode(AUTO_SW, INPUT_PULLUP); pinMode(ON_SW, INPUT_PULLUP); digitalWrite(HEATER, 0 ); digitalWrite(FAN, 0 ); heaterOn = false ; fanOn = false ; debouncerAuto.attach(AUTO_SW); debouncerAuto.interval( 5 ); debouncerOn.attach(ON_SW); debouncerOn.interval( 5 ); InitModem(); rtc.writeProtect( false ); rtc.halt( false ); #ifdef DEBUG Serial.print( "Fan timeout in millis:" ); Serial.print(fanTimeout); Serial.println( "." ); #endif } void loop() { // Mode switching debouncerAuto.update(); debouncerOn.update(); modeAuto = !debouncerAuto.read(); modeOn = !debouncerOn.read(); if ((modeAuto) && (mode != AUTO)) { mode = AUTO; #ifdef DEBUG Serial.println( "Switching to AUTO." ); #endif } if ((modeOn) && (mode != ON)) { mode = ON; #ifdef DEBUG Serial.println( "Switching to ON." ); #endif } if ((!(modeAuto || modeOn)) && ( mode != OFF)) { mode = OFF; #ifdef DEBUG Serial.println( "Switching to OFF." ); #endif } // End of mode switching switch (mode) { case AUTO: // Serial handling if (m590Serial.available()) { while (m590Serial.available()) { ch = m590Serial.read(); val += char (ch); delay( 20 ); } if (val.indexOf( "+PBREADY" ) > - 1 ) InitModem(); if (val.indexOf( "RING" ) > - 1 ) { if (CheckPhone()) { m590Serial.println( "ATH0" ); #ifdef DEBUG Serial.println( "--- MASTER CALL DETECTED ---" ); #endif MasterCall(); } else { #ifdef DEBUG Serial.println( "--- UNKNOWN CALL DETECTED ---" ); #endif m590Serial.println( "ATH0" ); } } else if (val.indexOf( "+CMT" ) > - 1 ) { if (CheckPhone()) { #ifdef DEBUG Serial.println( "--- MASTER SMS DETECTED ---" ); #endif MasterSms(); } } val = "" ; } if (Serial.available()) { while (Serial.available()) { ch = Serial.read(); val += char (ch); delay( 20 ); } ConsolePrint(); val = "" ; } // End of serial handling // Scheduled heating { Time currentTime = rtc.time(); while (currentTime.yr < 2016 ) { currentTime = rtc.time(); } uint8_t cold; switch (currentTime.mon) { case 1 : cold = 3 ; break ; case 2 : cold = 3 ; break ; case 3 : cold = 2 ; break ; case 4 : cold = 1 ; break ; case 5 : cold = 1 ; break ; case 6 : cold = 0 ; break ; case 7 : cold = 0 ; break ; case 8 : cold = 0 ; break ; case 9 : cold = 1 ; break ; case 10 : cold = 2 ; break ; case 11 : cold = 3 ; break ; case 12 : cold = 3 ; break ; } if (cold > 0 ) { if ((!heaterOn) && (currentTime.hr == ( 20 - cold)) && (currentTime.min == 0 )) { digitalWrite(HEATER, 1 ); digitalWrite(FAN, 1 ); heaterOn = true ; fanOn = true ; } if ((heaterOn) && (currentTime.hr == ( 7 + cold)) && (currentTime.min == 0 )) { digitalWrite(HEATER, 0 ); heaterOn = false ; } } } // End of scheduled heating if ((fanOn) && !(heaterOn)) { if (millis() - timestamp > fanTimeout) { digitalWrite(FAN, 0 ); fanOn = false ; #ifdef DEBUG Serial.print( "Fan switched off in AUTO mode due to timeout (" ); Serial.print(fanTimeoutSecs); Serial.println( " s.)" ); #endif } } break ; // AUTO MODE case ON: if (!heaterOn) { digitalWrite(HEATER, 1 ); digitalWrite(FAN, 1 ); heaterOn = true ; fanOn = true ; } break ; // ON MODE case OFF: if (heaterOn) { digitalWrite(HEATER, 0 ); heaterOn = false ; timestamp = millis(); } if (fanOn) { if (millis() - timestamp > fanTimeout) { digitalWrite(FAN, 0 ); fanOn = false ; #ifdef DEBUG Serial.print( "Fan switched off in OFF mode due to timeout (" ); Serial.print(fanTimeoutSecs); Serial.println( " s.)" ); #endif } } break ; // OFF MODE } } void InitModem() { delay( 2000 ); m590Serial.begin( 9600 ); m590Serial.println( "AT+CLIP=1" ); delay( 100 ); m590Serial.println( "AT+CMGF=1" ); delay( 100 ); m590Serial.println( "AT+CSCS=\"GSM\"" ); delay( 100 ); m590Serial.println( "AT+CNMI=2,2" ); delay( 100 ); Serial.begin( 9600 ); #ifdef DEBUG Serial.println( "M590 Modem initialized!" ); #endif } bool CheckPhone() { for ( int i = 0 ; i < numberPoolSize; i++) { if (val.indexOf(phoneNumbers[i]) > - 1 ) { phoneNumber = phoneNumbers[i]; #ifdef DEBUG Serial.println( "Phone number: +" + phoneNumber); #endif return true ; } } return false ; } void MasterCall() { } void MasterSms() { if ((val.indexOf( "on" ) > - 1 ) or (val.indexOf( "ON" ) > - 1 ) or (val.indexOf( "On" ) > - 1 ) or (val.indexOf( "oN" ) > - 1 )) { digitalWrite(HEATER, 1 ); digitalWrite(FAN, 1 ); heaterOn = true ; fanOn = true ; #ifdef DEBUG Serial.println( "Heater switched on in AUTO mode (SMS from " + phoneNumber + ")." ); #endif } if ((val.indexOf( "Off" ) > - 1 ) or (val.indexOf( "off" ) > - 1 ) or (val.indexOf( "oFF" ) > - 1 ) or (val.indexOf( "OFF" ) > - 1 )) { digitalWrite(HEATER, 0 ); heaterOn = false ; timestamp = millis(); #ifdef DEBUG Serial.println( "Heater switched off in AUTO mode (SMS from " + phoneNumber + ")." ); #endif } } void ConsolePrint() { MasterSms(); if ((val.indexOf( "clear" ) > - 1 ) or (val.indexOf( "Clear" ) > - 1 ) or (val.indexOf( "CLEAR" ) > - 1 )) { m590Serial.println( "AT+CMGD=0,4" ); Serial.println( "Clear: All messages removed" ); } if ((val.indexOf( "gettime" ) > - 1 ) or (val.indexOf( "GetTime" ) > - 1 ) or (val.indexOf( "Gettime" ) > - 1 ) or (val.indexOf( "getTime" ) > - 1 )) { printTime(); } if ((val.indexOf( "settime" ) > - 1 ) or (val.indexOf( "SetTime" ) > - 1 ) or (val.indexOf( "Settime" ) > - 1 ) or (val.indexOf( "setTime" ) > - 1 )) { Serial.println( "Enter year. Range: {2000, ..., 2099} :" ); long y = 0 ; while ((y < 2000 ) || (y > 2099 )) y = Serial.parseInt(); Serial.print( "Year is " ); Serial.println(y); Serial.println( "Enter month. Range: {1, ..., 12} :" ); long mon = 0 ; while ((mon < 1 ) || (mon > 12 )) mon = Serial.parseInt(); Serial.print( "Month is " ); Serial.println(mon); Serial.println( "Enter day of the month. Range: {1, ..., 31} :" ); long d = 0 ; while ((d < 1 ) || (d > 31 )) d = Serial.parseInt(); Serial.print( "Day of the month is " ); Serial.println(d); Serial.setTimeout( 65535 ); Serial.println( "Enter hour. Range: {0, ..., 23} :" ); long h = 99 ; do { h = Serial.parseInt(); } while ((h < 0 ) || (h > 23 )); Serial.print(h); Serial.println( " hours" ); Serial.println( "Enter minutes. Range: {0, ..., 59} :" ); long m = 99 ; while ((m < 0 ) || (m > 59 )) m = Serial.parseInt(); Serial.print(m); Serial.println( " minutes" ); Serial.println( "Enter seconds. Range: {0, ..., 59} :" ); long s = 99 ; while ((s < 0 ) || (s > 59 )) s = Serial.parseInt(); Serial.print(s); Serial.println( " seconds" ); Serial.println( "Enter weekday. Range: {1(Sunday), ..., 7(Saturday)} :" ); long w = 0 ; while ((w < 1 ) || (w > 7 )) w = Serial.parseInt(); Serial.print( "Weekday is " ); Serial.println(dayAsString(w)); Time newTime(y, mon, d, h, m, s, w); rtc.time(newTime); } } |
Comments
Post a Comment