Arduino Forum

Using Arduino => Project Guidance => Topic started by: bigdonk on Jan 09, 2019, 08:05 pm

Title: Noob here: Mosfet question and feasibilty
Post by: bigdonk on Jan 09, 2019, 08:05 pm
I want to try and do my first build.

I am trying to accomplish a water sensor for (3) areas with a single approach. The area where I want the arduino has 2 close spots. One will be approx 5 feet away and the other approx 10 feet away. The third spot will be approx 70ft (max) away.

I have come across many setups for this to be accomplished. I also came across how to modify a cheap door sensor to do the same thing. I was trying to combine the options I have seen.

I wanted to use a BS170-N as a switch similar to this drawing:

(https://cnet3.cbsistatic.com/img/t43VCtvhK7cNUfNbzdgyixRyLkQ=/0x0:2560x1397/770x578/2016/02/01/d5fc6d4f-3ac1-4669-93a7-a92071c1cfd1/fs-schematic.jpg)

The reason is I could then run (1) pair of wires to all 3 locations instead of needing multiple sensors. I don't need to know which one is wet, just that one is. I would like to put an Arduino with ethernet or wifi in place of the circuit board/battery in the diagram to send info to a pc.

The other setups I have seen call for multiple sensors and arduinos because of distance which ads cost.

Will this work like I want or am I incorrect? How would I connect to the Arduino?

Is this way inferior to the float switch or water sensors?

Thanks for any input.
Title: Re: Noob here: Mosfet question and feasibilty
Post by: DVDdoug on Jan 09, 2019, 08:48 pm
Not enough information...  We don't know anything about your "sensors". 

You shouldn't need a MOSFET on the input.   You didn't say the "circuit board" is an Arduino...  Is it?  You didn't say if you're connected to a pin programmed as an input (analog or digital) or programmed as an output.
Title: Re: Noob here: Mosfet question and feasibilty
Post by: bigdonk on Jan 09, 2019, 09:50 pm
Sorry, for the lack of specifics. Trying to explain better.

There are no sensors. There are 2 leads (very bottom of drawing) that when wet make a connection. The two wires would lay on the ground next to each other without touching and when wet will create a connection.

I mentioned that I want to put an arduino (ethernet or wifi capable) in place of the circuit board in the drawing. The drawing is of a standard window or door switch that is powered by batteries and has a alarm on it which is shown above the circuit board.

In this setup I believe the Gate sees some voltage when the 2 wires are wet at the same time triggering it.

Here is a link to the door sensor water alarm project: Door Sensor for Water Alarm (https://www.cnet.com/how-to/how-to-build-your-own-flood-sensor/)

I like the simplicity as well as benefits of doing it that way and was trying to incorporate it with an Arduino. I would only need one if this will work instead of multiple Arduino's and float or other water sensors.

I hope this explanation and link make more sense.

Thx,
Don
Title: Re: Noob here: Mosfet question and feasibilty
Post by: bluejets on Jan 10, 2019, 12:05 am
Don't need to buy all that stuff.
Go here..................................
http://www.talkingelectronics.com/te_interactive_index.html

Scroll to ebook 2 101-200ccts on the left side.....then on the right, scroll down to "water level detector".
3 circuits there, use one as an input to the Arduino.(connect where the 1K resistor meets the collector)
e.g. circuit 2, do not use the relay or the diode.
Will more than likely work with 5v supply, you may have to adjust the resistors to suit.
Title: Re: Noob here: Mosfet question and feasibilty
Post by: bigdonk on Jan 10, 2019, 01:15 am
Thanks for the reply. I think I am able to partially grasp that.

I am new to this, so if I ask a dumb question I apologize in advance  :)

What is the advantage of the BC547 over a BS170 Mosfet? I could accomplish the same thing with either component couldn't I? I ask because I thought the Mosfet had a lower voltage drop and may work better over distance and I have 1 run of 70ft.

I was looking at boards and think the ARDUINO MKR WIFI 1010 would be best as its already a 3.3V board. I would prefer ethernet, but it seems wifi is the cheaper route.

I am going off Circuit 3 from your link. I would be able to use as shown, but instead of running 3 for different levels, I could use 1 for each of the 3 locations.

I am not entirely certain on how to connect the Arduino. You mention to connect where the 1k resistor meets the collector, but in Circuit 3 there is only 100R's and they are on the emitter side. I don't fully grasp Circuit 2.

I see a 3V battery connection and a button, which I would not need so I am assuming I would supply the 3V voltage from the arduino. Would that be from an output pin or the 3V pin? Does the common get connected to ground on the Arduino?

Thx again,
Don
Title: Re: Noob here: Mosfet question and feasibilty
Post by: bluejets on Jan 10, 2019, 02:04 am
Mosfets usually have an extremely high input resistance and are a voltage operated device.
Transistors on the other hand are current operated(some will disagree) however the darlington arrangement of the 2... bc547 makes the circuit gain extremely high (multiplication of gain of both transistors) so either circuit should be ok.

As far as your approach on circuit 3, yes, fine.

For your Arduino, same connection for input. One each from the emitter/resistor point this time and program for a high signal with water present.i.e. as the transistor turns on, it will change the resistor/collector point from a low to a high signal.
Comprende..??

Oh, and remember to join the ground of your sensors to ground of the Arduino.
Title: Re: Noob here: Mosfet question and feasibilty
Post by: bigdonk on Jan 10, 2019, 02:41 pm
Thanks for your help. I have only been looking into circuitry and arduino for a few days. I usually pick things up really quick and maybe unfortunately get addicted to new things :)

