Circuit not performing as expected. Solenoid, level switches, MOSFET, LCD

Hello all,

Wanted to reach out to you guys because I have; what is likely a very normal small circuit phenomenon that I just don't know enough about I guess.

PROJECT OUTLINE
Using a solenoid, and two float switches; determine fluid position/and fill-state of solenoid adjusting state as needed. LCD merely displays debug info.

PROBLEM STATEMENT
(fried mosfet? controller?)
*3 (30 minute) durability tests were ran on the circuit last night to ensure the device didn't overheat or fail during normal operation. Normal operating time (for solenoid open) is about 7 minutes. The device completed 3 test perfectly. After this I moved it into service and connected everything. During its first operational fill, something went wrong- the LCD froze (likely whole microcontroller), and the MOSFET was now stuck in always-on state. Regardless of program (state).

(arduino boot hang)
A odd side-affect of this (or an issue I never noticed before). If the arduino is turned on with one of the float switches "open", the arduino flat-out wont boot. If I move the switch to "closed" it boots fine. I've noticed the float that causes this is using the same pin that is tied to the arduino LED. If I disconnect the floats completely the arduino starts up fine.

PARTS
Floats (I believe hall variant?- works well as digital-in)

MOSFET

BATTERLY ELIMINATION CIRCUIT

SOLENOID

OLED

ADRUINO- FEATHER M0 ADALOGGER

SCHEMATIC

SEE PAINT ATTACHMENT

NORMAL OPERATION

I plan to post the program tonight... but first ill give some basic explanation of what it does.

1)Level sensors are monitored for a change in state. A changed state is represented of being one value for more than 5 seconds.

2)Logic decides what state the device is in. Both sensors being closed means we're in "full state". Upper sensor open with lower sensor closed, AND solenoid open is "filling" state. Both sensors open is "empty" state. Upper sensor open with lower sensor closed, AND solenoid closed is "draining" state.

3)State change looks at current sensors, current state and decides if a change is needed.

-a change to full state shuts off the solenoid
-a change to empty state turns on the solenoid

4)Solenoid is open or closed based on state - information is relayed back to LCD

CLOSING STATEMENT

The device was working great up until whatever happened to it. Its possible the boot issue existed and i'm just now catching it... but I don't know I tested it beforehand. I think i'm missing some pull-ups and maybe a diode in there over the coil. I wish I knew just a little bit more (seems this is enough to be dangerous) but I will learn from this with some help from one of you circuit guru's!

PS- I've put 100 hours into getting this thing right- from plumbing to 3d printing on this one... if I have to hire someone to get me right- I will totally do that... just point me in the right direction of the person or lesson learned :slight_smile:

Do you have a flyback diode across the solenoid? It is important that you do.

Did you enable the internal pullups on the switches or provide external pullups? You need to do one or the other.

That is not a schematic. It is a diagram. It lacks the details that a schematic would have.

Schematics for new users.

groundFungus:
Do you have a flyback diode across the solenoid? It is important that you do.

Did you enable the internal pullups on the switches or provide external pullups? You need to do one or the other.

That is not a schematic. It is a diagram. It lacks the details that a schematic would have.

Schematics for new users.

Do you have a flyback diode across the solenoid? It is important that you do.
I do not. - I don't know why it didn't make it from the original design to my soldered version but this was overlooked. Could this have prevented the FET from frying? I am assuming I fried the FET since its it seems to be stuck at full output.
Side-question - does a coil care of polarity? It didn't seem to affect the operation of it so I assumed it did not.
Did you enable the internal pullups on the switches or provide external pullups?

I was just reading this on adafruits page

Pin Outputs & Pullups
The old-style way of turning on a pin as an input with a pullup is to use

pinMode(pin, INPUT)
digitalWrite(pin, HIGH)

This is because the pullup-selection register on 8-bit AVR chips is the same as the output-selection register.
For M0 & M4 boards, you can't do this anymore! Instead, use:

pinMode(pin, INPUT_PULLUP)

So maybe I'm not using any pullup at all either...? I will double check the code but my guess is I am not calling the pullup. Can I use the internal pullup on more than one pin? This is where I'm really light on knowledge. If external is the way to go what size would I consider?

That is not a schematic. It is a diagram. It lacks the details that a schematic would have.

Fair enough. Are we missing any details that would aid in the diagnosis of this problem? Surely I will add them.

Could this have prevented the FET from frying?

That is what the diode is there for, to absorb the high voltage back EMF when the solenoid is powered off.

Each pin that has a switch connected should have its internal pullup enabled. The internal pullups should be enough for a switch that is close to the processor. Longer wires to the switches call for lower value pullups. I start at 10K and go down until I get reliable operation. Not lower than 1K, though. For longer wires a 0.1uF cap across the switch can help with noise induced false indications. The modern way to enable the internal pullups is:

pinMode(pin, INPUT_PULLUP);

does a coil care of polarity?

In this case, no.

groundFungus:
That is what the diode is there for, to absorb the high voltage back EMF when the solenoid is powered off.

Each pin that has a switch connected should have its internal pullup enabled. The internal pullups should be enough for a switch that is close to the processor. Longer wires to the switches call for lower value pullups. I start at 10K and go down until I get reliable operation. Not lower than 1K, though. For longer wires a 0.1uF cap across the switch can help with noise induced false indications. The modern way to enable the internal pullups is:

pinMode(pin, INPUT_PULLUP);

In this case, no.

Alrighty. I have a spare FET I will wire in. I'll add the diodes over the fan and the solenoid. Ill change the program to include the internal pullups. My sensors have exactly 50ft of wire round-trip. 25ft to and back. Is the 10k internal still fine for this?

One last thing. The boot issue. That wouldn't be caused by no pull-up right? It could be due to the damaged fet bleeding something off to ground. I read somewhere, pins(maybe a certain pin) pulled low on boot could hang a boot.

"Since the pin 13 LED is used as an indicator during boot, a short to ground when the processor is trying to drive the pin HIGH could cause power problems and interfere with the boot."

Simple solution to simply use a different pin?

Circuit has resumed functioning as expected.

**Known Fixes **

  • Replacing the FET fixed the always on condition- so yeah I fried that thing.
  • Cant pull pin 13 low on feather M0 during boot. Works fine after boot. (same as LED- during boot it is driven HIGH to flash LED) Simply used another pin (10 in this case)
  • Adding flyback diodes (the one suggested) on both fan and solenoid.

Program was already using internal pullup on both pins so this was not a factor.

Thank you groundFungus for taking a look!

-PS a little context. This controls the fill rate of my saltwater fishtank. Since I use RO water its typically controlled manually by a valve. Forgetful me floods the basement regularly forgetting to shut this valve off. This is a perfect solution for me and its important it works properly :slight_smile: