Adding WiFi to my Keypad Lock

wvmarle:
You're missing a NOT there. The ESP needs peaks of 200 mA when transmitting on WiFi.

The peaks are momentary, a decent sized cap will take care of those. The average is around 80mA, so I think the Uno's 3.3V output should be fine, its rated at 150mA. This is not the case with Nano, by contrast.

Maybe something like this:


Notice, for Q2, I used a MOSFET -- Much better choice, in my opinion. Also, I left out the Flyback Diode, normally placed across the motor. The choice for Q2 will depend on the demands of that motor, but whatever MOSFET is used, must have a very low Gate Threshold voltage -- on the order of 2V or below. Or, some sort of Gate Driver will be needed. Why? Because, for the ESP8266, running at a mere 3.3V, will only be able to apply around 3.3 - 0.7 ≈ 2.6V because of the 1N914 diode drop.

GPIO2, via Q1, is for locking out control from the Arduino. When GPIO2 goes HIGH, it causes Q1 to clamp Q2's gate LOW. When that happens, nothing the Arduino throws at the gate will change that LOW condition. When GPIO2 is LOW, Q1 becomes a high impedance path, which allows both the Arduino and the ESP8266, to control the motor.

C1 supplies supplemental current during WiFi transmit bursts. The value may need to be adjusted, depending on actual conditions. I figured on 3mS bursts of 200mA, causing an approximate 130mV droop -- using a back-of-envelop calculation:

[b]C1[/b] = IT/V = 200mA * 3mS / 0.13V = [b]4615µF[/b] -- so, you know... 4700µF :wink:

The voltage of C1 depends on what voltage is supplied to the Arduino Vin pin.

If Q2 needs to be some mega-current handling beast [with a very high Gate Capacitance], then, the values of R2 & R3 may need to be lowered to something more like 10k or even, heck, 1k ['cuz the those outputs can take it, after all]. Tweak as needed :wink:

I suppose you're adding C1 to help the ESP? Then you should add it across the Vcc and GND pins of the ESP. Not the Vin of the Arduino (which you shouldn't be using in the first place).

Normal value for this capacitor is 100 µF.

3.3V from ESP8266 thru a diode will leave a very low level drive a MOSFET gate. Going to be tricky to find one that will turn full on with that low a gate voltage. Using a schottky diode well help, dropping the diode loss to 0.45V or lower. 20K will also drop voltage, change that to something much lower to charge the MOSFET gate capacitance and allow faster turn on & turn off.

Why not have the ESP8266 talk to the arduino let the Arduino drive MOSFET? AOD514 is a good N-channel MOSFET, very low Rds with Vgs of 4.5V and high current capable.

Or better: have both devices drive an NPN transistor each to pull the gate a P-channel MOSFET low to turn it on and source current to the load, vs sinking current from the load.

ReverseEMF:
Maybe something like this:

Thank you so much for taking the time and effort to draw this amazing schematic for me. I really admire your kill switch solution especially. Though I can understand most of the schematic, I have a few doubts. Kindly explain these to me:

-Why are we connecting D1 and D2 to ground also? I have always connected the GPIO pin only to the gate.
-What is the purpose of R2?

Also, won't Q2 be a overkill? I want to operate a 12V Solenoid Lock needing 400mA. Will a 2N2222A suffice?

Sorry if my doubts are too silly. Again, thanks a ton.

livelongpranav:
Kindly explain these to me:

-Why are we connecting D1 and D2 to ground also? I have always connected the GPIO pin only to the gate.

Not sure what you mean by connecting D1 and D2 to ground -- they're not connected to ground. The diodes function as an OR-gate.

livelongpranav:
-What is the purpose of R2?

Without R2, Q2's Gate would always be either 3.3V-VD2 or 5.0V-VD1. In other words, there would be nothing to pull the Gate to ground, so Q2 would never turn off. So, R2 is a Pull Down Resistor.

livelongpranav:
Also, won't Q2 be a overkill? I want to operate a 12V Solenoid Lock needing 400mA. Will a 2N2222A suffice?

Sounds like you're assuming there's no such thing as a low-power MOSFET. But, you hadn't given us any actual numbers, so I wasn't sure what we were dealing with :wink: So, now that I know -- yeah, it sounds like a 2N2222A would suffice. And, in fact, it would be easier for the ESP8266 to drive a bipolar transistor, in this case, as CrossRoads pointed out. But, here is, in fact, a MOSFET that should easily do the job: FDV303N

CrossRoads:
Why not have the ESP8266 talk to the arduino let the Arduino drive MOSFET? AOD514 is a good N-channel MOSFET, very low Rds with Vgs of 4.5V and high current capable.

Because the OP specified that the Arduino code not be touched.

ReverseEMF:
But, here is, in fact, a MOSFET that should easily do the job: FDV303N

I'm not too sure about that... the datasheet does give an on resistance for Vgs = 2.5V=2.7V (so that covers the ESP w/diode), but with a current of just 0.2A. OP wants 0.4A.

