I'm trying to make my Project to run on either usb or 2 AAA batteries.
Here's what I'm thinking:
Battery tray Pos to Pos on breadboard rail
Battery tray Neg to Neg on breadboard rail
Wemos D1 mini 3V3 pin to Pos on breadboard rail
Wemos D1 mini G pin to Neg on breadboard rail
I will have a tiny sliding switch between Pos rail 3V3 pins
Here's where I think need help. When I plug it in via the usb, I would need a diode to protect the back flow to the batteries. I know what a diode does, but that's about as far as my knowledge goes. I need help selecting the right type and size.
Will any of this brick my Wemos? What are my flaws?
And the sketch for those that want to look at that;
/*
Using my Wemos D1 mini as remote control for Adafruit
Audio FX board. This sketch is for the Access
Point/remote control button.
*/
#include <ESP8266WiFi.h>
extern "C" {
#include "user_interface.h"
}
char apName[] = "SoundFx";
char apPassword[] = "Adafruit";
void setup() {
Serial.begin(115200);
delay(100);
WiFi.softAP(apName, apPassword);
WiFi.mode(WIFI_AP);
pinMode(D4, INPUT);// not sure what to put here
Serial.println();
Serial.println("AP Started");
}
int value = 0;
int stations = -1;
void loop() {
int stationsNow = wifi_softap_get_station_num();
if (stations != stationsNow) {
stations = stationsNow;
Serial.print("Station count: ");
Serial.println(stations);
}
int newValue = digitalRead(D4);
if (newValue != value) {
value = newValue;
Serial.print("value=");
Serial.println(value);
struct station_info *stat_info;
struct ip_addr *IPaddress;
unsigned long uintaddress;
Serial.println("Updating connected stations...");
stat_info = wifi_softap_get_station_info();
while (stat_info != NULL) {
IPaddress = &stat_info->ip;
uintaddress = IPaddress->addr;
String host = String(ip4_addr1(&uintaddress)) + "." + ip4_addr2(&uintaddress) + "." + ip4_addr3(&uintaddress) + "." + ip4_addr4(&uintaddress);
Serial.print("connecting to ");
Serial.println(host);
// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host.c_str(), httpPort)) {
Serial.println("connection failed");
}
else {
// We now create a URI for the request
String url;
if (value == HIGH) {
url = "/LED=ON";
}
else {
url = "/LED=OFF";
}
Serial.print("Requesting URL: ");
Serial.println(url);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n\r\n");
delay(50);
// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}
Serial.println();
Serial.println("closing connection");
}
client.flush();
client.stop();
stat_info = STAILQ_NEXT(stat_info, next);
}
Serial.println("All connected stations updated.");
}
}