WeMos D1 pin output only 3v (not 5v)

The sketch below (using a WeMos D1 WiFi board) blinks one LED when connecting, and I can use my iPhone to turn the LED ON/OFF via WiFi…..works perfectly.

I now want to replace the LED with a relay (SRD-06VDC-SL-C) so as to turn on a Lamp (for example) from my iPhone.

My problem is that the voltage output on Pin 7 is only 3 vdc and the relay needs minimum of about 4.5 vdc. So when the WeMos board sends a signal to the relay, it is too low of a voltage to trigger the relay.

FYI: Power to WeMos board is via USB. Wiring is just Jumper GRD to relay and Pin 7 to relay, and used “LOLIN(WEMOS) D1 R2 & mini” board from Tools’ the pull-down menu

As a newbie to Arduino (January) I've tried the following:

  1. Re-checked my wiring to/from the relay

  2. Changed sketch to various other Pin numbers (still 3 vdc)

  3. Used another (identical) WeMos board and also changed Pin numbers (still 3 vdc)

  4. I then wrote a simple sketch to have a standard UNO board turn on an LED. And the output of UNO board pin was 5 vdc (which is what I thought HIGH on a pin should be).

  5. Just to verify the relay is working, using the UNO board, I switched from an LED to the relay. The relay worked perfectly.

  6. As a last resort, I tried using a mini-WeMos D1 WiFi board….same 3 vdc output

  7. Oh…one other thing. For the heck of it, I removed the USB and connected a standard wall cube (ac/dc converter) to the WeMos board. It worked just as above with only 3 vdc output to the pin. (I assumed this would have no effect, since the board has two internal voltage regulators 3.3 and 5 , but I just wanted to eliminate the USB connection as a problem source.

Could someone let me know if my Sketch below is causing the WeMos board to limit it’s pin-ouput to 3 vdc. Alternatively, if my Sketch is OK, does anyone have any idea how I can get a 5 vdc output from a Pin.

Thank You.

#include <ESP8266WebServer.h>
#include <ESP8266WiFi.h>
const char* ssid = "my_SSID";
const char* password = "my_PASSWORD";

int ledPin = D7;  // later I will rename this to..... relayPin)
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  Serial.println();
  Serial.println("LedPin ");
  Serial.println(ledPin);
  // Connect to WiFi network
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL : ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

}
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  while (!client.available()) {
    delay(1);
  }

  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  // Match the request

  int value = LOW;
  if (request.indexOf("/LED=ON") != -1) {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED=OFF") != -1) {
    digitalWrite(ledPin, LOW);
    value = LOW;
  }



  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");

  client.print("The LED pin is now: ");

  if (value == HIGH) {
    client.print("On");
  } else {
    client.print("Off");
  }
  client.println("<br><br>");
  client.println("Click <a href=\"/LED=ON\">here</a> Turn LED ON<br>");   //THIS APPEARS ON iPHONE
  client.println("<br><br>");
  client.println("Click <a href=\"/LED=OFF\">here</a> Turn LED OFF<br>"); //THIS APPEARS ON iPHONE
  client.println("</html>");

  delay(1);
  Serial.println("Client disconnected");
  Serial.println("");

}

An ESP8266 is a 3.3V device. An ESP8266 is not a 5V device.

I use opto-isolated relay modules to operate relays by an ESP32, also a 3.3V thing.

A ESP cannot directly drive a relay coil without supporting components.

What current does that relay need? If I got the proper figures it is 71 mA, way too much for any controller. Get a relay board that contains the driver.

Need to understand a lot about Ohm's law, voltage, current, and datasheets. :astonished:

There are special single relay shields that plug straight onto a WeMos D1 mini.
Do a search on ebay.
Leo..

Guys, thanks for ALL the inputs.

My bad !!! (I’m sorta’ embarrassed)

Here’s all the things I “didn’t know”…..but are now trying to better understand:

a) the standard output of WemosD1 ( ie: ESP units) is 3.3vdc (I assumed it was 5vdc like the UNO.

b) the WeMosD1 max mA per pin or mA per board. (…I’ve been googling and found conflicting values).

c) the 6vdc relay I have is 60mA (and for the 5vdc version, it’s 71.4mA

d) an ESP cannot drive a relay without “supporting components” (…like an optocoupler.

(and I now know that an UNO cannot either….)

e) what an optocoupler was…now I do

f) that there are relay modules that have the optocoupler and supporting components

I’m trying guys, really.

This forum has helped me get started with Arduino since January and I do appreciate your collective expertise and the time you spend to help total strangers.

I’ve just ordered a 5vdc Songle relay “module” from ebay so as to be used with my WeMosD1 (USA! 5 PCS - 5 VDC - 1 CHANNEL HIGH/LOW LEVEL INPUT, OPTO RELAY BOARD NEW! | eBay)

FYI, I had bought my existing 6vdc relay (which I’ve never used) over a year ago in “anticipation” of someday using it to turn AC devices on/off and, at that time, I had never even heard of Arduino.

