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:
-
Re-checked my wiring to/from the relay
-
Changed sketch to various other Pin numbers (still 3 vdc)
-
Used another (identical) WeMos board and also changed Pin numbers (still 3 vdc)
-
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).
-
Just to verify the relay is working, using the UNO board, I switched from an LED to the relay. The relay worked perfectly.
-
As a last resort, I tried using a mini-WeMos D1 WiFi board….same 3 vdc output
-
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("");
}
