School of Computing Department of Computer Science and Engineering
School of Computing Department of Computer Science and Engineering
Industry 4.0 concepts - Sensors and sensor Node and interfacing using any Embedded
target boards (Raspberry Pi / Intel Galileo/ARM Cortex/ Arduino) - DIY Kits – Soil
moisture monitoring - Weather monitoring - Air quality Monitoring - Movement
Detection.
VCC-->3v3
GND -->
GND
D0 --> GPIO 17 (Pin 11)
With everything now wired up, we can turn on the Raspberry Pi. Without writing
any code we can test to see our moisture sensor working. When the sensor detects
moisture, a second led will illuminate .So as a quick test, grab a glass of water (be
very careful not to spill water!!) then place the probes into the water and see the
detection led shine. If the detection light doesn‗t illuminate, you can adjust the
potentiometer on the sensor which allows you to change the detection threshold
(this only applies to the digital output signal). In this example we want to monitor
the moisture levels of our plant pot. So we want to set the detection point at a level
so that if it drops below we get notified that our plant pot is too dry and needs
watering. Our plant here, is a little on the dry side, but ok for now, if it gets any
drier it‗ll need watering.
Figure 2: Experimental Setup
To run the script simply run the following command from the same directory as
the script: sudo python moisture.py
1.1 Code
import RPi.GPIO as
import time
sendEmail function
def sendEmail(smtp_message):
try:
smtpObj.sendmail(smtp_sender, smtp_receivers,
except smtplib.SMTPException:
# This is our callback function, this function will be called every time there is a
change on the specified GPIO channel, in this example we are using 17
def callback(channel):
if GPIO.input(channel):
sendEmail(message_d
ead)
else:
sendEmail(message_al
ive)
BCM
GPIO.setmode(GPIO.BCM)
# Define the GPIO pin that we have our digital output from our sensor
connected to channel = 17
GPIO.setup(channel, GPIO.IN)
# This line tells our script to keep an eye on our gpio pin and let us know
when the pin goes HIGH or LOW
GPIO.add_event_callback(channel, callback)
# This line simply tells our script to wait 0.1 of a second, this is so the script
doesnt hog all of the CPU
time.sleep(0.1)
2. Weather Monitoring
DHT11 Specifications
The device itself has four pins but one of these is not used. You can buy the 4-pin
device on its own or as part of a 3-pin module. The modules have three pins and
are easy to connect directly to the Pi‗s GPIO header.
The 4-pin device will require a resistor (4.7K-10K) to be placed between Pin 1
(3.3V) and Pin 2 (Data). The 3-pin modules will usually have this resistor included
which makes the wiring a bit easier. The 3 pins should be connected to the Pi as
shown in the table below :
Your data pin can be attached to any GPIO pin you prefer. In my example I am
using physical pin 11 which is GPIO 17. Here is a 4-pin sensor connected to the
Pi‗s GPIO header. It has a 10K resistor between pin 1 (3.3V) and 2 (Data/Out).
Python Library
install python
AdafruitDHT.py 11 17
The example script takes two parameters. The first is the sensor type so is set to
―11‖ to represent the DHT11. The second is the GPIO number so for my example
I am using ―17‖ for GPIO17. You can change this if you are using a different
GPIO pin for your data/out wire. You should see an output similar to this :
Temp=22.0*Humidity=6
8.0% import
Adafruit_DHT
# Set sensor type : Options are DHT11,DHT22 or
AM2302 sensor=Adafruit_DHT.DHT11
connected to gpio=17
None:
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature,
humidity)) else:
Air pollution is a major problem in urban centers as well as rural set-up. The
major pollutants of concern are primarily carbon monoxide, nitrogen oxides,
hydrocarbons and particulate matter (PM10, PM2.5). Ozone, PAN and PBN are
other secondary pollutants generated as a result of the photochemical reactions
of the primary pollutants. These pollutants affect human health as well as
environment. Therefore, air pollution monitoring is necessary to keep a check
on the concentration of these pollutants in ambient air. The grove sensors, grove
DHT (for temperature and humidity), grove gas sensor modules like dust, MQ-5
(for smoke), MQ-7 (for CO) and MQ-135 (for CO2) are interfaced to this shield
for monitoring in our proposed.
Adafruit CCS811 is a gas sensor that can detect a wide range of Volatile
Organic Compounds (VOCs) and is intended for indoor air quality monitoring.
When connected to your microcontroller (running our library code) it will return a
Total Volatile Organic Compound (TVOC) reading and an equivalent carbon
dioxide reading (eCO2) over I2C. There is also an on- board thermistor that can be
used to calculate the approximate local ambient temperature.
Vin - this is the power pin. Since the sensor uses 3.3V, we have included an
onboard voltage regulator that will take 3-5VDC and safely convert it
down. To power the board, give it the same power as the logic level of
your microcontroller - e.g. for a 5V micro like Arduino, use 5V
3Vo - this is the 3.3V output from the voltage regulator, you can grab up to
100mA from this if you like
GND - common ground for power and logic
Logic pins
SCL - this is the I2C clock pin, connect to your microcontrollers I2C
clock line.
There is a 10K pullup on this pin and it is level shifted so you can use 3 -
5VDC.
SDA - this is the I2C data pin, connect to your microcontrollers I2C data
line. There is a 10K pullup on this pin and it is level shifted so you can
use 3 - 5VDC.
INT - this is the interrupt-output pin. It is 3V logic and you can use it to
detect when a new reading is ready or when a reading gets too high or too
low.
WAKE - this is the wakeup pin for the sensor. It needs to be pulled to
ground in order to communicate with the sensor. This pin is level shifted
so you can use 3- 5VDC logic.
RST - this is the reset pin. When it is pulled to ground the sensor resets
itself. This pin is level shifted so you can use 3-5VDC logic.
Next, we will install the Raspberry Pi library and Adafruit_GPIO which is our
hardware interfacing layer
1. sudo apt-get install -y build-essential python-pip python-dev python-smbus git
2. git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
3. cd Adafruit_Python_GPIO
4. sudo python setup.py install
Enable I2C
We need to enable the I2C bus so we can communicate with the sensor.
1. sudo raspi-config
Once I2C is enabled, we need to slow the speed way down due to constraints of
this particular sensor.
1. dtparam=i2c_baudrate=10000
press Ctrl+X, then Y, then enter to save and exit. Then run sudo shutdown -h
now to turn off the Pi and prepare for wiring.
Wiring Up Sensor
With the Pi powered off, we can wire up the sensor to the Pi Cobbler like this:
Now you should be able to verify that the sensor is wired up correctly by asking the
Pi to detect what addresses it can see on the I2C bus:
1. sudo i2cdetect -y 1
1. cd ~/
2. git clone https://github.com/adafruit/Adafruit_CCS811_python.git
3. cd Adafruit_CCS811_python/examples
4. sudo python CCS811_example.py
Adafruit_CCS811 ccs =
Adafruit_CCS811()
while not
ccs.available():
pass
temp =
ccs.calculateTemperature()
while(1):
if ccs.available():
temp =
ccs.calculateTemperature() if
not ccs.readData():
"ERROR!"
while(1):
pas
s sleep(2)
4. Movement Detection
PIR stands for passive infrared. This motion sensor consists of a fresnel lens, an
infrared detector, and supporting detection circuitry. The lens on the sensor focuses
any infrared radiation present around it toward the infrared detector. Our bodies
generate infrared heat, and as a result, this heat is picked up by the motion sensor.
The sensor outputs a 5V signal for a period of one minute as soon as it detects the
presence of a person. It offers a tentative range of detection of about 6–7 meters
and is highly sensitive. When the PIR motion sensor detects a person, it outputs a
5V signal to the Raspberry Pi through its GPIO and we define what the Raspberry
Pi should do as it detects an intruder through the Python coding. Here we are just
printing "Intruder detected".
library
while True:
detection
Thingspeak Go to
www.thinspeak.com
Once you Sign in after your account activation, Create a new channel by
clicking ―New Channel‖ button
After the ―New Channel‖ page loads, enter the Name and Description of the data
you want to upload. You can enter the name of your data (ex: Temperature) in
Field1. If you want more Fields you can check the box next to Field option and
enter the corresponding name of your data.
We created two Fields, one is CPU Memory and one for CPU Temperature
To upload our data, we need an API key, which we will later include in a piece of
python code to upload our sensor data to Thingspeak Website.
Click on ―API Keys‖ tab to get the key for uploading your sensor data.
Figure 11: Copy the Write API Key of the channel
Go to
https://github.com/sriharshakunda/Thingspeak_CPU_Python-
notepad. Code:
Use your Write API Key to replace the key with your API Key
Use your Write API Key to replace the key with your API Key
Step 5: Assuming you have python 2.7 and proper python libraries, go to the
folder where you copied the CPU_Python.py file
In case if there are any errors uploading the data, you will receive ―connection failed‖
message
Open your channel and you should see the temperature uploading into thinspeak
website.
Figure: 12 CPU Temperature data displayed in
Field Chart
6. IFTTT
IFTTT – short for ‗If This Then That‗ – is a free online service that lets you
automate specific tasks. It lets you trigger actions on other apps, web services and
devices automatically every time certain conditions are met. These trigger > action
relationships used to be called recipes. but will now be known as Applets. The
trigger and action relationships have always been known as recipes‗, but that‗s all
changing. From now on, they will be dubbed Applets. There are no major changes
to the way things work, but there are a few differences worth being aware of. Each
Applet you enable will still trigger ‗if this then that‗ action when the relevant
conditions are met, but now Applets can trigger multiple actions, instead of just
one. Once the first action is completed, a second, third, fourth, etc, can also be
triggered.
"Channel" is IFTTT parlance for a Web service or other action. IFTTT currently
supports 67 different channels spanning a wide range of popular services, and it
can perform basic actions such as calling or texting a phone, or sending you an
email. Here's a list of all the available IFTTT channels. You may recognize some
of them: Craigslist, Dropbox, Evernote, Facebook, Flickr, Foursquare, Instagram,
SkyDrive, Twitter, YouTube, and a wide range of Google services are just the tip
of the iceberg. A newly released iPhone IFTTT app even adds channels for your
phone's Reminders, Contacts, and Photos apps. Once you've gone through and
activated some channels—basically, granting IFTTT access to your various
services or providing it with personal details—you're ready to start crafting.
Services
A service is just what it sounds like, a tool, application, or facility that works with
IFTTT. The brilliant thing about IFTTT is that its variety of channels allows it to
offer something to everybody. The list of available services is enormous and more
are added all the time. Some of the most popular services include Facebook,
Twitter, Instagram, YouTube, SoundCloud, Dropbox, Evernote, and Pocket.
Applets
Applets are what make IFTTT worth your time. Basically, they are the
combination of services that use a trigger and an action. When something happens
on one service, it triggers an action on another.
Create an Applet
The first step is to click My Applets and then New Applet. Next, click the word This.
Figure13: Login Page
For this example, we will select the Instagram trigger, which will then ask us to
activate Instagram just this once. Having done that, we will choose a trigger
action:
After doing this, we will be greeted by the second batch of actions. We‗ll select the
first one and be asked to complete the fields. In this case, it‗s asking us where to
grab the photos, how to name them and where it should put them. All you have to
do is click on the Add ingredient, make your selection from the drop-down box,
and hit the Create Action button. Finally, you will be asked to review your Applet.
You can optionally enable notifications when the Applet runs. Then, click Finish.
Pre-Made Applets
We can browse other people‗s Applets, view options by category, check out
collections, look at recommendations, or do a search if you are looking for
something specific. And, using existing Applets is easier than creating your own.
Just click on an Applet to review the details, and move the slider to turn it on.
Depending on the Applet you choose, you may be asked to connect an account like
Facebook or configure pieces of the Applet like date and time. But, this is all very
simple and self-explanatory as you move through the process.
Top 7 Applets
Add and remotely control sensors, motors, actuators, GPIO boards, and more
Customizable dashboards with drag-and-drop widgets for connection devices
Create triggers and threshold alerts for devices, events, and actions
Schedule one-time or multi-device events for easy automation
Quick and easy setup - connect your Pi in minutes
Step 1: Go to Cayenne site and Sign Up. After download the file and install the
Cayenne system on your Raspberry Pi. Download the app on your Smartphone or
tablet by using the follows link
Cayenne on Apple Store or Cayenne on Play Store
Install on your Raspberry Pi the Raspbian system. For this step download NOOBS
from Raspberripi.org: https://www.raspberrypi.org/downloads/
Copy the package on your SD, and start the Raspbian installation. For the raspbian
installation I recommend to use a HDMI screen, a USB mouse and a USB
keyboard.After this, connect your Raspberry at your LAN by cable. Then open your
Cayenne app and install the library on your device. The next step.
Install on your Raspberry Pi the Raspbian system. After this, connect your Raspberry
at your LAN by cable. Then open your Cayenne app and install the library on your
device (or)
wget
https://cayenne.mydevices.com/dl/rpi_b8w8pn82i
By using Computer you can see your device on: https://cayenne.mydevices.com/ like
in photo. By using a Smartphone you can open the app and see your devices.You can
personalize the Dashboard of Cayenne by using the widgets. The default Dashboard
have CPU, Temp and RAM widget . These are the values of your Raspberry Pi. You
can see the temp and the work flow of Raspberry pi. Then you can see the GPIO
schedule. In the GPIO you can set every pin of GPIO of Raspberry. You can set the
pin like Output or Input. Then you can activate the pin or read the value of the pin. The
two values are HIGH or LOW. This is valid for Input and Output.
Step 4: Connect a Led to Your Raspberry Pi
Now you can connect a led to GPIO port of Raspberry Pi. Use ALWAYS a resistor in
series to led. If you don't use a resistor, you can burn the led or the Raspberry Pi. See
the photo and connect the led to pin number 11 or GPIO 17.
Now you can add a widget. Select Actuators device --> Select Generic --> Select
Digital Output. Fill the all the fields, and select the correct channel for RGB led.
You can use a normal breadboard and an RGB led common cathode. The RGB led is a
led that have 3 leds inside. Why the pin are only 3? Because the 3 leds share a cathode,
or anode pin. For this reason you must specify the kind of led you want. Now I use a
common cathode led.
the 24
The Alexa Voice Service (AVS) enables you to access cloud-based Alexa
capabilities with the support of AVS APIs, hardware kits, software tools, and
documentation. We simplify building voice-forward products by handling complex
speech recognition and natural language understanding in the cloud, reducing your
development costs and accelerating your time to market. Best of all, regular Alexa
updates bring new features to your product and add support for a growing assortment
of compatible smart home devices. Build with AVS, and become part of the Alexa
family.