Smart Home Sensor for Water Usage – Raspberry Pi

by Apr 5, 2020Raspberry Pi projects

In our previous post, we discussed the smart home automation with Arduino and NodeMCU. In this post, we will implement the smart home sensor design using Raspberry Pi.

Click here for the link for Smart home sensor development using Arduino Uno and NodeMCU

With Piezo electric sensor

The Piezoelectric Sensor connected to one of the analog pins in the MCP3008 chip with a 1Megaohm resistor connected series with the sensor. The threshold value calculated for the sensor, if the sensor reads values more than 200 then there is a flow of water in the pipe. The date and time set up to verify the flow in a particular time period.

After the successful connection of the sensors with the Raspberry Pi and the code implementation using Python, the results are obtained. The MCP3008 chip is low cost and easy to connect also doesn’t need any extra components. The SPI bus protocol is used which is supported by the Raspberry Pi’s GPIO pins. The SSH is enabled in the Raspberry Pi configuration and the whole system can be viewed in a remote desktop software application. The TightVNC is a free, open-source viewer used for the graphical desktop sharing.

Circuit

Code

# Importing modules
import spidev # To communicate with SPI devices
from time import sleep
import datetime

# To add delay
# Start SPI connection
spi = spidev.SpiDev() # Created an object
spi.open(0,0) 
# Read MCP3008 data
def analogInput(channel):
  spi.max_speed_hz = 1350000
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data

# Below function will convert data to voltage
def Volts(data):
  volts = (data * 3.3) / float(1023)
  volts = round(volts, 2) # Round off to 2 decimal places
  return volts
 
while True:
  temp_output = analogInput(1) # Reading from CH0
  temp_volts = Volts(temp_output)                                                                                          
  x = datetime.datetime.now()
  print("vibration : {} {} ({}V)".format(temp_output,x,temp_volts))
  if (temp_output > 200):
    print ("The tap is ON")
  
  sleep(5)

Results

The calculated threshold value set to an analog value of 100. The sensor detects the flow every 5 seconds and prints the result. When the analog sensor reading is above the threshold value, it indicates water flow in the pipe and prints the line “The tap is ON”.

The table shows the results of the experiment which tests the accuracy of the sensor while the tap opened and closed for a few seconds. When the tap was opened at 02:39:10 pm, the output analog value shows 94 where the value is not as per the calculated threshold value. However, at 02:39:17 pm, the output analog value reaches the calculated threshold value and shows 152.

2. Raspberry Pi and Thermistor

In thermistor when the tap is ON and the temperature of the water changes irrespective of hot or cold, the analog value elevates to the range from 130 to 170. The value decreases to 0 when the tap is OFF. When there is no flow in the pipe it prints the line “There is no temperature change!” in the python shell. There is no delay in this experiment.

The resistance of 10K ohm connected series to the thermistor. It acts as a voltage divider. The analog data from the CH0 pin which also connected with a 10K ohms resistor. The values read from Python IDLE which provides information on the date and time of the water flow.

Circuit

Code

# Importing modules
import spidev # To communicate with SPI devices
from time import sleep
import datetime

# To add delay
# Start SPI connection
spi = spidev.SpiDev() # Created an object
spi.open(0,0) 
# Read MCP3008 data
def analogInput(channel):
  spi.max_speed_hz = 1350000
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data



# Below function will convert data to voltage
def Volts(data):
  volts = (data * 3.3) / float(1023)
  volts = round(volts, 2) # Round off to 2 decimal places
  return volts
 
# Below function will convert data to temperature.
def Temp(data):
  temp = ((data * 330)/float(1023))-50
  temp = round(temp)
  return temp


while True:
  temp_output = analogInput(0) # Reading from CH0
  temp_volts = Volts(temp_output)
  x = datetime.datetime.now()
  if (temp_output < 4):
    
    print("Temp : {} {} ({}V)".format(temp_output,x,temp_volts))
    print ("The tap is ON")
  sleep(5)

The table displays the experiment results of the thermistor with different temperatures. The time period for each trial is for 15 seconds. There are no errors in the first trial. The tap closed for 10 seconds from 04:10:40 pm to 04:10:49 pm and opened again. During this period of time,printed the line “There is no temperature change”. Also, there were no errors at this point. However, when the tap was opened again at 04:10:50 pm there was a minor error for a second as it didn’t reach the calculated threshold value (130-170) analog integer. This error neglected as the measurement reaches the threshold limits of the sensor in the next 5 seconds.

Creating a multiplication Skill in Alexa using python

Written By Monisha Macharla

