I'm making a PCB for automatic dispenser and use Wemos D1 R2 as the microcontroller. The microcontroller works fine with the code and if I supply 12V to the microcontroller first then put it on the PCB they work fine too. But if I put the microcontroller on the PCB first then supply 12V to them, the don't work. What's happening? Why they couldn't work?
Is there any way to make them work without modifying my PCB?
We know nothing about this PCB, nothing about your code, and nothing about how you have the Wemos setup when it's off this mystery PCB - so impossible to say what's going on!
What investigation/testing/debugging have you done?
You say the Wemos works off the board: so take measurements in the "working" state, and corresponding measurement in the "non-working" state (on the PCB) - compare & contrast ...
The PCB consist relay module. The code only consist digitalwrite high and low for pin D3 and nothing else.
Without PCB, the microcontroller works fine, then while it's on and working, I put the microcontroller on the PCB and they work fine too (state 1).
But, if I put the microcontroller while it's off to the PCB and turning on both of them together, they won't work (state 2).
In state 1, pin D3 could go around 3.3V for HIGH and around 0V for LOW
In state 2, pin D3 only staying at 1,...V and not going HIGH or LOW
Maybe there's some "interference" with the boot pins. If they're pulled-down at boot then it's stuffed.
That would explain why it would be ok if powered and then mated to the relay board.
Remove the 10k resistors, I'd say, and it will likely come right.
The boot pins are D0, 3, 4, 8, rx, tx (a.k.a. GPIO 0, 2, 15, 3, 1)
PE ─ After further consideration - the transistor (B-E) will still "pull down" a boot pin too.
Which outputs have relay circuits? Post Your Code.
Alias for GPIO 0 & 2, so yes, they can not be pulled LOW at boot or the ESP will go into an alternate boot mode. and the transistor pulls them LOW.
Basically those pins are not suitable to drive an NPN transistor.
RX is not a boot pin, it can be pulled LOW or HIGH at boot without issue D8 / GPIO 15 should not be pulled HIGH.
Go for the end of the resistor that goes to the GPIO pin, so you could connect that end to a different pin to make it work.
I suspect through the VIN pin, but without the full schematic this is guess work.
D2 and D3 have 10K pull-ups on the WEMOS-D1 board and D8 has a 10K pull-down.
You have D2 and D3 connected to a 1K and 10K to ground and D8 connected to a pullup to 5V, that will keep the WEMOS-D1 from booting.
Design a board to go between the two that has a PCF8574 (I2C I/O expander).
D1, D2 are there and waiting.
An opportunity to free the 8266ers from the boot pin curse.
It's a trap, not really a curse. Actually just a simple TTL buffer or inverter is fine.
Other issue is that some pins go HIGH momentarily during Boot as well, which can be seriously disturbing.
Your suggestion is almost right. The 1k isn't really the problem, but maybe it's affected by them too. But, the real problem is the D8 pin.
You said that "The boot pins are D0, 3, 4, 8, rx, tx (a.k.a. GPIO 0, 2, 15, 3, 1) PE ─ After further consideration - the transistor (B-E) will still "pull down" a boot pin too.
Which outputs have relay circuits? Post Your Code."
D8 isn't output and I make it as an input for DS18B20. I connect the D8 with 5V through 4.7k ohm resistor and that's the problem.
I tried your suggestion to remove the 10k ohm from D3 and D4 but it still won't work. Then I tried to remove the 4.7k ohm from D8 like I said before. Then it works.
But now I'm confused to put my DS18B20 to which pin as input pin. Do you have any suggestion?
The jack on PCB connects to VIN of microcontroller. This means plugging through the microcontroller jack or plugging through the PCB's jack are the same things. Well there's no difference that occurred.