The PMV16XN will definitely do the job. It's fully on (for a load of 2.1A) at Vgs = 1.8V, or 6A at Vgs = 2.5V. Arguably a bit overkill but it's an inexpensive part nonetheless.

wvmarle:
I'm not too sure about that... the datasheet does give an on resistance for Vgs = 2.5V=2.7V (so that covers the ESP w/diode), but with a current of just 0.2A. OP wants 0.4A.

The PMV16XN will definitely do the job. It's fully on (for a load of 2.1A) at Vgs = 1.8V, or 6A at Vgs = 2.5V. Arguably a bit overkill but it's an inexpensive part nonetheless.

Yeah, you're right -- I missed that.

What happens when the battery gets weak and
cannot run the motor? Can the door still be opened?
Herb

ReverseEMF:
Not sure what you mean by connecting D1 and D2 to ground -- they're not connected to ground. The diodes function as an OR-gate.
Without R2, Q2's Gate would always be either 3.3V-VD2 or 5.0V-VD1. In other words, there would be nothing to pull the Gate to ground, so Q2 would never turn off. So, R2 is a Pull Down Resistor.FDV303N

In the schematic, D1 and D2 are connected to the gate via R3, which I understand. But why are they both connected to ground via R2, as I can see in the schematic? I've never used pull down resistors before. I have always connected GPIO to base/gate via a resistor on the base.

Thanks.

That's because this is a MOSFET (voltage driven), not a BJT (current driven).

When both inputs are grounded the diodes prevent the gate from being pulled low as well. That's what that resistor does for you.

herbschwarz:
What happens when the battery gets weak and
cannot run the motor? Can the door still be opened?
Herb

Yes. I have designed the circuit so that apart from the 9V battery pack inside there is a battery connector outside also. And a power switch for the battery is also outside. So in case the battery is dead, just switch off the battery, put another one from outside, open the door and replace the battery.

I've connected both batteries to the same slot on the power supply though, which will give me 3.3v and 5v. Is this okay? Or is there a better way to connect a backup battery?

9V batteries, if you mean PP3 size, are a poor choice for any Arduino circuit. I am surprised that it has the strength to move the solenoid!

A better choice would be 4xAA NiMh cells. You can connect them to the 5V pin on the Uno, instead of the Vin pin. If you don't have NiMh cells and a charger, please get them, but if you insist in using non-rechargeable AA cells, use 3x not 4x.

PaulRB:
9V batteries, if you mean PP3 size, are a poor choice for any Arduino circuit. I am surprised that it has the strength to move the solenoid!

A better choice would be 4xAA NiMh cells. You can connect them to the 5V pin on the Uno, instead of the Vin pin. If you don't have NiMh cells and a charger, please get them, but if you insist in using non-rechargeable AA cells, use 3x not 4x.

Thanks for your suggestions.

I would be using 6xAA batteries to get 9V. For the backup connector outside, I'll use a PP3 though.
Won't 3x be 4.5v, less than the arduino requires? I would have used 4x but the solenoid needs 12v and it would be easier to boost 9v to 12v, or will 4x do?
I'll see if I can get NiMh cells.
Maybe I'll get a 5V solenoid.

pranavmittal611:
I would be using 6xAA batteries to get 9V. For the backup connector outside, I'll use a PP3 though.

Do check whether that can actually activate your solenoid.

Won't 3x be 4.5v, less than the arduino requires?

It'll do just fine at that voltage at 16 MHz. When full alkaline batteries are about 1.6V each, most of their life 1.3-1.5V, when pretty much drained down to 1.1-1.2V.

Actually an 8 MHz Pro Mini runs just fine on two AA batteries... even if they're down to 2.4V. You'll anyway have to go for a Pro Mini or so, or you can never get somewhat decent battery life.

Indeed, do get a 5V solenoid instead. Makes life a lot easier.

wvmarle:
Indeed, do get a 5V solenoid instead. Makes life a lot easier.

But, consider that a 5V solenoid will require more current [something like twice as much], to achieve the same pull force. So, if the 12V solenoid you are currently using, is at, or near, the edge of adequate, then, a 5V solenoid will, likely, demand too much current for an Arduino output pin. In which case, you would still need a driver.

Also, from the seat of my pants comes an aversion to driving anything inductive, directly from an MCU output -- even with flyback protection. I like the idea of a buffer between such evil, and my precious MCU. Just a superstition :wink:

gollum_animated_03_244x300.gif

gollum_animated_03_244x300.gif

Of course, a 5V one needs more current, but as it's a solenoid I assume it needs a driver anyway. Just one voltage less to deal with, that's always a plus.

wvmarle:
Of course, a 5V one needs more current, but as it's a solenoid I assume it needs a driver anyway. Just one voltage less to deal with, that's always a plus.

Ahhhh...I get it :wink: