Wemos D1 mini 3.3V out to 5V out without level shifter

HI all!

I use a wemos D1 mini, and need to drive a laser. the laser's control board, takes an analog input signal (0-5V), but in my case it has to beither on or of.. so either 0 or 5V. The D1 mini has 3.3V on the pins..

I need to use what I have in house in order to be able to solve this as due to snow everything is blocked..

I have a ton of resistors with various values and the I have these:
cny74-4 (optocoupler)
CBC547B (transistor)
C556B (transistor)
IRF540N (mosfet)
IRF4905 (mosfet)

Is there a way to do this with these components? the output should simply be 0/5V, instead of 0/3.3V. if possible, then i'd prefer it not to be inverted.

Thank you very much!!

You have a 5V source available for the laser supply?
If so, you can use two transistors & three resistors.

I would give it a try with the BC547 and a resistor. You will need to calculate the resistor value.

Inversion can very easily be done in software.

#define LASER_ON LOW

...
...
// laser on
digitalWrite(laserPin, LASER_ON);
// laser off
digitalWrite)laserPin, !LASER_ON);

CrossRoads:
You have a 5V source available for the laser supply?
If so, you can use two transistors & three resistors.

thank you very much! so the CBC547B transistors should work well for this.. right? 2 more questions: dont I need a pull down resistor on the 3.3V pin? how can I calculate the proper values for the resistors?
Thank you very much!

I think you can do this with one NPN transistor while preserving the original polarity. I would have to draw it later today, but basically you connect the collector to the laser input along with a 10K pullup resistor to 5V. Then you connect the base through a 47K resistor to the 3.3V rail (not the 5V rail). And finally, connect the emitter to your GPIO pin.

When the GPIO pin is high, the BE differential is zero, so the transistor shuts off, which lets the 5V pullup resistor drive the laser. When the GPIO pin is low, the BE differential is 3.3V, so current will flow through the gate and the transistor will turn on. That grounds the laser input.

The idea is that while you can turn on an NPN transistor by increasing the base voltage with respect to the emitter, you can also turn it on by reducing the emitter voltage with respect to the base. You don't have any gain doing it that way, but all you're doing here is sinking half a milliamp through the 10K resistor, and the GPIO pin can easily do that without needing any gain.

This works for N-channel mosfets too.

thank you everybody! I am trying with the scatch above right now and trying to figure out the resistor values.. by googleing and trying some formuals I came to these values: R1 on the pin of the wemos 240 ohm, and both colletor resistors 4.7Kohm.

does that sound correct? can somebody confirm that these values wont damage anything?

thank you!

240Ω for base resistor sounds very low to me. I'm more thinking of something like 10k. You have the gain of the transistor so the base resistor can easily be 10x the value of the pull-up resistor.

You can make a single transistor level shifter as explained here:

Resistor values are not critical.

Mind, the ESP can source/sink only 8-10 mA on its pins, so a 240Ω resistor would overload it.

The base current is amplified by the transistor, so it only has to be a small fraction of the collector current. If you use 4.7K resistors on the collectors, 47k would be fine on the base. 240R would waste a lot of power for no benefit.

Anyway, here's a drawing of the circuit I suggested in reply #4. "3.3V means the 3.3V pin of the D1 Mini. "GPIO" means whatever digital output pin you are using.

ShermanP:
The base current is amplified by the transistor, so it only has to be a small fraction of the collector current. If you use 4.7K resistors on the collectors, 47k would be fine on the base. 240R would waste a lot of power for no benefit.

Anyway, here's a drawing of the circuit I suggested in reply #4. "3.3V means the 3.3V pin of the D1 Mini. "GPIO" means whatever digital output pin you are using.

Thank you,
just tested it and it kinda works.. 5V is ok, 0V not.. i have a voltage, as i see the laser turning on. I measured 0.11V there.. that is enough toleave marks on wood..

moreover, as long as the wemos is turned off, the laser is at full power..

Have you tried controlling the laser directly from the 3.3V GPIO port? Most 5V logic devices will see anything over 2.7V as a legitimate high.

If the single transistor sort of works, it is likely due to having the Vce of the NPN combining with voltage at the output of the D1 Mini to be a bit high.
With the dual transistor method I showed earlier, there is only the Vce of the transistor, which would be closer to 0V.

All depends on the transistor you use. I would expect ~ 0.7V or less depending on how much current flows.
With 10K pullup resistors and 1K between the uC and the first base, that would only be 0.5mA, so 0.7V would probably ne lower.
See the Vce sat #s on page 2

sharkyenergy:
Thank you,
just tested it and it kinda works.. 5V is ok, 0V not.. i have a voltage, as i see the laser turning on. I measured 0.11V there.. that is enough toleave marks on wood..

moreover, as long as the wemos is turned off, the laser is at full power..

Then you'll have to use the two-transistor solution. But if you still get voltage on the low end, try using one of the mosfets for the second transistor. It will probably bring the laser input closer to ground than a bipolar transistor.

sharkyenergy:
just tested it and it kinda works.. 5V is ok, 0V not.. i have a voltage, as i see the laser turning on. I measured 0.11V there.. that is enough toleave marks on wood..

moreover, as long as the wemos is turned off, the laser is at full power..

Makes me wonder: is that input really a digital (on/off) input? It sounds like the laser intensity depends on the voltage on that input.
Indeed typically <0.3*Vcc is seen as low by a digital input, that's <1.5V on a 5V input.
Do you have the data sheet of that laser control board?

Thanks to everyone for the answers! The laser has an analog input.. so the output power is proportional to the input tension. For my projevt i only need it to be either on or off, so either 0 or 5V. Will try tomorrow with the double transistor to see if it gets better. Thank you all

If you want true 0 or 5 V, you are far better off to use a logic gate such as two inverters in a 74HCT14. Basically, just about any basic HCMOS gate will give you the definite 5 V logic levels with a 3.3 V logic input.

Do you have a Relay handy?