I'm building an project where I need a pump which is controlled by the arduino but also has a float switch in case the water runs low. This all works, I can switch the pump on and off in software as needed and the float switch overrides the software control.
This is basically my system:
How can I get feedback from my circuit that tells me when the float switch is off, i.e. the circuit isn't closed? I would like to trigger an event if the float switch is off?
Sorry, that doesn't cut it here. This is because we need to know your exact system before we can offer good advice.
So where does the float switch feature in that schematic? Is it across collector and base of the transistor?
Is it in line with the motor's power? And what voltage is the motor running on, that link showed it was 5V from the Arduino.
Once we know these things we can tell you how to use the float switch as an input to the Arduino.
So, when the float switch is open there is no power to the motor and you can't override it with the Arduino. When the float switch is closed then the Arduino decides if the motor is running or not. Is that correct?
Connect the motor end of the switch to an Arduino input and add a 10K pull down resistor, that is one going from the input to ground. That will read LOW when the motor is off and the float switch is open.
Thanks, that works really well to tell me if the motor is running, i.e. I get a 1 on my Arduino pin when the float switch is on. When it's off though it switches from 1 to 0 and back again every few seconds?
This is something I can deal with, but I was wondering what causes this issue. Wiring as I understood it attached.
The diode should go across the motor after the float switch, otherwise the voltage on the motor
terminals will have inductive spikes that could be damaging to your pin sensing the voltage to
the motor.
The 10k across the motor is doing nothing AFAICT.
It will really help to learn to draw a circuit diagram, not a Fritzing wiring diagram, since
clear circuit diagrams (aka schematics) are the language electronic circuits are communicated in.
A wiring diagram is merely for the construction step, its not intended to communicate function to
humans, just to allow physical wiring up of a given circuit.
It was put in the wrong place, the previous advice was fine. The fact that it was not placed where you were told to place resulted in the problems you had with the signal reading high and low randomly. This is known as a floating input and he resistor, if correctly placed, cures his.
OK, now take that Fritzing layout and click on the Schematic tab. Spend some time making the wires look tidy, like having them all horizontal or vertical and minimizing the wire crossings, and you will have a passable schematic that everyone can respect.