Go Down

Topic: How do I power Wemos D1 Mini Properly? (Read 176 times) previous topic - next topic

DJDJDJDJ

Nov 17, 2019, 05:30 pm Last Edit: Nov 17, 2019, 05:31 pm by DJDJDJDJ
Hi,

I am creating a project using Wemos D1 Mini to control a two-relay module. If I supply power to Wemos using USB and relays using a buck converter (all 5v) then everything seems to be working. However, if I power everything from just the buch converter, nothing works. I have tried to explain this using diagrams.

Please let me know what I am doing wrong.

Thanks.

This setup does not work.

https://imgur.com/a/9Odn8cH

This setup works.

https://imgur.com/a/mMAlFeG

I would like to power everything from one power sources (buck converter in this case).

Juraj

how nothing works? how much current can the converter supply?

PaulRB

This setup does not work.
Your images are not showing, and we shouldn't have to click links, because you can easily attach images to your post.

DJDJDJDJ

#3
Nov 17, 2019, 05:57 pm Last Edit: Nov 17, 2019, 06:45 pm by DJDJDJDJ
Your images are not showing, and we shouldn't have to click links, because you can easily attach images to your post.
I used the insert image option in the post but for whatever reason images did not show up. That's when I edited the post and added the links. I am not sure if I can included images or now since I have low post count.  

how nothing works? how much current can the converter supply?
Sorry, I have included that information in the images. Power converter is set to provide 5v. If I power using just that, then my LED turns on dimly, push button does not work, one of the two relays has LED on but other than that they do not trigger.

If I, however, power it using the USB and relays with buck converter, then everything works. I have this showing in the images as well.





PaulRB

#4
Nov 17, 2019, 06:03 pm Last Edit: Nov 17, 2019, 06:03 pm by PaulRB
I used the insert image option in the post but for whatever reason images did not show up. That's when I edited the post and added the links.
I suspect imgur don't like "deep" links from external sites.

To attach images to you post, don't use the "Quick Reply" box, instead hit "REPLY". You should see an "attachments" option under the reply box. Select your images from the PC and hit "Post". Then you can right-click and copy the address of each image. Then hit Modify on your post and insert the images using the "insert an image" icon.

PaulRB

Are you setting D6 to INPUT_PULLUP? If not, that's why the button is not working. If it works using just INPUT with USB power and not when powered by the DC converter, that's just luck. The 2K in series with the button is pointless.

When you say the led is dim, is that when its supposed to be on or supposed to be off?

DJDJDJDJ

Thank you Paul for the image linking info.

Yes, I am using Pull-up.

LED is supposed to be on when relay is off. And when Relay is on LED is supposed to be off. If I power it using only the buck converter, dimmed LED is always on and button does not do anything. If I add the USB power to the mix, then everything works including the button.

Here is my code.

Code: [Select]

// Fully Working - 2019-11-17 (with dual power)
// Two Relays, one LED, one manual push/momentary switch, Wifi/Alexa Control

// Project for: Alexa Control mains light; + Button

#include <ESP8266WiFi.h>
#include <Bounce2.h>
#include "fauxmoESP.h"


const byte ButtonPin = D6;
const byte LedPin = D5;
Bounce button;

#define RELAY_PIN_1 D7
#define RELAY_PIN_2 D8
#define SERIAL_BAUDRATE 115200

#define WIFI_SSID "ssid"
#define WIFI_PASS "password"

#define LAMP_1 "Kitchen Light"
#define LAMP_2 "Extra Light"

fauxmoESP fauxmo;

// Wi-Fi Connection
void wifiSetup() {
  // Set WIFI module to STA mode
  WiFi.mode(WIFI_STA);

  // Connect
  Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASS);

  // Wait
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
  }
  Serial.println();

  // Connected!
  Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}
// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
void setup() {


  // Init serial port and clean garbage
  Serial.begin(SERIAL_BAUDRATE);
  Serial.println();

  // Wi-Fi connection
  wifiSetup();

  pinMode(RELAY_PIN_1, OUTPUT);
  digitalWrite(RELAY_PIN_1, HIGH);

  pinMode(RELAY_PIN_2, OUTPUT);
  digitalWrite(RELAY_PIN_2, HIGH);

  // Manual button
  button.attach(ButtonPin, INPUT_PULLUP);
  pinMode(LedPin, OUTPUT);


  // By default, fauxmoESP creates it's own webserver on the defined port
  // The TCP port must be 80 for gen3 devices (default is 1901)
  // This has to be done before the call to enable()
  fauxmo.createServer(true); // not needed, this is the default value
  fauxmo.setPort(80); // This is required for gen3 devices

  // You have to call enable(true) once you have a WiFi connection
  // You can enable or disable the library at any moment
  // Disabling it will prevent the devices from being discovered and switched
  fauxmo.enable(true);
  // You can use different ways to invoke alexa to modify the devices state:
  // "Alexa, turn lamp two on"

  // Add virtual devices
  fauxmo.addDevice(LAMP_1);
  fauxmo.addDevice(LAMP_2);

  fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
    // Callback when a command from Alexa is received.
    // You can use device_id or device_name to choose the element to perform an action onto (relay, LED,...)
    // State is a boolean (ON/OFF) and value a number from 0 to 255 (if you say "set kitchen light to 50%" you will receive a 128 here).
    // Just remember not to delay too much here, this is a callback, exit as soon as possible.
    // If you have to do something more involved here set a flag and process it in your main loop.

    Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);
    if ( (strcmp(device_name, LAMP_1) == 0) ) {
      // this just sets a variable that the main loop() does something about
      Serial.println("RELAY 1 switched by Alexa");
      //digitalWrite(RELAY_PIN_1, !digitalRead(RELAY_PIN_1));
      if (state) {
        digitalWrite(RELAY_PIN_1, LOW);
        digitalToggle(LedPin);
        Serial.print("LED should be off");
      } else {
        digitalWrite(RELAY_PIN_1, HIGH);
        digitalToggle(LedPin);
        Serial.print("LED should be on");
      }
    }
    if ( (strcmp(device_name, LAMP_2) == 0) ) {
      // this just sets a variable that the main loop() does something about
      Serial.println("RELAY 2 switched by Alexa");
      if (state) {
        digitalWrite(RELAY_PIN_2, LOW);
      } else {
        digitalWrite(RELAY_PIN_2, HIGH);
      }
    }
  });

}

