Monday, 22 February 2016

Wi-Fi controlled Air freshener

This is my project , a Wi-Fi controlled Air freshener.

Hi , I've found the best way to learn programming is to create a real project , so that you can solve problem you will encounter on the way ,which will allow your projects to get more and more complex as you learn.

The Hardwate

The hardware part Is made from a hacked automatic air freshener pump dispenser.
I could have easy built my own using a servo pressing down on the can`s top and built my own case, but why re-invent the wheel.

The Software

( 1 ) I started with a simple test code which would momentarily activate a port controlling the dispenser , go to sleep for 10 minutes to save batteries and whole restart the cycle again.
( 2 ) My next idea was to use the inbuilt ADCs on the photon to publish the voltage of the batteries , which turned out to be not so simple as first thought.
I build a voltage divider using 2 x 1k resistors and found that this method give inconsistent results also was not very battery friendly.
I decided to use a external ADC which give more consistent results and wasn't a big drain on battery life.
( 3 ) Now I wanted a method of controlling various variables used in my photon program , which would allow me to change the time in sleep ( The time between each pump of the  dispenser ) , the time the arm would press in the can , and the number of pumps, etc.
After a lot of trial and error I found a way to post the voltage to a cgi script and receive back a json data block.  
This was all right , but had to manually define each variable by editing the script by hand every time I wanted to make a change to the timing or number of pumps.
( 4 ) Next a made a user script using html form elements , so I could generate a json file to save , which the other script would load and control my photon.
This script has started to grow in complexity when new ideas form, which lead to having to rewriting all the other code.

No comments:

Post a Comment