Float Sensor - ArtTHEbard/Hydro-Pi-nics GitHub Wiki
Programming the Float Sensor
The float sensor is a small, waterproof sensor that we will be using to give readings about the water level in the basin. It sends out a boolean value based on the angle of the sensor arm.
Hardware
- Using a combination of female to female and male to male ribbon cables, I connected the float sensors two pins to the Pics pin 14 and 16(Ground).
Programming
My current code package for testing the senor:
import RPi.GPIO as GPIO
import time, httplib, urllib
GPIO.setmode(GPIO. BCM)
GPIO.setup (23, GPIO.IN, pull_up_down=GPIO. PUD_UP)
key = "**************"
while True:
input_state = GPIO.input (23)
if input_state == True:
status ="0"
time.sleep(10)
else:
status = "1"
params=urllib.urlencode({'field1':status, 'key':key})
headers={"Conetnt-type":"application/x-www-form-urlencoded","Accept":"text.plain"}
conn = httplib.HTTPConnection("api.thingspeak.com:80")
conn.request("POST","/update",params,headers)
response=conn.getresponse()
print(response.status, response.reason)
time.sleep(180)

MyCodo Configuration (DEPRECIATED)
In the Mycodo software, navigate to the Setup --> Input. In the Select Input dropdown, select "Raspberry Pi: GPIO State Sensor".

Once the Input adds to the list, select the cog icon and input the following settings.

Select the Data Tab and Navigate to the default dashboard or the dashboard you created. Select Add Widget. Enter the following Widget settings, and select Save.

Install
Using rubber gromets, we installed the float sensor in the side of our water basin through a hole we drilled. After testing the basin with standing water, we used FlexSeal to ensure that the sensor inclusion did not compromise the watertightness of the basin.