If you have any recommendations on some really good reading/videos and or kits I should order to start it would be much appreciated.

Pretty confident I can handle this first project now thanks to you. I will report back with my success/failure next week after I give it a shot.

Thx,
Don
Title: Re: Noob here: Mosfet question and feasibilty
Post by: wvmarle on Jan 10, 2019, 02:49 pm
That MOSFET won't do you any good at 3.3V levels. It's not even well suited for 5V.

It sounds like you're trying to build a flood sensor for your home/basement, based around an Arduino, correct? Then this door bell hack is the wrong way. Just forget about it. It's a hack, and a rather ugly one at that.

Get a float switch, even cheaper, easier and almost certainly more reliable than this hack if only because it's designed for this exact job. Water rises, switch opens (don't get a type that closes when water rises). Simple and reliable. If you really want to cheap out on signal wire you can connect them all in series.

As they're all in series and normally closed, you can run a small current through the wire. Connect it to an Arduino pin, set it to INPUT_PULLUP, other end to GND. The moment one of the switches is triggered, or the wire breaks, the circuit breaks and your alarm goes off. DON'T get types that close when they detect water. That's less reliable, as in case your wire breaks the alarm will not go off, ever.

Spend a few bucks more and you can wire them up separately.
Title: Re: Noob here: Mosfet question and feasibilty
Post by: bigdonk on Jan 10, 2019, 03:21 pm
Thanks for the reply.  You are correct in what I am trying to do. I was just using the hack as an example. I was more looking at bluejets recommendation.

Pic won't post for some reason link is below

https://www.dropbox.com/s/jpwhgs6lx1f96ya/Capture.jpg

I would be setting the above circuit as 3 different water sensors instead of using them to monitor different water levels.

I wasn't against the float switches, but I thought I read somewhere that I couldn't have a 70ft run. Don't mind paying more for sensors, just didn't want to have multiple Arduinos.

Would (3) float switches with runs of 5, 10, and 70ft work with a single Arduino?

Are the floats a better choice then the diagram above?

(2) floats will be in sump pits and I am not worried about a wire breaking. Is there any worry of a normally closed switch seizing itself from not being activated for months or years?

Title: Re: Noob here: Mosfet question and feasibilty
Post by: wvmarle on Jan 10, 2019, 03:31 pm
Note that with a normal float switch you basically don't need any extra parts.

Would (3) float switches with runs of 5, 10, and 70ft work with a single Arduino?
Yes, but 70 ft is a very long wire, and will act as antenna. That may give problems with EMI (and false readings), and risk of lightning strikes. Even a nearby strike may induce high voltages in that long a wire.
For the EMI it may be a good idea to add a small bypass capacitor (10-100 nF ceramic), and possibly a stronger external pull-up resistor instead of using the internal one (start with 4k7). Capacitors may also be a good measure for the other two, with shorter wires.

Quote
Are the floats a better choice then the diagram above?
Just about anything is better than that hacked door bell.

Quote
(2) floats will be in sump pits and I am not worried about a wire breaking. Is there any worry of a normally closed switch seizing itself from not being activated for months or years?
Well, it won't seize itself, but it may get seized up over time. Dirt falling on it, a rat building a nest on it, that kind of things mean you should at the very least do some inspection once or twice a year. Floats that are actually activated on a somewhat regular basis should keep themselves clean. Nonetheless it'll be far, far more reliable than your doorbell hack.

Even if you don't expect wires to break, it's a very simple safety measure (at no additional cost) to use a normal closed circuit.
Title: Re: Noob here: Mosfet question and feasibilty
Post by: bigdonk on Jan 10, 2019, 04:52 pm
Wow, thanks for all that info. I am definitely leaning that way now.

Quote
For the EMI it may be a good idea to add a small bypass capacitor (10-100 nF ceramic), and possibly a stronger external pull-up resistor instead of using the internal one (start with 4k7). Capacitors may also be a good measure for the other two, with shorter wires.
I am extremely new to this so bare with me. I would run a lead from board 5V to pull-up resistor to say pin 3. I would then run 1 side of the float switch to connect between pin 3 and the pull-up resistor. The other side of the float would go to the ground pin.

