vvarrior
Posts: 89
Joined: Fri Jan 02, 2015 3:03 am

Float sensor changes with mode up, but not down

Mon Oct 22, 2018 6:31 pm

Subject pretty much describes it. I have a float sensor that when set to gpio mode up, will be 0 when closed and 1 when open. When I change the mode to down, it should be 1 when closed and 0 when open but it just stays on 0 whether its open or closed. Float sensor is outside of tank during this test so I can verify sensor is actually changing. I am also using an ohm meter to verify the switch is actually activating and it is.

All of my code is setup for gpio down. Float sensor is setup as an "empty" sensor. When the tank is not empty, the float sensor floats up and breaks the connection, gpio 18 will show 0 - empty = 0. When the tank is empty, float sensor follows gravity and closes connection, gpio 18 should show 1 - empty = 1.

This does work successfully with down on another raspberry pi zero w, so I'm not sure what I'm doing wrong on this one. Suggestions are welcome for troubleshooting.

pcmanbob
Posts: 4461
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Float sensor changes with mode up, but not down

Mon Oct 22, 2018 6:52 pm

You probably have the switch connected wrong as you have to change how its connected to the gpio when you change from pull up to pull down.

this site explains the difference for the wiring of the switch to the gpio

https://github.com/raspberrypilearning/ ... up_down.md
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

vvarrior
Posts: 89
Joined: Fri Jan 02, 2015 3:03 am

Re: Float sensor changes with mode up, but not down

Mon Oct 22, 2018 7:44 pm

It seems that all I need to do is swap the wires on the switch no? Easy enough because it's connected to the gpio with jst connectors, however, when I do that, the result is the same. I'll take a look at the schematics on the git link you sent and verify.

Thanks for your quick reply earlier.

vvarrior
Posts: 89
Joined: Fri Jan 02, 2015 3:03 am

Re: Float sensor changes with mode up, but not down

Mon Oct 22, 2018 7:46 pm

Actually, it looks like changing wires isn't enough. I will need to move the GPIO pin wire to the other wire on the float sensor, then instead of connecting to ground, I'll need to connect to 3.3v. Ok, I'll make that change and see what happens.

pcmanbob
Posts: 4461
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Float sensor changes with mode up, but not down

Mon Oct 22, 2018 7:48 pm

If you are still having problems post a picture of each version of the connections between your pi and the switch and the code you are using in each case.
Remember we want information.......................no information no help
The use of crystal balls & mind reading is not supported

vvarrior
Posts: 89
Joined: Fri Jan 02, 2015 3:03 am

Re: Float sensor changes with mode up, but not down

Mon Oct 22, 2018 8:08 pm

Nope, worked perfect. Changed wires (although I don't think that was a necessary step) and moved the float GND wire to 3.3v - gpio mode down started working. I love when simple fixes work - and there was also learning. Down circuits need positive voltage while up circuits need GND. Makes sense. The GPIO pin acts as positive for up circuits and ground for down circuits.

Thanks again. I love this forum.

Return to “Troubleshooting”