Issue with float switchs

G40Mitch

New member
Hello,

Im building a project that has 2 float switchs for measuring water depth. When both switchs are activated it switchs on a 12v pump (via mosfet) until the water drops below the lower float switch.

However im having an issue with the float switch.

I have everything on a picaxe experimenter board if i use the boards push buttons to simulate float switchs it works perfectly however as soon as i connect up the float switchs it becomes very unreliable.

Sometimes it works fine but most of the time it will only activate the pump for a brief moment and not for the full duration down to the bottom float switch.

Its like the bottom float switch isnt activating fully.

Is there a way to change how much activation the switch needs before the picaxe sees a 1 or 0
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

There should generally be no difference between a push button switch and a float switch but I am guessing the float switches are some way away from the PICAXE board whereas the push buttons would be closer when being tested.

The float switch should be giving a clean on-off indication but it could be that they are resistive and don't. Some details on the float switches may help there.

The push buttons on the experimenter board have pull-up resistors included. If you haven't added those pull-ups when using the float switches that could cause things not to work.

It could be that some ripple in the water is causing the float switches to activate then deactivate and the program code is not designed to handle that possibility.

The other possibility is that the distance is the issue, the length of wiring causing false triggering or similar which is causing the program to prematurely stop working. Details on how you have the switches wired to the PICAXE and what your program is doing will help with that.

It should be possible to make it all work. It's just a question of determining why it currently doesn't.
 
Last edited:

G40Mitch

New member
The float switchs only have about 6" of wire on them as it is very much a prototype. I am manually pulling up the float switches with my finger so water bounce is not an issue either (i also have pause to help prevent bounce).

One side of each switch connects to the pin on the picaxe 18m2 (c.2 and c.1). The other connected to ground. Im guessing this is the issue. Ive been reading about pullup and pulldown resistors is this what is needed.

I have only just picked up the picaxe for the first time since school over 10years ago so please bare with me.

I have uploaded my code. Im still messing with it but the bit in questions starts at line 150 titled Main:
 

Attachments

hippy

Technical Support
Staff member
One side of each switch connects to the pin on the picaxe 18m2 (c.2 and c.1). The other connected to ground. Im guessing this is the issue. Ive been reading about pullup and pulldown resistors is this what is needed.
It does sound like missing pull-ups will be the issue. You will need to add those externally as the 18M2 doesn't support internal pull-ups for the pins you are using. 4K7 or 10K are usually good choices but almost anything will do at least for testing. Connect the resistors between the pin / switch signal and PICAXE V+.
 

G40Mitch

New member
Will give it a go when I'm back home tonight thanks for your help.

I only have 10k resistors so hopefully they work ok.
 

inglewoodpete

Senior Member
One side of each switch connects to the pin on the picaxe 18m2 (c.2 and c.1). The other connected to ground. Im guessing this is the issue. Ive been reading about pullup and pulldown resistors is this what is needed.
10k resistors will be fine for pullups or pulldowns. The inputs need to be held in stable state when not activated. Without a pullup or pulldown resistor connected, the input will 'float' in value and could randomly read as low or high, affected by electrostatic or magnetic fields. A pullup or pulldown resistor holds the input high (+4.5v to 5v) or low (0.5v to 0v) and acts a bit like a rubber band. When an opposite voltage is applied to the pin the state being read on the pin will change.
 

Aries

New Member
Another thing to remember if and when you move from the pre-built Picaxe board to something else is that you will definitely need the 100nF decoupling capacitor across the Picaxe supply pins. Motors are notorious for interference and could cause erratic behaviour of the Picaxe, such as random resets.

I have a set of six float switches in an underground rainwater harvesting tank, to measure levels and trigger the pump if the tank is over-full. The connections are actually to TTL ics, with 10k pull-down resistors and the TTLs then connect to the Picaxe. The switches are about 30m away from the control box (containing a Picaxe 20M2 plus various TTLs), with a 5V supply. I have not had problems with the switches' internals. However, I have had corrosion of joints in the wires (most are perforce underwater) and a spider weaving a web around the topmost switch, so that it didn't operate. Also - as I am currently missing decoupling capacitors on the TTLs - when the tank is quite full, I can get the pump triggering when I turn on the fluorescent lights in the garage. Just some things for you to beware of in the future....
 

techElder

Well-known member
Will give it a go when I'm back home tonight thanks for your help.

I only have 10k resistors so hopefully they work ok.
I would add larger capacitors from the pin to ground. Experiment with values so you get slow switch detection at the picaxe. Water level rising is a slow event, but the picaxe is capable of seeing many interim uninvolved events.
 
Top