// &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

void loop() {
  // fauxmoESP uses an async TCP server but a sync UDP server
  // Therefore, we have to manually poll for UDP packets
  fauxmo.handle();

  static unsigned long last = millis();
  if (millis() - last > 5000) {
    last = millis();
    Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
  }

  // Manually trigger Relay using momentary push button

  button.update();
  if (button.fell()) {
    digitalToggle(LedPin);
    digitalWrite(RELAY_PIN_1, digitalRead(LedPin));
    Serial.println(digitalRead(LedPin) ? F("on") : F("off"));
  }

}
inline void digitalToggle(byte pin) {
  digitalWrite(pin, !digitalRead(pin));
}


Thanks.

Juraj

Sorry, I have included that information in the images. Power converter is set to provide 5v. If I power using just that, then my LED turns on dimly, push button does not work, one of the two relays has LED on but other than that they do not trigger.
I asked about current not voltage. How much amps can the converter supply?

DJDJDJDJ

I asked about current not voltage. How much amps can the converter supply?
It is rated for max 10w so at 5v, I guess max 2 amps.

Juraj

#9
Nov 17, 2019, 06:55 pm Last Edit: Nov 17, 2019, 06:56 pm by Juraj
It is rated for max 10w so at 5v, I guess max 2 amps.
that should be enough, if it can provide it fast enough.

DJDJDJDJ

It is LM2596 base converter that someone recommended for this project. It provides 1.5-35 volts at 2A and 3A if used with a heatsink (I don't have heat sink as I don't think I need it).

PaulRB

Yes, the Wemos will only need around 80mA, and the relay module perhaps 100mA when both relays are on.

BTW, why did you choose a 12V PSU and the DC convertor, instead of simply using a 5V PSU?

I suggest you start simple and test things one at a time. Put the Alexa sketch to one side for the moment. Upload the Blink sketch, set to use the Wemo's tiny blue led. Test that it works on USB power. Then test it on the PSU. If all is good, change the Blink sketch to use the external led, test on USB, then the external PSU. Then change the Blink sketch to activate one relay. Test using USB power. Then test with the external PSU but with the "self-powered" link in place. Then test without the link. Then test the other relay.

DJDJDJDJ

Yes, the Wemos will only need around 80mA, and the relay module perhaps 100mA when both relays are on.

BTW, why did you choose a 12V PSU and the DC convertor, instead of simply using a 5V PSU?

I suggest you start simple and test things one at a time. Put the Alexa sketch to one side for the moment. Upload the Blink sketch, set to use the Wemo's tiny blue led. Test that it works on USB power. Then test it on the PSU. If all is good, change the Blink sketch to use the external led, test on USB, then the external PSU. Then change the Blink sketch to activate one relay. Test using USB power. Then test with the external PSU but with the "self-powered" link in place. Then test without the link. Then test the other relay.

Thank you Paul.
I had a 12v power laying around at home so I decided to use it.

A quick questions, Wemos pin label 5V; can it be used to power the wemos? If I power it via the USB, can the same pin be used to power other devices such as relays etc? I am not too sure about this particular part.

With Arduino, I know that VCC & usb are to power the board and 5v is to provide power to other devices but I am not too clear with wemos.

I will try your approach and see if I can isolate any particular scenario. 

Thank you for your help.

Juraj

Yes, the Wemos will only need around 80mA.
check the esp8266 datasheet. max is 170 mA

A quick questions, Wemos pin label 5V; can it be used to power the wemos? If I power it via the USB, can the same pin be used to power other devices such as relays etc? I am not too sure about this particular part.
yes


PaulRB

check the esp8266 datasheet. max is 170mA
There are shorts bursts of current required, yes, probably in excess of 200mA. But they are short-lived. The average consumption is around 80mA. As long as your circuit has sufficient capacitor smoothing, you do not need much more than around 80mA PSU in practice. Plus, of course, what current other components in the circuit may need.

Go Up