So, just one more thing please. If someday I want to use my existing 6vdc relay, is there a simple device (or board) they sell to make it useable with my UNO and WeMosD1

(sorry guys….this may be another of my newbie, 78yr old embarrassing questions.....I tried to google this, but was unable to find something....mostly because I didn't know the right terminology fo such an interface component)

Thanks

:frowning:
As I said, there are relay modules designed for the WeMos D1 mini.
Leo..

Edit.
Just saw on your cross-post (same topic) that you are using a WeMos D1, not a WeMos D1 mini.
So the advice given doesn't work.
A D1 mini and the above module would be easier though.

Yeah, any logic level mosfet will pretty much do OK. You also need a small signal diode; something like 1n4148 (very common type) does fine. Most likely the relay will even work at 5VDC; if it doesn't, you need a 6V power supply of some sorts; again, that doesn't have to be complicated/expensive. That's 2 discrete components and 1 power supply module; that's all.

Well, we know from the datasheet that there is a 6 V version of the relay, but how you managed to purchase one of those instead of the more common 5 V version is quite fascinating! :astonished:

Even a 2N7000 which may be fairly available where you bought the relay. :grin:

Hi @seniorcitizenhere,
I had the same issue with Wemos controlling 5V logic devices (like a servo PWM pin, for instance) and this article helped me a lot: Servo motor interfaced with nodemcu esp8266 12e: Controlling servo motor over WiFi
There is a schematic using 2N3904 NPN transistors and it can be used for almost any device you want to connect to your esp8266 pins (of course, up to 200mA). Using that schematic will also allow you to use the PWM function on that pins, too. If you want more power, you could just go with 2N2222 and you'll be able to power-up up to 600mA devices.
Cheers!

Will probably work for a servo and may be appropriate where you require more than 30 mA to operate the device, but very clumsy in general and inappropriate (ineffective) for high speed signals.


For controlling a logic device - such as a NeoPixel string - it is better to use a purpose-designed IC such as the 74HCT14 Hex inverter.

Just as that circuit above uses two transistors to invert twice, you use two inverters of the 74HCT14 cascaded. And you then have three such level converters available. The inputs of the unused gates should be grounded.

I used a wemos d1 mini to control a solid State Relay similar to the ones in the link below. I am controlling it directly with the wemos board. No mosfets or optocouplers additional needed. Connect Ground to one side of SSR and the pin that will go high/low when triggered the other input side of the SSR. If I understand correctly it already has the optocoupler built in (3v will activate relay).

I am not sure what you are controlling (AC/DC) or how many amps are needed. You will need to select the appropriate relay for your application.

SSR-40DD Solid State Relay DC to DC (Input 3-32V DC Output 5-60V DC) with Heat Sink, 40A: Amazon.com: Industrial & Scientific

Good Luck!

One would certainly hope they are not required as the SSR is specified as "3 to 32 V" control input. Hopefully the current required to control it is well within the drive capability of the D1 Mini, just a few milliamps.

That is an obligatory part of a SSR. :grin:

Both, 2N3904 and 2N2222A operate at 300MHz. Isn't this high-speed enough? It's actually double the speed of ESP8266. So, their speed is more than you actually need.
For the Neopixel use-case, I agree with you that is better to use a level-shifter, instead of using tons of transistors and resistors. But because of the space on a PCB/protoboard, not speed.

Complete nonsense! :roll_eyes:

They do not "operate" at 300 MHz at all.

You are quoting their notional "fT" or gain-bandwidth product. Essentially this is the frequency at which they definitely do not amplify at all. At one third of that frequency, they have a notional gain of three. Frankly, just how useful is a gain of three? :face_with_raised_eyebrow:

So you demonstrate you do not know about gain-bandwidth product. Do you know what "saturation" is?

@Paul_B,
You can imagine that, if I used the schematic from a blog, I do not know too much about electronics. Now, since I saw that trick, after I read the characteristics of those transistors, I though that the transition frequency is the frequency I can command that transistor.
Anyway, speaking of PWM signal, knowing that the maximum frequency of a PWM signal is 40kHz in case of ESP8266, can those transistors shift the 3.3V PWM signal to a higher voltage signal? Of course using an external power supply for them.
Is there a formula that we can apply to find the maximum frequency they can be used efficiently?

At 40 kHz - maybe, maybe not. :grin:

I learnt about saturation back in the early '70s IIRC. The transistors can amplify linearly up to a very high frequency (potentially tens of MHz) but if saturated, will take several microseconds to switch off. For digital logic operation, you want them to switch positively on and off; there are ways of doing this which were designed into the now essentially obsolete 7400 and 74LS00 logic IC series.

For driving servos where you are using sub-kilohertz frequencies, the simple transistor circuit will generally work just fine, but once you approach digital logic frequencies, you are advised to use logic ICs (HCMOS) designed for the purpose. :face_with_raised_eyebrow: