Wireless Sensor Proof of Concept

A project log for PASS: Pollution Analytics Shared Socially

A community pollution monitoring system aggregating pollution data from individual station users to get information on the environment.

Joshua YoungJoshua Young 09/10/2015 at 17:150 Comments

I am still waiting on my parts to come in for my Gas senor build, but thought that lack of proper parts should not stop my progress so I decided to press on. What I wanted was a prof of concept that I could implement a user monitoring system and add functionality to the system to allow user queries and interaction. I had a water moisture senor handy so I decided to make a sink leak detector (or water heater, or AC, or whatever you want to stay dry).

First step was figuring out the tools. I have been using a mBed Freescale Freedom board as my prototyping controller since it works well with my ESP 8266 wifi board, and the water sensor seems happy at 3 volts. For the web interfacing and UI I decided to go with what I have been using so far and that is ThingSpeak and IFTTT. ThingSpeak is a great place to dump, log and read data with simple HTTP requests. IFTTT is a great API linker that has a maker channel that can allow your controller to interact and post to just about all forms of social medial and communication. Once the tools were identified I need to map out the controller logic. The primary goals I had for this leak detector were to send out an initial leak notice as soon as a leak occurred, while still allowing the user to poll the leak detector status on demand. Just to try two methods I decided to use twitter to post the initial status and phone text messages to take in poll requests and send updates back to the user. Below is a map of the basic pseudo code I wanted to use. I did not end up using all of the variable flags as it adds complexity, but you could get more than one data point if you wanted to.

Once the base logic was figured out I began to implement the code on the mBed online compiler. I already have libraries for IFTTT, ESP 8266 and HTTP that I hacked into my code, I say hacked, because it was not the cleanest of jobs. One I got those libraries linked correctly I pasted in my simple loop to test the moisture read from my Freedom board's analog pin. I set the leak event to be triggered over a 30% moisture level. I noticed that just touching the sensor could get values of up to 25%. The initial twitter post was taken care of with a single post to a recipe I created in IFTTT to tweet a leak notification when the IFTTT url is pinged by my microcontroller via the ESP 8266.

The user query part of the code was more complex. I used IFTTT to post a text flag to ThingSpeak everytime I sent a text to IFTTT. My code scans ThingSpeak to look for this flag, when it sees it, the code goes into some if statements to set the appropriate state response. Once the response is text sent the code writes over the Text flag in ThingSpeak and continues to wait for more requests in an endless loop.

It took a few tries of code tweeks, but the leak detector ended up working pretty well. I got a battery back and USB backup battery to plug into my boards and ended up making the device fully portable. I am not sure if I would do this as a final implementation, but I was fun to see it working truly wireless.

The next steps will be implementing a similar protocol with my Gas sensors, once they are working to get them to post real time air Quality data.