Adding WiFi to my Keypad Lock

Hello, amazing people.

I'm a really passionate beginner with arduino and electronics and I've built a Keypad lock for my room's door (inside the house).

I've used an arduino that activates a motor using a transistor to open the door if the correct pin is entered.

I want to add wifi control to my project. I have a few transistors, relays and ESP01s lying around for the upgrade. I want to use the blynk app and use the ESP01 independently without disturbing or modifying the arduino code. I'll program the ESP01

These are my requirements:
-A failsafe so I can open the lock via blynk if I forget the pin
-A kill switch that will turn off the arduino if I suspect somebody knows my PIN.

These are my ideas:
-Can I directly connect an ESP GPIO pin to the base of the transistor where the arduino is connected? By doing this can I control the transistor to switch the motor via both the arduino and the Esp01?
-Can I put a relay module between the arduino and the battery pack and connect it to the ESP? I will connect the relay so that it will disconnect power to the arduino only when powered on. Is this a viable solution for a kill switch?

Any suggestions and ideas about how to go about this will be highly appreciated.

Esp-01 has 2 pins. You could disconnect the wire from the other Arduino to the transistor and connect it to the esp as an input. Then connect the other esp pin to the transistor. Then you can code the esp to activate the transistor when it gets a signal from the other arduino, or to ignore that signal if required. And, of course, it can activate the transistor itself.

However, there are some problems using esp-01 that you must understand. I will assume your other arduino is an Uno as you forgot to tell us. Firstly, Uno outputs are 5V, esp pins are 3.3V. To connect the Uno output to the esp, you must reduce the voltage down to 3.3V or the esp could be damaged. A voltage divider consisting of two resistors will do this. Secondly, the esp outputs are 3.3V and cannot source very much current compared to Uno pins. If you give a schematic of the circuit and component details, we can advise if the esp output can drive the transistor or if that part of the circuit needs to be adapted. Thirdly, the 3.3V output of the Uno is powerful enough to power the esp, which requires 80mA. You may need a separate 3.3V regulator for the esp if you are not using an Uno.

PaulRB:
Thirdly, the 3.3V output of the Uno is powerful enough to power the esp, which requires 80mA.

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

PaulRB:
Esp-01 has 2 pins. You could disconnect the wire from the other Arduino to the transistor and connect it to the esp as an input. Then connect the other esp pin to the transistor. Then you can code the esp to activate the transistor when it gets a signal from the other arduino, or to ignore that signal if required. And, of course, it can activate the transistor itself.

Thank you so much for your suggestion. Why didn't I think of that before! I'll surely do that, saving the hassle of using a relay.

I'm using an Arduino Uno and will power the ESP using a buck converter directly from the battery pack.

Also, I'm a total beginner to ESP and Arduino coding, can you tell me about how to code the ESP to do the following:
-Activate transistor on receiving signal from Arduino
-Ignoring that signal if told to, via Blynk
-Activating the transistor directly if told to, via Blynk

It'll be great if you can share with me any tutorials and learning resources.

ESP beginner's guide

The ESP01 has four GPIO pins available: GPIO0, 1, 2, and 3.
GPIO0 and 2 are involved in the boot process so you have to be very careful at what you attach to them, or you may not be able to boot. GPIO 1 and 3 are the Serial interface; if that's not used these pins are perfectly usable as general I/O pins. In fact that'd be the pins I'd be looking at first for this project (this in contrast to an Arduino where RX/TX are the last to be employed).
Do get one of those convenient ESP01 USB programmers; build a small PCB (perfboard) with 2x4 connector to plug in your ESP01 for permanent installation.

wvmarle:
Do get one of those convenient ESP01 USB programmers; build a small PCB (perfboard) with 2x4 connector to plug in your ESP01 for permanent installation.

Or just use the ESP01 programmer, as it has a regulator on board to power from 5 V if you use a "phone charger".

There is one of those sitting in my office just as a joke, programmed as the captive portal for people who get curious. Just the Phone charger (no cord) with the adapter and ESP-01 plugged in. But I use another in my "times square display" with a strip of eight MAX7219 modules.

This requires an added link to program.


This includes the programming switch.

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.