Jorge
Published © GPL3+

WiPy Analog Light Sensor To Cloud

Measuring light and reporting it to Initial State Cloud, using Adafruit ALS-PT19 Analog Light Sensor Breakout and the Wipy to read.

BeginnerProtip1 hour1,320
WiPy Analog Light Sensor To Cloud

Things used in this project

Hardware components

WiPy 3.0
Pycom WiPy 3.0
×1
Adafruit ALS-PT19 Analog light Sensor Breakout
×1

Software apps and online services

Initial State
Easy to use cloud

Story

Read more

Schematics

Connection diagram

Code

Main.py

MicroPython
Using the Wipy to get the analog output and pushing the data to initial state cloud.

Main.py
#Imports
import pycom
import time
from machine import ADC
import urequest

pycom.heartbeat(False)#Disable LED heartbeat

#Configure the ADC
adc = ADC(0)
adc_c = adc.channel(pin='P13')

#We will push the information to the initialstate Cloud every 10 seconds
#The sensor used is the ALS PT19 you could find some on Adafruit.
#The ouput of the sensor is analog, for testing purposes we are going to work
#with the raw reading which will be the ADC counts
while True:
    adc_c()
    AmbientLight=adc_c.value()#We get the value of the counts here
    print(AmbientLight)# we print the  value stored on AmbientLight

    #here we will do the GET request to the Initialstate cloud with your credentials.
    #Note* Replace the accessKey and bucketKey with your own credentials
    r=urequest.request("GET","https://groker.initialstate.com/api/events?accessKey=xxxxxx&bucketKey=xxxxx&AmbientLight="+str(AmbientLight),None)
    r.close()
    time.sleep(10)

Boot.py

MicroPython
Boot.py file for configuration of wify

Use your WiFy credentials
# boot.py -- run on boot-up
import os
from machine import UART
from network import WLAN
uart = UART(0, 115200)
os.dupterm(uart)

wlan = WLAN(mode=WLAN.STA)
wlan.scan()

wlan.connect(ssid='yournetwork', auth=(WLAN.WPA2, 'yourpassword'))

while not wlan.isconnected():
    pass

print(wlan.ifconfig()) # prints out local IP to allow for easy connection via Pymakr Plugin or FTP Client

Credits

Jorge

Jorge

3 projects • 8 followers
I am a EE that enjoys doing projects at home having fun with electronics. I like the world of Internet of things. www.seasluglabs.io

Comments