Software apps and online services
Hand tools and fabrication machines
In this project, we are going to mix water, fire, light, wind, and beer with some hardware and code and send data to Hologram to notify us if the elements are pleased.
Imagine the following scenario:
You are ready to pop a cold one only to be met with that look that happens when you there is no beer left in the fridge. Somehow managing to avoid dry-heaving you head to the nearest beer store only to be met with a closed sign. And then the light bulb goes on, you are ready to use your inner full metal alchemist.
The RGB and ambient light sensor are used to detect the presence of beer. Light is shone on a beer bottle and the light intensity is measured. If the beer bottle is not there the reflection is minimal and the threshold if below the critical. If the space is full of beer the reflection is above the threshold and we are all happy.
This is where the Hologram functionality kicks in. Even if you're out of home and somebody else is imbibing on your ale, the Hologram server can send you an email or SMS so that you are prepared.
The hardware setup is shown below. The Hologram box emulates the beer bottle.
Ambient light sensor.
The main program makes use of the APDS9300 digital ambient light sensor which communicates over I2C. The sensor has two channels and based on the data sampled from two photo diodes one can calculate the amount of ambient light measured in LUX.
The Python driver code attached below contains a fully functional API for controlling the sensor.
An RGB led is used as the active sensor. During normal operation the RGB leds are all on. The light gets reflected from the bottle and is continuously measured by the sensor every second. If the ambient light is below the programmed threshold for more than a minute then the program sends an SMS to my phone.
Open a shell and issue:
sudo hologram connect
Then log in on your account using the username and password and select the plan if you have more than one. Once the modem blue led is blinking you are ready to proceed.
At this point, also make sure to take down your device key. This will be needed to send data or SMS via the Hologram modem.
The program shines a light on a beer bottle and measures the amount of reflected light. If the measured data is below a threshold (meaning no beer bottle in front of the sensor) an SMS is sent.
First we check the sensor address via the i2cdetect package. Issue:
sudo i2cdetect -y 1
This will give the addresses below. On my setup the ambient light sensor is the one with address 0x29.
The other two are the RTC and EEPROM.
The program initializes the sensor, configures access to the hologram cloud and and shines the LED over the bottles. The while loop then continuously measures the reflected light intensity. Once the reflected light is below the threshold an SMS message is send via the Hologram Nova and the program exits.
To send an SMS we have to import the subprocess module in Python and include this line:
subprocess.call (["hologram","send","--sms","--destination","+1xxxxxxxxx","'Message from Hologram.io : Out of Beer bro!'","--devicekey","mykeybro"])
Check the main program for further details. This basically calls a command line version with admin privileges.
I wanted to simulate the beer bottle with a nice bottle of rum but I settled for the cardboard box of the modem:
Start the program by issuing:
sudo python AppBeerSensor.py
And finally all the hard work rewards us with this:
Code available below. (licensed under GPLV3)