How can a reed switch and a mosfet be used to cut power to a microcontroller

Thread Starter

FranciscoB

Joined Feb 8, 2014
139
You were both right, thank you. I also re-positioned the reed switch to cut V+ instead of the path to ground and it already fulfilled its function. It's been working consistently for almost 3 weeks now, watering the plants twice a day. Now I can redo and shorten all that wiring.
 

Attachments

Thread Starter

FranciscoB

Joined Feb 8, 2014
139
After approximately 5 weeks of work without interruption, the reed switch stopped closing when a magnet was near it. After replacing the reed switch, the circuit worked normally again. I already ate the bell peppers, the switch fulfilled its task...
 

MisterBill2

Joined Jan 23, 2018
28,704
The reed switch might have just required a bit more magnetic flux, OR it may have simply failed. I suspect that some of them can fail if they are made of less durable materials. There is a small bit of flexing with every operation.
 

Thread Starter

FranciscoB

Joined Feb 8, 2014
139
Motivated by the previous success, I got a second water dispenser but this one has a different pcb.

The water dispenser works around a chip that handles charging; button press and enables a motor (M+ connects to said chip, M- to ground). One of the pins* of this IC is connected to gnd through a 2k resistor and a button; when the button is pressed once, the pin is pulled LOW and motor runs until the button is pressed again. Can I connect a gpio of my ESP32 in parallel to the button and use digitialwrite(10, LOW) to sink the current through the 2k resistor and enable the motor?

*When it's not doing anything, the pin measures 0.68V; after I press once, it stays at 2.68V until I press it again to shut the motor OFF.
 

Attachments

MisterBill2

Joined Jan 23, 2018
28,704
Another consideration is what the actual voltage and current that the reed switch was controlling, versus the actual specifications for that switch. There is a huge spread in reed switch specifications.
 

Thread Starter

FranciscoB

Joined Feb 8, 2014
139
Would using the same power supply make the optcoupler redundant because all GND would be tied together?

I think it would still protect the ESP32 gpio pin, no?
 

sghioto

Joined Dec 31, 2017
8,767
Would using the same power supply make the optcoupler redundant because all GND would be tied together?
I think it would still protect the ESP32 gpio pin, no?
Using the same power supply would be redundant. A GPIO pin configured as an output will have voltage on the pin when in the high state which is why I show a diode in series. I don't see any need for additional protection on the GPIO pin with the diode in series. The diode is the protection.
 
Last edited:

Thread Starter

FranciscoB

Joined Feb 8, 2014
139
I've decided to use the optocoupler together with:
Code:
void optoButton() {

  // Switch optocoupler to actuate the motor

  // pressing button to start the motor
  digitalWrite(10, HIGH);
  delay(500);
  digitalWrite(10, LOW);

  delay(20000); // let the motor run for 20 seconds

  // pressing button another time to turn off the motor
  digitalWrite(10, HIGH);
  delay(500);
  digitalWrite(10, LOW);
    
}
The ESP32 GPIO can only sink about 20mA, I'd rather not pull-down the FM5013 button pin through the ESP32. This way I use the usual digitalWrite every times the ESP wakes up from deepsleep.

It's been working steadily for the past couple of hours.
 

Attachments

Top