I am attempting to control the attached relay using Pin D1, with the VCC connected to 3V and ground to ground.
I am setting the D1 port high on setup, and then low to initiate.
My testing has proved that when I power the system through either the power adaptor in the diagram, or the USB power while connected to my laptop and running Arduino IDE and with the relay functionality disabled, it works. I can merrily swipe away and the code does it things and detects swipes and switches the LEDs accordingly.
When I enable the relay functionality and power the arduino through by computer, it works fine as well. I can hear the click as the relay is switched on or off, can repeatedly swipe on and off.
The moment I connect mains power through the relay, the system will swipe on AND THEN ACCEPT NO MORE SWIPES!
I have added a truth table to demonstrate
Arduino Power | Relay Connected | Result
-----------------+-----------------+--------
Computer | No | OK
Mains Adaptor | No | OK
Computer | 240V AC | HANG
Mains Adaptor | 240V AC | HANG
I have tried out 2 relays, so the component is not the issue. Is the general model of relay unsuitable for Arduino?
Is there some magic exception in electronics land that is causing this issue? The relay has no dip switches or jumpers, so I don't think it is configuration.
Why did you chose a 3v3 relay? A 5V relay could be fed directly from the adaptor.
What type of load is controlled by the relay?
Can you post a picture of your setup?
I use 3.3v for the relay because that’s the base voltage that Arduino ESP8266 serves best. (If I use 5V, I need a separate 5V power supply which means a bigger box which means retooling.) These configs already work, I have 5 other builds working using this plan.
What’s a “blynk sketch”? I have modified the code (1000+ lines) to use booleans for Wifi Functionality, Card Reader Functionality, and Relay function. it only stops working when 240v AC goes through the relay.
I see USB power, so why didn't you use a 5volt relay.
Trying to power a 3volt relay from the 3V3 pin of the ESP is asking for trouble.
A 3V relay coil draws more current than a 5volt relay, overloading the 3V3 regulator.
What are you switching. Did you use a suitable snubber circuit on the AC side.
Leo..
I am not using a snubber circuit on the other 5 boxes that use this configuration, as well as 3.3v across them. They all seem to work fine. When I use 5V on an ESP8266, it does bad things to the device, so I need a separate PSU for the 5V feed.
There is nothing connected to the other side of the power connection. I did try a column heater but that had the same result as when nothing was plugged in.
Have you tried a different make of relay module? It sounds rather like there is a problem with the module. I have found some makes of relay module are more reliable than others.
As I said it seems like the AC is interferring with the reader and/or D1 mini.
Leave the box open like you show and remove the AC adaptor and power everything from USB computer. Move all the AC wires away from the D1 mini.
Does it still fail?
The spark from a mechanical mains switching event can cause interference which could disrupt your controller. You could try a Solid State Relay to see if that cures the problem.
You might want to check how much current that relay module draws when the relay is energised. They can be as much as 50 or 100mA for a single relay. Some 3.3V microcontroller boards are fine with that much coming out of Vcc but yours might not be. Need to check the spec sheets.
Your 3.3v relay probably draws about 120mA via the internal regulator of the Wemos board. Much better, as already pointed out, would have been to use a 5v relay module powered from the 5v pin of the Wemos board.
However, this is probably not your main problem if, as you have implied, with no mains power to that box and powering the Wemos via a computer connected usb cable seems to show that the circuit including the relay functions as expected. When the box is shut, those signal wires to the RFID device appear to be in close contact to the mains wiring.