For the bypass capacitor I would assume they go in between the ground and pin 3. Does it matter if it connects between the pin and switch or anywhere between the pull-up resistor and pin.

Now for the confusing part to me, how do I add the other 2 sensors so they can have their own respective pin. If I connect them to ground and between the pull-up and their pin, won't they all trip when 1 float is triggered. Not that its a big deal, but probably would be nice to get individual alerts if its easy to do.

Hopefully I got at least a few things correct above...

Title: Re: Noob here: Mosfet question and feasibilty
Post by: wvmarle on Jan 10, 2019, 05:04 pm
Each sensor would have its own pull-up and pin of course.

The capacitor goes close to the Arduino's pin.

Those float switches would be wired and read just like regular switches and buttons - lots of tutorials on those online.
Title: Re: Noob here: Mosfet question and feasibilty
Post by: bigdonk on Jan 10, 2019, 07:36 pm
OK, I got it. I was thinking I only needed 1 pull-up, but that clearly doesn't make sense.

I also thought I only needed 1 capacitor, but you had mentioned putting one on each sensor so after freshly downloading fritzing I have come up with this. The one thing I wasn't sure of is if it mattered if the capacitor was between the resistor and input pin or float switch and input pin.

I used buttons as I couldn't find the float sensors.

Can you tell me if I am close?

UPDATE: I forgot you said ceramic capacitor, so the image shows the incorrect one!

(https://forum.arduino.cc/index.php?action=dlattach;topic=589806.0;attach=289517)
Title: Re: Noob here: Mosfet question and feasibilty
Post by: wvmarle on Jan 10, 2019, 08:31 pm
Now if you'd have upgraded to real schematic drawing software (EagleCAD, KiCAD) you'd have been a lot further. It's just way too hard to figure out what is connected to what and how in those spaghetti images. It looks OK.

Capacitor goes between pin and GND. Resistor between pin and Vcc. Switch between pin and GND. Physical layout matters in this case: the capacitor goes with the Arduino, near the pin. Not at the switch (the other end of the wire), it doesn't have much effect there. For practical reasons the resistor also goes at the Arduino.
Title: Re: Noob here: Mosfet question and feasibilty
Post by: bigdonk on Jan 10, 2019, 08:59 pm
Thanks for all the help. I wasn't ready for the real software yet! I will keep everything at the arduino and only the leads for the sensors will be long.

I'm going to give this a shot and see what happens. I'll report back when I get all the stuff in and try it.
Title: Re: Noob here: Mosfet question and feasibilty
Post by: bigdonk on Jan 19, 2019, 03:46 am
Just thought I would post an update.

I was able to get it working from all the advise above. I only have it on the breadboard with short wires. I will test out again with long wires when I get a chance. I was also able to find an old copy of Gobetwino and trigger a batch file on a windows pc for data logging as well as SMS and Email notifications. I don't know Python to make my own program, so I went with good ole batch file  :) Please don't laugh!

My code below if anyone wants to use or tell me a better way to do it. I only wanted a single notification for each up and down, so I got as creative as a novice can get...

Code: [Select]
int NorthSump = 7;
int SouthSump = 6;
int HotWaterTank = 5;


void setup() {
pinMode(NorthSump,INPUT_PULLUP);
pinMode(SouthSump,INPUT_PULLUP);
pinMode(HotWaterTank,INPUT_PULLUP);
Serial.begin(9600);
}

void loop() {
 WaterSensors();
}

void WaterSensors() {
 static int ns1 = 0;
 static int ss1 = 0;
 static int hwt1 = 0;
 char buffer[3];
 int ns = digitalRead(NorthSump);
 int ss = digitalRead(SouthSump);
 int hwt = digitalRead(HotWaterTank);
 if ((ns == 1) && (ns1 == 0)) { Serial.println("#S|NSUP|[]#"); ns1 = 1; } // Float is up
 if ((ns == 0) && (ns1 == 1)) { Serial.println("#S|NSDWN|[]#"); ns1 = 0; } // Float is down
 if ((ss == 1) && (ss1 == 0)) { Serial.println("#S|SSUP|[]#"); ss1 = 1; } // Float is up
 if ((ss == 0) && (ss1 == 1)) { Serial.println("#S|SSDWN|[]#"); ss1 = 0; } // Float is down
 if ((hwt == 1) && (hwt1 == 0)) { Serial.println("#S|HWTWET|[]#"); hwt1 = 1; } // Sensor is wet
 if ((hwt == 0) && (hwt1 == 1)) { Serial.println("#S|HWTDRY|[]#"); hwt1 = 0; } // Sensor is dry
}


Since the package of float sensors contained (6) sensors I am going to put 2 floats in each sump. (1) will monitor the on/off cycles of the sump pumps and (1) will be the alarm for High water in the sump. I won't add those until the single float setup is installed and tested.

Thx,
Don