Water level sensor with reed switches

Hi,
Can you please post some images of your project, in particular the level sensor array?

Did you purchase it or build it yourself?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

All this will help keep us all on the same page.

Thanks... Tom... :smiley: :+1: :coffee: :australia:
PS. I used to make custom level sensors like yours, and we spaced the reed switches so that there was not a gap between them when the magnet ascended or descended. They were wired to resistors so you got a change in resistance for level, so only three wires needed and an analog input.

The post i replied about was about light the one sensed and all below. The code in post #15 does not save the position of the last positive read nor restore it.

here, just so it doesn't get lost.

int level;

void loop () {
    for (int i = 0; i < numReedSwitches; i++) {
        if (LOW == digitalRead (reedSwitchPins[i]))  {
            level = i;
        }
    }

    for (int i = 0; i <= numReedSwitches; i++)  {
        if (i <= level)
            digitalWrite (ledPins[i], On);
        else
            digitalWrite (ledPins[i], Off);
    }
}

This is what i got so far. ive had a look around and couldent find any sensors to fit the depth i needed, plus i find it more fun to do little diy projects :smiley:

I did start off with resistors between the reed switches but changed it thinking it was to complicated for me.

This is great thanks, but i'd need too many reed switches to close the gaps between them. the depth i need is 3 feet, unless i use a much stronger magnet? hmm

Thanks for this, it works great, except it doesent light up the highest led when the highest switch is closed, and the bottom switch turns off all the leds when i'd really need the bottom led to remain lit if that makes sense

huh?
doesn't the code below from post #15, which you copied above, save the the index of the last detected switch?

Ah, a little mistake in @gcjr's code which I did not spot!

Should be:

for (int i = 0; i <= numReedSwitches; i++) {

not

for (int i = 0; i < numReedSwitches; i++) {

Does not make much sense to me. How will you know if the bottom switch is activated?

Do you really want a 9th led which is a power led?

so you think the loop should test 9 (0-8) switches?

it should turn on from 0 to and including level ( <= level)

Ehhh, no of course not, sorry about that @gcjr :man_facepalming:t2:

However,

for (int i = 0; i <= numReedSwitches; i++)  {
        if (i <= level)
            digitalWrite (ledPins[i], On);
else
            digitalWrite (ledPins[i], Off);

we don't want to access ledPins[8]

yes, both should be

for (int i = 0; i < numReedSwitches; i++)  {

but should be

        if (i <= level)
3 Likes

awesome thanks everyone that sorted it :smiley:

Okay no, you're right since it only sets detected level, initially zero.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.