Would like some guidance on power switching with D1 mini.

Hi there,

I have a bunch of cheap holiday laser lights that I am going to control by throwing an D1 mini into each one and controlling all that with a Blynk app.

The problem I am facing is that these lights do not have a power button and work on a 8 hours on, 16 hours off. The lights are powered by a 5V/2A wall wart. D1 mini's power and ground pins are soldered directly to the light's PCB. I am trying to find a way to insert a D1 in between incoming power feed and the light's PCB, so I can turn off the light completely, while still maintaining power to the D1.

So a relay seems to be a logical solution, but its rather bulky and I am only controlling 5V DC, so I don't need a full blown relay. Adding a transistor or a button? That would require me to solder things directly to the wires, because I have no other way to add them and it will be a mess.

Is there anything I can do with just a D1 mini to be able to cut power (or perhaps ground) to the light's PCB whenever needed?

Also, I am using 5V to power the D1, so I can't use that pin anymore....

Google:

miniature relay

There is a relay shield available for the D1 mini.
Leo..

larryd:
Google:

miniature relay

Yeah I looked around for it, but haven't been able to find anything small enough.

There is, however, a D1 1-button Shield, which looks rather interesting. Please let me know if I am mis-understanding what it does.

https://wiki.wemos.cc/products:d1_mini_shields:1-button_shield

The description says "Connects D3 (GPIO0) to Ground"

Does that mean that I can connect GPIO0 to the Ground on the light's PCB board and by changing GPIO0 state it would turn on/off the light by opening/closing the ground signal to the PCB of the light?

pruchai:
Yeah I looked around for it, but haven't been able to find anything small enough.

There is, however, a D1 1-button Shield, which looks rather interesting. Please let me know if I am mis-understanding what it does.

https://wiki.wemos.cc/products:d1_mini_shields:1-button_shield

The description says "Connects D3 (GPIO0) to Ground"

Does that mean that I can connect GPIO0 to the Ground on the light's PCB board and by changing GPIO0 state it would turn on/off the light by opening/closing the ground signal to the PCB of the light?

This is a simple button.
It grounds D3(GPIO0).

What happens when that occurs is completely up to you.

The state of the button is read by the below code example from the Wemos Github site.

/*
 * 1 Button Shield - Simple Push
 * Press the pushbutton to switch on the LED
 *
 * 1 Button Shield pushbutton connects pin D3 to GND
 */

const int buttonPin = D3;
const int ledPin = BUILTIN_LED;

int buttonState = 0;

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);

  // set initial state, LED off
  digitalWrite(ledPin, buttonState);
}

void loop() {
  // read button state, HIGH when pressed, LOW when not
  buttonState = digitalRead(buttonPin);

  // if the push button pressed, switch on the LED
  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);  // LED on
  } else {
    digitalWrite(ledPin, LOW); // LED off
  }
}

Ok, I got it to work with N222 transistor that came with my first Arduino kit.

Here is a question. I have transistor base connected to GPIO15 on my D1 mini. GPIO15 has an internal 10K pull down resistor. Do i still need another resistor between GPIO15 and the base or the built-in resistor is enough?

EDIT: Hm.. looking at the diagrams, i may need to move the transistor base to a pin with a pull-up resistor since I would be using that pin as output. Is this correct assumption?