Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Himanshu Dagdi
Published © GPL3+

Water Level Monitoring System in Water Tanks Using Bolt IoT

Feel Bored while Monitoring water tanks in our Houses to avoid overflow and wastage of water? This Simple project can solve these Problems.

IntermediateFull instructions provided5 hours11,262
Water Level Monitoring System in Water Tanks Using Bolt IoT

Things used in this project

Story

Read more

Schematics

CIRCUIT

This is how the connections are done

Code

Python3 Program

Python
import requests, time, math, json
from boltiot import Bolt
import conf2 as conf	#my Configuration File

data = [] 	#Empty list for storing sensor values...
mybolt = Bolt(conf.bolt_api_key, conf.device_id) #My Bolt
mybolt.digitalWrite(0,"LOW")

#Function:Get Sensor Value
def get_sv(pin):
	try:
		response = mybolt.analogRead(pin)
		data = json.loads(response)
		if data["success"]!=1:
			print("Rquest Failed")
			print("Response:",data)
			return -999
		sensor_value = int(data["value"])
		return sensor_value
	except Exception as e:
		print("Something went wrong")
		print(e)
		return -999

#Function:Send Telegram Message
def send_tm(message):
	url = "https://api.telegram.org/"+conf.telegram_bot_id+"/sendMessage"
	data = {
		"chat_id":conf.telegram_chat_id,
		"text":message
	}
	try:
		response=requests.request(
			"POST",
			url,
			params = data
		)
		print("This is the telegram response=>")
		print(response.text)
		telegram_data = json.loads(response.text)
		return telegram_data["ok"]
	except Exception as e:
		print("Errror Occurred in sending the alert message")
		print(e)
		return False


#MAIN:->
while True:
	sensor_value = get_sv("A0")
	print("Sensor value is = ",sensor_value)

	if sensor_value == -999:
		print("Request unsuccessful.Skipping...")
		time.sleep(10)
		continue

	if(sensor_value >= conf.threshold):
		print("Alert:Water Level exceeded the threshold value")
		message = "Alert(Type 1)!Water Level exceeded.Time to Stop filling the tank"+
			".The current sensor value is:"+str(sensor_value)
		telegram_status = send_tm(message)
		print("This is the telegram status:",telegram_status)
		mybolt.digitalwrite(0,"HIGH")
		time.sleep(60)
		mybolt.digitalWrite(0,"LOW")
	else:
		mybolt.digitalwrite(0,"LOW")

	data.append(sensor_value)
	time.sleep(10)

#END

JS Program :-

JavaScript
Code for the product in Bolt Cloud
setChartLibrary('google-chart');
setChartTitle('Water Level Monitoring !!!');
setChartType('areaGraph');
setAxisName('Time Stamp', 'Water Level');
plotChart('time_stamp', 'water');

Credits

Himanshu Dagdi
1 project • 4 followers

Comments