Hi, I'm Monisha. I am a tech blogger and a hobbyist. I am eager to learn and explore tech related stuff! also, I wanted to deliver you the same as much as the simpler way with more informative content. I generally appreciate learning by doing, rather than only learning. Thank you for reading my blog! Happy learning!

RELATED POSTS

Magic Wand using Raspberry Pi and OpenCV

Magic Wand using Raspberry Pi and OpenCV

What if I could do things with a swing of a wand? Practically impossible but with technology maybe not. In this tutorial, we will use a raspberry pi and OpenCV to try and recreate something similar to a wand. It will perform specific functions when it recognizes...

IBM Watson IoT Platform with Raspberry Pi

IBM Watson IoT Platform with Raspberry Pi

IBM Watson is one of the leading cloud computing platforms there is. It has almost all the features one could expect from a modern-day cloud platform, from machine learning support to IoT, even till edge computing. In this tutorial, we will use raspberry pi and an...

Home Automation With Telegram and Raspberry Pi

Home Automation With Telegram and Raspberry Pi

In this Article we will see how we can use Telegram for Home Automation. Telegram is an extremely popular multi-platform messaging service. Just like any other messaging platform, it is used to send messages and exchange photos, videos, stickers, audio, and files of...

Home Automation System with Raspberry Pi and Flask

Home Automation systems are becoming increasingly popular for the level of convenience they offer. Imagine sitting on your couch and turning on/off lights or fans in the room without having to get up. You could also control blinds or even door locks. This project is a...

Smart Alarm Clock with Raspberry Pi

Smart Alarm Clock with Raspberry Pi

Smart Alarms are very common today yet the good ones expensive. What if you wanted to make a smart alarm clock on your own using as little hardware and cost as possible? You may ask isn't the RPI costly, yes it is but, the only purpose of using an RPI is easy to net...

VIDEOS – FOLLOW US ON YOUTUBE

EXPLORE OUR IOT PROJECTS

IoT Smart Gardening System – ESP8266, MQTT, Adafruit IO

Gardening is always a very calming pastime. However, our gardens' plants may not always receive the care they require due to our active lifestyles. What if we could remotely keep an eye on their health and provide them with the attention they require? In this article,...

How to Simulate IoT projects using Cisco Packet Tracer

In this tutorial, let's learn how to simulate the IoT project using the Cisco packet tracer. As an example, we shall build a simple Home Automation project to control and monitor devices. Introduction Firstly, let's quickly look at the overview of the software. Packet...

All you need to know about integrating NodeMCU with Ubidots over MQTT

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

All you need to know about integrating NodeMCU with Ubidots over Https

In this tutorial, let's discuss Integrating NodeMCU and Ubidots IoT platform. As an illustration, we shall interface the DHT11 sensor to monitor temperature and Humidity. Additionally, an led bulb is controlled using the dashboard. Besides, the implementation will be...

How to design a Wireless Blind Stick using nRF24L01 Module?

Introduction Let's learn to design a low-cost wireless blind stick using the nRF24L01 transceiver module. So the complete project is divided into the transmitter part and receiver part. Thus, the Transmitter part consists of an Arduino Nano microcontroller, ultrasonic...

Sending Temperature data to ThingSpeak Cloud and Visualize

In this article, we are going to learn “How to send temperature data to ThingSpeak Cloud?”. We can then visualize the temperature data uploaded to ThingSpeak Cloud anywhere in the world. But "What is ThingSpeak?” ThingSpeak is an open-source IoT platform that allows...

Amaze your friend with latest tricks of Raspberry Pi and Firebase

Introduction to our Raspberry Pi and Firebase trick Let me introduce you to the latest trick of Raspberry Pi and Firebase we'll be using to fool them. It begins with a small circuit to connect a temperature sensor and an Infrared sensor with Raspberry Pi. The circuit...

How to implement Machine Learning on IoT based Data?

Introduction The industrial scope for the convergence of the Internet of Things(IoT) and Machine learning(ML) is wide and informative. IoT renders an enormous amount of data from various sensors. On the other hand, ML opens up insight hidden in the acquired data....

Smart Display Board based on IoT and Google Firebase

Introduction In this tutorial, we are going to build a Smart Display Board based on IoT and Google Firebase by using NodeMCU8266 (or you can even use NodeMCU32) and LCD. Generally, in shops, hotels, offices, railway stations, notice/ display boards are used. They are...

Smart Gardening System – GO GREEN Project

Automation of farm activities can transform agricultural domain from being manual into a dynamic field to yield higher production with less human intervention. The project Green is developed to manage farms using modern information and communication technologies....