Things used in this project

Hardware components:
Photon new
Particle Photon
×1
12002 04
Breadboard (generic)
×1
MikroElektronika Alcohol Click
×1
Software apps and online services:
Zpm toolbar 1
Zerynth Studio
Zerynth lamp app
Zerynth App

Code

Alcohol tester code - Zerynth App - TemplateHTML (Ruby)
<html>

<head>
  <zerynth/>
  <zerynth-jquery/>
  <zerynth-jquery-mobile/>
  <zerynth-jqwidgets/>
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>
  <div data-role="page">
    <div data-role="header">
      <h1>IoT Alcohol Tester</h1></div>
    <div role="main" class="ui-content" style="text-align:center">
          <div class="demo-gauge" style="position: relative; height: 380px;">
        <div id='gauge' style="position: relative; margin: auto;">
        </div>
    </div>
    <p id="label" style="color:#468c8c; font-size:36px;" >Blooooooooow!</p>
    </div>
    <div data-role="footer">Powered by Zerynth</div>
  </div>
  <script>
 $(document).ready(function () {
            $('#gauge').jqxGauge({
                 ranges: [{ startValue: 0, endValue: 60, style: { fill: '#4cb848', stroke: '#4cb848' }, startDistance: 0, endDistance: 0 },
                         { startValue: 60, endValue: 80, style: { fill: '#fad00b', stroke: '#fad00b' }, startDistance: 0, endDistance: 0 },
                         { startValue: 80, endValue: 100, style: { fill: '#e53d37', stroke: '#e53d37' }, startDistance: 0, endDistance: 0}],
                cap: { size: '5%', style: { fill: '#2e79bb', stroke: '#2e79bb'} },
                border: { style: { fill: '#8e9495', stroke: '#7b8384', 'stroke-width': 1 }, visible: false},
                ticksMinor: { interval: 5, size: '5%' },
                ticksMajor: { interval: 20, size: '10%' },       
                labels: { position: 'outside', interval: 20 },
                pointer: { style: { fill: '#2e79bb' }, width: 5 }, 
                value: 0,
                max: 100,
                animationDuration: 1000
            });
        });
            msg_ok = "Keep Calm and Drink Beer!";
            msg_no = "You're drunk, go home! (Don't Drive!)";
            function update_graph(x){
            $("#gauge").jqxGauge('setValue', x)
            }
            ZerynthApp.listen("adc",update_graph)
            
            function update_label(msg){
            if (msg == 0){
                $("#label").text(msg_ok);
            } else if (msg == 1) {
                $("#label").text(msg_no)};
            }
            ZerynthApp.listen("show_msg",update_label)
            
            ZerynthApp.jquerymobile_scalecontent()
  </script>
</body>
</html>
Alcohol tester code - Zerynth StudioPython
# IoT Alcohol Tester

# import everything needed
import streams
from wireless import wifi
from broadcom.bcm43362 import bcm43362 as wifi_driver
from zerynthapp import zerynthapp
import adc

streams.serial()

# save the template.html in the board flash with new_resource
new_resource("template.html")

# init the wifi driver!
# The driver automatically registers itself to the wifi interface
# with the correct configuration for the selected board

# connect to a wifi network
try:
    wifi_driver.auto_init()
    # use the wifi interface to link to the Access Point
    # change network name, security and password as needed
    print("Establishing Link...")
    wifi.link("wifi-name", wifi.WIFI_WPA2, "wifi-password")
    print("Ok!")
except Exception as e:
    print(e)


def map_range(x, in_min, in_max, out_min, out_max):
    if x < in_min:
        x = in_min
    elif x > in_max:
        x = in_max
    return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min

# Configure and run the Zerynth App instance

zp = zerynthapp.ZerynthApp("IoT Alcohol Tester", "Yeah, an IoT breathalyzer", "resource://template.html", logging=True)
zp.run()

msgs = ["Keep Calm and Drink Beer!", "You're drunk, go home! (Don't Drive!)"]
x = adc.read(A0)
max_in = 1100  # set the potentiometer to low and check the max value
range = 100
threshold = 80
x_old = map_range(x, 0, max_in, 0, range)

while True:
    sleep(500)
    # read from adc
    x = adc.read(A0)
    print(x)
    x = map_range(x, 0, max_in, 0, range)
    # send the value to the mobile app via a notification event called "adc"
    # the notification is sent only after the mobile app to zerynth script link is established ;)
    zp.notify("adc", x)
    print(x)
    if x <= threshold and x_old >= threshold:
        zp.notify("show_msg", 0)
        print(msgs[0])
    elif x > threshold and x_old < threshold:
        zp.notify("show_msg", 1)
        print(msgs[1])
    x_old = x
readme.mdPython
IoT Alcohol Tester
================

Yeah, an IoT breathalyzer

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Two Person Weasley Clock with Particle Photon and IFTTT
Easy
  • 680
  • 8

Full instructions

Taking inspiration from the Harry Potter character's Weasley clock, this one uses Particle and IFTTT to tell you where two people are.

Security+ 2.0 MyQ Garage Door Opener
Easy
  • 764
  • 3

Full instructions

Interface newer garage door openers with more than a relay.

Temperature and humidity monitor
Easy
  • 335
  • 3

Full instructions

This is a project that uses SHT30 to get the current temperature and humidity. And then displays it on a no-chip embeded LCD.

Measuring temperature and humidity with Particle Photon
Easy
  • 523
  • 3

Full instructions

Measure temperature and humidity with Particle Photon and Adafruit Si7021 using the Adafruit Si7021 library for I2C based communication.

Study Buddy
Easy
  • 2,388
  • 140

Full instructions

Know when an assignment is coming up!

Study Buddy

Team Alexa and Shannon

Automatic garage door opener using geolocation on Android.
Easy
  • 620
  • 2

Full instructions

Control and monitor your garage door remotely and open it automatically when approaching your house using geolocation.

Add projectSign up / Login
Respect project