July 22, 2018

IoT Project 3 : RaspberryPi3, GY-30 Sensor and Thingspeak(Avinash Aeron)

got light sensor GY-30 and excited to upgrade the Home-Environment monitoring solution that I’m building (see earlier posts on an integration of DTH11 and BMP085 sensors)

Required items:
– Raspberry PI 3 & SD Card with ubuntu-mate Operating System https://www.raspberrypi.org/products/ra … 3-model-b/
– GY-30 sensor pack
– 4 x pitch jumpers

Preparing Raspberry PI 3 & SHDC:
Create the setup as follows:
1. Download below two as described https://ubuntu-mate.org/raspberry-pi/
– 7-Zip to extract the image.
– Win32 Disk Imager to write the image.
2. Extracted ‘ubuntu-mate from zip and flashed SHCD using Win32 Disk Imager
3. Put the SHCD into slot and power-up the Raspberry PI 3.
4. After ubuntu-mate is up, execute following on the terminal:

CODE: SELECT ALL
sudo apt-get update
sudo apt-get upgrade

5. If you have not installed git, install it now:

CODE: SELECT ALL
sudo apt-get install git

6. Enable i2c :
Follow instructions (see reference – Steps to enable i2c on Rpi)
Setup GY-30 with Raspberry Pi:
7. A script used for this experiment:

CODE: SELECT ALL
"""
My First Internet of Things

Temperature/Humidity Light monitor using Raspberry Pi, DHT11, and photosensor
Data is displayed at thingspeak.com
2015/06/15
SolderingSunday.com

Based on project by Mahesh Venkitachalam at electronut.in

"""
# Import all the libraries we need to run
import sys
import RPi.GPIO as GPIO
import os
from time import sleep
import math
import Adafruit_DHT
import urllib2
import Adafruit_BMP.BMP085 as BMP085
import smbus
#import time

# Define some constants from the datasheet CY-30 light-sensor
DEVICE = 0x23 # Default device I2C address

POWER_DOWN = 0x00 # No active state
POWER_ON   = 0x01 # Power on
RESET      = 0x07 # Reset data register value

# Start measurement at 4lx resolution. Time typically 16ms.
CONTINUOUS_LOW_RES_MODE = 0x13
# Start measurement at 1lx resolution. Time typically 120ms
CONTINUOUS_HIGH_RES_MODE_1 = 0x10
# Start measurement at 0.5lx resolution. Time typically 120ms
CONTINUOUS_HIGH_RES_MODE_2 = 0x11
# Start measurement at 1lx resolution. Time typically 120ms
# Device is automatically set to Power Down after measurement.
ONE_TIME_HIGH_RES_MODE_1 = 0x20
# Start measurement at 0.5lx resolution. Time typically 120ms
# Device is automatically set to Power Down after measurement.
ONE_TIME_HIGH_RES_MODE_2 = 0x21
# Start measurement at 1lx resolution. Time typically 120ms
# Device is automatically set to Power Down after measurement.
ONE_TIME_LOW_RES_MODE = 0x23

#bus = smbus.SMBus(0) # Rev 1 Pi uses 0
#bus = smbus.SMBus(1)  # Rev 2 Pi uses 1

#========================================================
#sensor = BMP085.BMP085()
#bus = smbus.SMBus(1)  # Rev 2 Pi uses 1

DEBUG = 1
# Setup the pins we are connect to
RCpin = 24
DHTpin = 4

# Constants for Dew Point cumputation
DPB = 17.6 # 17.67 to be accurate
DPC = 243.5

#Setup our API and delay
myAPI = "MMC6LWE2DVMYFNPU"
myDelay = 10 #how many seconds between posting data

GPIO.setmode(GPIO.BCM)
#GPIO.setup(RCpin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

#*************************************************************
# for humidity-sensor DHT11
def getSensorData():
RHW, TW = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, DHTpin)

#Convert from Celius to Farenheit
TWF = 9*TW/5+32

# return dict
return (str(RHW), str(TW), str(TWF))

def computeDewPoint():

