IOT with Google Analytics

Partical This post is going to be a little different from what I normally write about. You wont find any .Net or PHP in this post. We are going to talk about Internet Of Things(IOT).

The internet of things (IoT) is the network of physical objects—devices, vehicles, buildings and other items—embedded with electronics, software, sensors, and network connectivity that enables these objects to collect and exchange data.

Instead of just taking data from an API and displaying it we are taking data from the real world and doing something with it.    There are a lot of options out there for doing this.   Arduino and Raspberry Pi are the two I have heard most about.    I have done a lot of reading on this subject but to be honest looking at a circuit board it seamed like a daunting task.    What are all these wires and tube things (Resistors) anyway? What do they do? How do you know what goes to where?     A few months ago I ran across a local group of geeks or nerds who are also interested in IOT and they seamed willing to teach me.     So I have joined IOT Denmark on Saturday we had our first hackathon.    They ordered some kits (we each paid for our own pretty cheep if you ask me)  and where told to make an account on a website and that was that.      So 9 am Saturday i showed up and that’s where things got interesting.

Particle Photon

So apparently there are other types of controllers then the Arduino and Pi.   We where each given a Particle Photon there is all kinds of technical info on this thing on their website i wont try and explain what it is.    The basic point of the Photon is its cheep and it has WiFi on board.    For me the WiFi  was a huge plus you know me if i cant hook something to the cloud whats the point of it.

We had all day to play these things someone tried to explain about resistors and Ome’s law.   I think someone is going to have to go over that with me again personally one on one for that to sink.   I am sure i didn’t understand a word of it.     They also tried to show us how to build things using diagrams again blank. To me looked like he was drawing a picture from a 19 century artist Picasso maybe?   Quite pretty but like most art didn’t make much sense.   Again i think I need someone to sit with me one on one  to get that into my head.    My goal is to do a bit of studying before the next meeting then I can ask some questions.

So again these guys are great sat with me and helped me plug one wire to ground OK add a resistor between the power and the light bulb light-bulb to ground wow!

Top Tip:  If you get a Photon don’t push on the top of it to take the USB cable out.   That would be the setup and reset buttons.   Duh! * 2

Google Analytics

Ok so around noon I had a photoresistor working.  That’s cool you can detect changes in light level.   If anyone wants to know it goes down by two every minute.   Yes i know you couldn’t live without that information.   So now what?  A bit of Googling yes you can send HTTP Posts and HTTP Gets with the Photon some nice person made a HTTP library.     20 minutes later figure out how to add a library.

By the end of the day I had it sending hits to Google Analytics nothing major but i could push a button and send a hit.


So I got a little board Sunday.    This is where things stand currently.    Every minute I log the current light level as a custom metric to a Google Analytics application account.   If the light level changes by more then 50 points plus or minus I log a Light change event decrees or increase with the event value of the amount changed. This is version 1, the code is nasty I plan on improving it as soon as I dig around in my old C books, its been a while.

Version changes

Version 1:
Checks light level every minute. If it has changed by more then 50 we log it to Google Analytics as a light level change event
Version 2:
Checks light level every second if it has changed by more then 5 we log it as an event to Google analytics.
Every minute or 60 steps of the above then we log the current light level as a hit to google analytics.
I am wondering if you can use this as a movement detector during the day. IF someone is standing between it and a light source it will detect a change in light level.

Running log

Here are the results after it ran for a night.HomeAnalytics

So what we have here is the midnight refrigerator raid spy system anyone turns a light on in the kitchen at night I am going to know about it.   There is also a automatic light out side the kitchen window for the drive way.   The dam cat that has been laying on the car sets it off sometimes.   I wonder if we can get this to fire a fog horn if anything sets it off at 3 am, probably annoy the heck out of my neighbors though.   details details …..

It still has a few bugs I am not sure why I am logging more increases then decreases you would think the event logging would be more equal.

This is just the start I am going to order a humidity , temperature , Co2 sensors soon.  Then we can log some other things around the house to Google Analytics.


Power consumption

It ran for two days attached to my Anker Astro battery then it stopped running. Astro appears to be at 50% power, I am charging it up again not to see if its a power issue.



I have looked into Google Authentication with Particle and it shouldn’t take me to long to figure that out.   Then i can for example write to a Google Sheet and store the data there as well.   This might be useful for logging since the logging to the Particle website is limited I think by how long you have the browser window open.


This is just the start I think.   I have been a programmer for 20 years but everything i have done has been with data that is already on the system.    Being able to play with data from the real world is giving me so many ideas.    I cant wait to try them,  but i think i need to learn about resistors and circuit diagram first.   Baby steps.

Say Hello to Kitchen spy!




About Linda Lawton

My name is Linda Lawton I have more than 20 years experience working as an application developer and a database expert. I have also been working with Google APIs since 2012 and I have been contributing to the Google .Net client library since 2013. In 2013 I became a a Google Developer Experts for Google Analytics.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.