Tuesday, 19 January 2016

Car preheating automation with ESP8266

 Don't copy this. It requires messing with mains 230V that is lethal!
Seriously. Don't.

So here in finland winters are cold. Even at as south as Helsinki temperature can go bellow -25°C or -13°F so cars like some preheating before they are started for maximizing librication and minimizing gasoline consumption and engine wear. Also most of the people have heater blower inside car to heat it from the inside so it melts ice and snow from the windows. (Also it's much more comfortable to go and sit in the warm car.)

Till now i did not have any proper timing system or anything to turn heater on for x amount of time or schedule heating. There is only cable in the kitchen that goes through the wall outside and when you want to heat up car you plug the cable inside to socket. This means you might forget to do so, or remove the cable after heating meaning that car keeps getting heat even tho it's not necessary thus wasting electricity. (And too much heat is not good for car either since it causes oil from inside to dry out and flow down again reducing lubrication.)

Then i decided that timer/automation would be awesome. And since i need car kinda random times of day, i did not want those mechanical or digital timers that you plug to socket. Also something i can switch on from bed when i wake up would be totally great. So i started thinking and decided to make my own with ESP8266-12E and couple relays.


Started my design process with EAGLE and drew chematic. It's messy. Still need to learn to make neat designs.


 

Then was time to make the board. Turned out much neater. 
 

I was able to get out with only one jumper. I could have taken the trace between legs of the relay but i wanted to keep those as far as i could from mains voltage.

When i was happy with the design i created gcodes with pcb gcode for Eagle and made some modifications to it with Cambam.


Milling process with 0.1mm 60degrees cutter on my 3040T mill.


Ready pcb with removed copper around the mains area and gaps to keep any arcs away. Might be bit overkill but better be on the safe side. I also added some kapton tape where the module will be so it won't short to the copper under it. One of the traces got destroyed because the board was not completely flat so i fixed it with piece of wire soldered on the trace.

 Module soldered in place and mains traces tinned to improve current capacity.

All parts soldered and testing the pcb.
 
It works. Relays click and led turns on. At this point it was time for the software. On the module i flashed ESP8266BASIC most awesome way to develop on these modules. If you have not yet tried it i highly recomend you do. No need to connect module to the computer for modifying the software. You can do it over the internet and even from the other side of the world! With phone!

Here is the code for the module. It's not anyway optimized yet.

 cls  
 state = Off  
 po 13, 0  
 po 14, 0  
 heatingTime = 0  
 heatingTimeMin = 0  
 humanTime = 0  
 interrupt 12, [phyButton]  
 timer 1000, [timerSec]  
 css ulkoasu.css  
 wprint |<meta name="viewport" content="width=device-width, initial-scale=1" />|  
 wprint |<meta http-equiv='refresh' content='5;URL=/input?'></head>|  
 wprint |<center><b>|  
 wprint "Heater: "  
 wprint htmlvar(state)  
 wprint "<br> Heating time left: "  
 wprint htmlvar(humanTime)  
 wprint "<br><br>"  
 button "On for 2H" [onTwoH]  
 wprint "<br><br>"  
 button "On for 1H 30min" [onOneHalf]  
 wprint "<br><br>"  
 button "On for 1H" [onOneH]  
 wprint "<br><br>"  
 button "On for 30min" [onHalf]  
 wprint "<br><br>"  
 button "Off" [turnOff]  
 wprint "<br><br>"  
 wait  
   
 [onTwoH]  
 heatingTime = 7200  
 goto [turnOn]  
 wait  
   
 [onOneHalf]  
 heatingTime = 5400  
 goto [turnOn]  
 wait  
   
 [onOneH]  
 heatingTime = 3600  
 goto [turnOn]  
 wait  
   
 [onHalf]  
 heatingTime = 1800  
 goto [turnOn]  
 wait  
   
 [turnOn]  
 po 13, 1  
 po 14, 1  
 state = On  
 wait  
   
 [turnOff]  
 po 13, 0  
 po 14, 0  
 state = Off  
 heatingTime = 0  
 interrupt 12, [phyButton]  
 wait  
   
 [phyButton]  
 interrupt 12  
 plusheatingTime = heatingTime + 1800  
 if plusheatingTime < 7200 then goto [addTime]  
 if plusheatingTime > 7200 then goto [turnOff]  
 wait  
   
 [addTime]  
 heatingTime = heatingTime + 1800  
 goto [blinkLed]  
 wait  
   
 [blinkLed]  
 blinkTimes = heatingTime / 1800  
 blinkTimes = left(blinkTimes,1)  
 for x = 1 to blinkTimes  
 po 14, 0  
 delay 100  
 po 14, 1  
 next x  
 interrupt 12, [phyButton]  
 goto [turnOn]  
 wait  
   
 [timerSec]  
 plusheatingTime = 0  
 heatingTime = heatingTime - 1  
 heatingTimeMin = heatingTime / 60  
 if heatingTime > 3600 then heatingTimeMin = heatingTimeMin - 60  
 let heatingTimeMin = left(heatingTimeMin,2)  
 let heatingTimeMin = replace(heatingTimeMin,".","")  
 if heatingTime > 3600 then humanTime = "1h "  
 if heatingTime > 3600 then humanTime = humanTime & heatingTimeMin  
 if heatingTime > 3600 then humanTime = humanTime & "min"  
 if heatingTimeMin <= 0 then heatingTimeMin = 0  
 if heatingTime < 3600 then humanTime = heatingTimeMin & "min"  
 if heatingTime <= 0 then goto [turnOff]  
 wait  

GUI has 5 buttons. Times every 30 minutes and OFF. Physical button on the pin 12 works so 1 press selects 30min and led turns on. second press adds time and flashes led twice etc till 5th press turns it off.

And here is code for the CSS-file.

 button, input[type="button"], input[type="submit"] {   
      background-color:#000000;  
      border:4px solid #000000;  
      display:inline-block;  
      cursor:pointer;  
      color:#ffffff;  
      font-family:Arial;  
      font-size:20px;  
      text-decoration:none;  
      width:80%;  
      height:50px;  
      max-width:500px;  
 }   

Produces following GUI.

 
It also scales nicely on the screen of phone. 
 
 That working, it was time to make the case for the controller. Decided plastic box ment for doing electrical connections will work nicely. Found this from BILTEMA for 4.99€
Kytkinrasia 
And then. Making holess for the socket.
 
 
 

After some cleaning. Socket fits perfectly. Also from BILTEMA for couple euros.
  
Also pcb will fit neatly inside. There was even some conviniently placed screw holes inside the box for mounting the pcb.
 
 PCB for buttons comes mounted to the top of the box.
 
After that it was time to wire the pcb and the socket and the whole thing was done. Inside is also small nokia 5V charger to provide power for the module and relays. Some testing and crushing the bugs from the code and it was working well and ready for action.

Today i used it first time for 2 hours and all went great. Still have some ideas how to continue to make it better, for example scheduling system and OLED display on the front when they arrive.

- Jokke

No comments:

Post a Comment