RHW, TW = Adafruit_DHT.read_retry(Adafruit_DHT.DHT11, DHTpin)

LGMA  = math.log(RHW/100)
DPTW = DPC+TW
GMA = DPB*TW/DPTW+LGMA
DPBGMA = DPB-GMA
DEWPC = DPC*GMA/DPBGMA

return (str(DEWPC))

#*************************************************************
# for pressure-sensor MSP085
def getPressureData():

#    print('Temp = {0:0.2f} *C'.format(sensor.read_temperature()))
#    print('Pressure = {0:0.2f} Pa'.format(sensor.read_pressure()))
#    print('Altitude = {0:0.2f} m'.format(sensor.read_altitude()))
#    print('Sealevel Pressure = {0:0.2f} Pa'.format(sensor.read_sealevel_pressure()))
sensor = BMP085.BMP085()

APHA = sensor.read_pressure()

MSLP = sensor.read_sealevel_pressure()

PTMP = sensor.read_temperature()
# return dict
return (str(APHA), str(MSLP), str(PTMP))

#*************************************************************
# for light-sensor GY-30
def convertToNumber(data):
# Simple function to convert 2 bytes of data
# into a decimal number
return ((data[1] + (256 * data[0])) / 1.2)

def readLight(addr=DEVICE):
bus = smbus.SMBus(1)
data = bus.read_i2c_block_data(addr,ONE_TIME_HIGH_RES_MODE_1)
return (str(convertToNumber(data)))

#  return (str(55.55))

#*************************************************************

# main() function
def main():

print 'starting...'

baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI
print baseURL

while True:
try:
RHW, TW, TWF = getSensorData()
#            print "DTH11 data obtained"
#            print TW + "C " + TWF+ "F " + RHW + "% "

DEWPC = computeDewPoint()
#            print "dewpoint computed"
#            print DEWPC + "C "

APHA, MSLP, PTMP = getPressureData()
#            print "MSP085 data obtained"
#            print PTMP + "*C " + APHA + "Pa " + MSLP + "Pa "

LIGHT = readLight()
#            print "GY-30 data obtained"
#            print LIGHT + "lux "
LT = "0"

f = urllib2.urlopen(baseURL +
"&field1=%s&field2=%s&field3=%s&field4=%s&field5=%s&field6=%s&field7=%s" % (TW, DEWPC, RHW, APHA, MSLP, LIGHT, PTMP) +
"&field8=%s" % (LT))
print f.read()
print TW + "*C " + TWF+ "*F " + RHW + "% " + DEWPC +"*C " + LT
print PTMP + "*C " + APHA + "Pa " + MSLP + "Pa " + LIGHT + "lux "
f.close()

sleep(int(myDelay))
except:
print " "
print TW + "*C " + TWF + "*F " + RHW + "% "
print 'exiting.'
break

# call main
if __name__ == '__main__':
main()

Connect as illustrated in picture:
VCC (GY-30 board) <-> pin17 (RPi-3 3.3v)
Ground (GY-30 board) <-> pin20 (RPi-3 Ground)
SDA (GY-30 board) <-> pin03 (RPi-3 GPIO-02 / SDA I2c)
SCL (GY-30 board) <-> pin05 (RPi-3 GPIO-03 / SCL I2c)

20160720_220245-1-1.jpg
RPi3 Setup with DTH11 BMP085 and GY-30

Setup Thingspeak:
Create your account at https://thingspeak.com/
Create your channel and set it up as you wish. Instructions are on the website.
The one created for this experiment is here:

GY-30_thingspeak.png
ThingSpeak channel setup

Here you go!
execute the python script and monitor data on the web.

Luninance.png
Luninance.png (6.34 KiB) Viewed 3 times

On the Android smart-phone:
Install ThingView from Google Play Store
Log in to your account and setup channel. You are done! All data on your smart-phone.

References:

RPi-3 pin diagram has been picked from here:
https://www.raspberrypi.org/documentation/usage/gpio-plus-and-raspi2/

Steps to enable i2c on Rpi:
http://skpang.co.uk/blog/archives/575

Leave a Reply

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