1

I am brand new to Arduino. So I apologize in advance if I have missed the information I am looking for. I have looked for hours and cannot find any help with a Adafruit Featherwing Latching Relay(#2923 on Adafruit). This is the one that has 2 set pins "Set" & "Unset". I would love to use a Wemos d1 mini to trigger this relay. But I cannot find any sketchs or documentation on how to get started.

Ideally the setup would have a push button to toggle between states as well as the basic esp8266 web page to toggle state as well.

I am just trying to turn off/on some LEDs. And want to run the switch via this setup.

Thanks E

Well I am further along. I was able to get most of this working but now the CSS i am using is causing headaches. The code below errors on "page = <style......" the html

//the HTML of the web page

page = "<style> .button{ background-color:red; color:blue; border-radius: 8px; padding: 12px 24px; }</style><h1>Simple NodeMCU Web Server</h1><p> <a href="LEDOn"><button class="button">ON</button></a> &nbsp; <a href="LEDOff"><button>OFF</button></a></p>";

I get the error 'inconsistent user-defined literal suffixes 'LEDOn' and 'button' in string literal'

Any help would most appreciated. This line is the only one failing in my sketch

1
  • Please ask a new question for a new question rather than globbing it onto an existing one, particularly when it regards a completely separate topic. If you're having code issues including the code would be... helpful. Jun 17 '21 at 0:01
1

I will add the final code here. It took me weeks to find a starting place and many hours of trial and error to sort it all out. With help I was able to get a stable working switch.

This code was written for a Wemos D1 Mini coupled to a Adafruit Featherwing Latching relay. Since it has Set and Unset pins coding this was struggle for me. The Set/Unset pins only require a pulse to trigger them then they stay 'Latched' in state. even if power is lost. I found the base code here and it took a bit of tweaking to get it to work.

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

// Replace with your network credentials
const char* ssid = "SSID";
const char* password = "PASSWORD";

ESP8266WebServer server(80);   //instantiate server at port 80 (http port)

String page = "";
int LEDUnsetPin = D1;
int LEDSetPin = D2;
void setup(void){
 //the HTML of the web page
 //don’t forget you need estapes (") around the quotes
 page = "<style>  .button{    background-color:red;    color:blue;    border-radius: 8px;    padding: 12px 24px;  }</style><h1>Kitchen LEDs</h1><p>    <a href=\"LEDOn\"><button class=\"button\">ON</button></a>    &nbsp;    <a href=\"LEDOff\"><button>OFF</button></a></p>";
 //make the LED pins output and initially turned off
 pinMode(LEDUnsetPin, OUTPUT);
 digitalWrite(LEDUnsetPin, LOW);
 pinMode(LEDSetPin, OUTPUT);
 digitalWrite(LEDSetPin, LOW);

 delay(1000);
 Serial.begin(115200);
 WiFi.begin(ssid, password); //begin WiFi connection
 Serial.println("");

 // Wait for connection
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
 Serial.println("");
 Serial.print("Connected to ");
 Serial.println(ssid);
 Serial.print("IP address: ");
 Serial.println(WiFi.localIP());

 server.on("/", [](){
   server.send(200, "text/html", page);
 });

 //turn on the on pin and turn off the off pin
 server.on("/LEDOn", [](){
   server.send(200, "text/html", page);
   digitalWrite(LEDSetPin, HIGH);
   delay(10);
   digitalWrite(LEDSetPin, LOW);
   delay(10);
 });

 //turn off the on pin and turn on the off pin
 server.on("/LEDOff", [](){
   server.send(200, "text/html", page);
   digitalWrite(LEDUnsetPin, HIGH);
   delay(10);
   digitalWrite(LEDUnsetPin, LOW);
   delay(10);
 });
 server.begin();
 Serial.println("Web server started!");
}

void loop(void){
 server.handleClient();
}
0

That board is specifically designed for the Feather ecosystem, so you'd need to provide the relevant connections, looks like 3.3V and GND, and the two input signals (also 3.3V, I assume). Nutshell: you can ignore almost every single connector on the board except for 3.3V, GND, SET, and UNSET.

Any D1 (or Arduino in general) tutorial that discusses how to set an output pin value is fine--you'd need them to be LOW by default and bring the relevant one HIGH for 10ms (delay is fine here) to set the new state.

Any switch input tutorial should be fine for learning how to read a switch, and there are multiple tutorials regarding setting up a simple web app that interacts with 8266 IO. Note that you'll want to keep track of the current state, though, and probably update the web app with the current state if it's changed via the button.

All this said: "just trying to turn off/on some LEDs" is broad. A relay may not be necessary; is there an explicit need for a latching relay?

1
  • Dave - This pretty much what I am after. There is no explicit need really just a learning exercise. Really finding an answer to a question no one asked ;o) - If anyone wants to provide code.... that would be awesome but I'm not greedy and can dig it up myself. Thanks
    – Siburmax
    Jun 14 '21 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.