Haby Philipose
Published © GPL3+

Temperature Monitoring System on Plants

Maintaining a controlled temperature within a greenhouse environment is crucial. Thus we built this project.

IntermediateFull instructions provided2 hours1,769
Temperature Monitoring System on Plants

Things used in this project

Hardware components

Bolt WiFi Module
Bolt IoT Bolt WiFi Module
×1
Gravity: Analog LM35 Temperature Sensor For Arduino
DFRobot Gravity: Analog LM35 Temperature Sensor For Arduino
×1

Software apps and online services

Bolt Cloud
Bolt IoT Bolt Cloud

Hand tools and fabrication machines

Extraction Tool, Male & Female Type XII Contacts
Extraction Tool, Male & Female Type XII Contacts

Story

Read more

Custom parts and enclosures

Message sent by twilio to our mobile phone.

Schematics

picture of the circuit used.

Code

CODE for the project and its explanation

Python
IN PYTHON TERMINAL
create a file named 'conf.py' which will store all the credentials related to Twilio. To create a new file type 'sudo nano conf.py' in the terminal. After that write below code to save all the credentials in a single file.

SID = 'You can find SID in your Twilio Dashboard'
AUTH_TOKEN = 'You can find on your Twilio Dashboard'
FROM_NUMBER = 'This is the no. generated by Twilio. You can find this on your Twilio Dashboard'
TO_NUMBER = 'This is your number. Make sure you are adding +91 in beginning'
API_KEY = 'This is your Bolt Cloud accout API key'
DEVICE_ID = 'This is the ID of your Bolt device'

Note:You can find the first four value in Twilio dashboard and the last two in Bolt Cloud dashboard.

We store all the credentials in a separate file since it is sensitive data which should not be shared with anyone. Hence it is a good practice to avoid using credentials in code directly. After replacing all the values, save the file using CTRL+X.

Step 4: Now create one more file named temp_sms.py. To do so you have to type sudo nano temp_sms.py in the terminal. Now we will write main code to collect the data from the Bolt and send SMS if it crosses the threshold.

The algorithm for the code can be broken down into the following steps -

Fetch the latest sensor value from the Bolt device.
Check if the sensor value is in the range specified in our min and max values.
If it is not in range, send the SMS.
Wait for 10 seconds.
Repeat from step 1.

Below is the complete code:

import conf
from boltiot import Sms, Bolt
import json, time

minimum_limit = 300
maximum_limit = 600


mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)


while True:
print ("Reading sensor value")
response = mybolt.analogRead('A0')
data = json.loads(response)
print("Sensor value is: " + str(data['value']))
try:
sensor_value = int(data['value'])
if sensor_value > maximum_limit or sensor_value < minimum_limit:
print("Making request to Twilio to send a SMS")
response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
print("Response received from Twilio is: " + str(response))
print("Status of SMS at Twilio is :" + str(response.status))
except Exception as e:
print ("Error occured: Below are the details")
print (e)
time.sleep(10)

Note: The above "sensor_value" is the raw temperature reading, obtained from the LM35 sensor. In case you want to convert this value to the temperature in degree Celsius, use the formula:

Temperature=(100*sensor_value)/1024

Where sensor_value is the variable in which data obtained from the LM35 sensor is stored.

Save the file. Time to run the code. To do so type `sudo python3 temp_sms.py` in terminal

Please note that SMS delivery via a trial Twilio account is NOT guaranteed to be instant by Twilio. Also, note that SMS will NOT be sent to numbers which have DND(Do Not Disturb) turned ON. It usually takes a few minutes for your SMS to be sent to your mobile number. Please check the logs on Twilio if you are not receiving the SMS even if the temperature exceeds the threshold.

Since we have written a couple of print statement in the code. So the temperature data will get printed on the terminal. If that value falls outside the threshold range then SMS will be sent to your registered number.
import conf
from boltiot import Sms, Bolt
import json, time

minimum_limit = 400
maximum_limit = 500  


mybolt = Bolt(conf.API_KEY, conf.DEVICE_ID)
sms = Sms(conf.SID, conf.AUTH_TOKEN, conf.TO_NUMBER, conf.FROM_NUMBER)


while True: 
    print ("Reading sensor value")
    response = mybolt.analogRead('A0') 
    data = json.loads(response) 
    print("Sensor value is: " + str(data['value']))
    try: 
        sensor_value = int(data['value']) 
        if sensor_value > maximum_limit or sensor_value < minimum_limit:
            print("Making request to Twilio to send a SMS")
            response = sms.send_sms("The Current temperature sensor value is " +str(sensor_value))
            print("Response received from Twilio is: " + str(response))
            print("Status of SMS at Twilio is :" + str(response.status))
    except Exception as e: 
        print ("Error occured: Below are the details")
        print (e)
    time.sleep(10)

Credits

Haby Philipose

Haby Philipose

1 project • 0 followers

Comments