USB sensors send data to the Cloud from Raspberry Pi Computer Board

Our Model LFS108 series USB sensors can be connected to Raspberry Pi computer board. You can monitor your sensor data from Raspberry Pi, save them to SD card and/or send the data to the Cloud. Here are the steps to setup an account with Thingspeak.com which is an IoT platform:

  1. You need to create an account with ThingSpeak.com. The account is free. ThingSpeak is an IoT platform to collect data to cloud, analyze the data, and react to the data.
  2. Create a new Private Channel. Fill in the channel settings such as Name, Description, Field 1, Field 2, etc. Each Field is for one set of data.
  3. Go to API keys tab and look for “Write API Key”. Copy the API key code.
  4. Paste the API key code in the following program.

After setting up your account with Thingspeak.com, connect your LFS108 series sensor board to the USB port of the Raspberry Pi board. Most of the Raspberry Pi boards already come with built-in WiFi. Connect the board to your local WiFi network. Run the following Python program from the Raspberry Pi. This program reads the Infrared & Ambient temperature and relative humidity from LFS108D board, saves the data to a local text file, and sends the data to the cloud.

# -*- coding: utf-8 -*-
import serial
import time
import urllib2

# ------- Setup the URL for Thingspeak.com Data Cloud --------

baseURL = 'http://api.thingspeak.com/update?key=Your API Key'

# ----- Setup the Serial COM Port ------

ser = serial.Serial(
port='/dev/ttyACM0',
baudrate = 115200,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=1
)

# ---- Create a data file -----

file_name = raw_input("Please enter file name:")
data_file = open(file_name, 'w')
data_file.write("LFS108D Test Data\n")
data_file.write("Time(HH:MM:SS) Infrared (Deg F) Ambient(Deg F) Humidity(%RH)\n")

for i in range(5):

# ----- Read the Infrared Temperature -----

ser.write('GET3\r')
x = ser.readline()
x = x[:-1]                # Remove the last character
a = int(x) / 10.0      # Divide the number by 10
print "Infrared - Deg F =" ,a

# ----- Read the Ambient Temperature -----

ser.write('GET1\r')
x = ser.readline()
x = x[:-1]              # Remove the last character
b = int(x) / 10.0    # Divide the number by 10
print "Ambient - Deg F =" ,b

# ----- Read the Relative Humidity -----

ser.write('GET2\r')
x = ser.readline()
x = x[:-1]                # Remove the last character
c = int(x) / 10.0      # Divide the number by 10
print "Humidity %RH =" ,c

now = time.strftime("%H:%M:%S")
y = str(now)
data_file.write(y)
data_file.write(" ")
y = str(a)
data_file.write(y)    # Save Infrared Temp in data file
data_file.write(" ")
y = str(b)
data_file.write(y)    # Save Ambient Temp in data file
data_file.write(" ")
y = str(c)
data_file.write(y)    # Save Relative Humidity in data file
data_file.write("\n")

# ------- Send Sensor Data to the Cloud -----------
f = urllib2.urlopen(baseURL + '&field1=' + str(a) + '&field2=' + str(b) + '&field3=' + str(c))
f.read()
f.close()

# ------ 20 second timer --------
time.sleep(20)
data_file.close()

                  Typical Python Program running on Raspberry Pi board

Typical Thingspeak.com Screen, LFS108D Temperature and Humidity

                        Typical Thingspeak.com Screen

LFS108D Temperature, Humidity sensor board connected to Raspberry Pi board

       Connecting LFS108D board to Raspberry Pi Computer board


Older Post Newer Post