'How do I solve error '<=' not supported between instances of 'float' and 'NoneType' on pyFirmata?
I am making a code for an automatic watering system for my plants using pyFirmata on Arduino but I always get this error when I try to run it
Traceback (most recent call last):
File "C:/Users/wenbi/PycharmProjects/Helen/Automated watefring.py", line 43, in <module>
if 0.5<=val<=0.7:
TypeError: '<=' not supported between instances of 'float' and 'NoneType'
When I got the two input values "val" from the reading of the soil moisture sensor connected to A0 on my Arduino and "waterlvl" from the water sensor connected to D2 to print, it will only give a 'None' as a result instead of a value.
I don't know what's wrong with my code as Pycharm isn't detecting any problems.
Here's my code for reference:
import time
from pyfirmata import Arduino, util
board = Arduino('COM4')
iterator = util.Iterator(board)
iterator.start()
LED5 = board.get_pin('d:5:o')
LED6 = board.get_pin('d:6:o')
LED7 = board.get_pin('d:7:o')
buzz_pin = board.get_pin('d:10:o')
waterdetect = board.get_pin('d:2:i')
soildetect = board.get_pin('a:0:i')
waterpump = board.get_pin('d:8:s')
def blinkLED6():
for s in range(1):
LED6.write(1)
time.sleep(0.25)
LED6.write(0)
time.sleep(0.25)
def buzzalarm():
for f in range(1):
buzz_pin.write(1)
time.sleep(0.25)
buzz_pin.write(0)
time.sleep(0.25)
while True:
val = soildetect.read()
waterlvl = waterdetect.read()
if 0.5 <= val <= 0.7:
LED5.write(1)
if waterdetect == "True":
buzzalarm()
elif waterdetect == "False":
waterpump.write(1)
LED5.write(0)
blinkLED6()
if val <= 0.25:
waterpump.write(0)
LED7.write(1)
if val < 0.5:
continue
So can I ask how do I solve this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|