I'm trying to implement a "button pusher" with some transistors controlled by an ESP-01 module, to push buttons on a remote control. I'm having an issue where if when the GPIOs (I'm using 0, 2, and 3) are connected to the base of the transistor (via a 1k resistor) when I apply power, the ESP will not start and the transistors (2n2222) are in the on state. The red light comes on, the blue light flashes very briefly, but the LEDs I'm testing the transistors with are on, and ESP never starts broadcasting its network. If I disconnect the GPIO 0, 2, and 3 pins, power the ESP, then reconnect them then everything works fine until reboot. Here is a portion of the circuit, the real one has 3 transistors, but they're all set up the same.
simulate this circuit – Schematic created using CircuitLab
And here's my code:
#include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
const char *ssid = "RemoteControl";
const char *password = "********";
const int button1 = 0;
const int button2 = 2;
const int button3 = 3;
const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);
String webpage = "<!DOCTYPE html><html><head><title>Remote Control</title><meta name='mobile-web-app-capable' content='yes' /><meta name='viewport' content='width=device-width' /><script type='text/javascript'>var eventLocked=false;function handleEvent(button){if(eventLocked||button>3){return;}var params='b='+button;var req=new XMLHttpRequest();req.open('POST','?'+params,true);req.send();eventLocked=true;req.onreadystatechange=function(){if(req.readyState==4){eventLocked=false;}}}</script></head><body style='margin: 0px; padding: 0px;'><button onclick='handleEvent(1)' style='width:100%;'><h1>1</h1></button><br><br><button onclick='handleEvent(2)' style='width:100%;'><h1>2</h1></button><br><br><button onclick='handleEvent(3)' style='width:100%;'><h1>3</h1></button></body></html>";
void handleRoot() {
String button = webServer.arg(0);
switch(button.toInt()) {
case 0:
// initialize webpage
digitalWrite(button1, LOW);
digitalWrite(button2, LOW);
digitalWrite(button3, LOW);
break;
case 1:
digitalWrite(button1, HIGH);
delay(250);
digitalWrite(button1, LOW);
break;
case 2:
digitalWrite(button2, HIGH);
delay(250);
digitalWrite(button2, LOW);
break;
case 3:
digitalWrite(button3, HIGH);
delay(250);
digitalWrite(button3, LOW);
break;
}
webServer.send(200, "text/html", webpage);
}
void setup() {
pinMode(button1, OUTPUT);
pinMode(button2, OUTPUT);
pinMode(button3, OUTPUT);
digitalWrite(button1, LOW);
digitalWrite(button2, LOW);
digitalWrite(button3, LOW);
delay(1000);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(ssid, password);
dnsServer.start(DNS_PORT, "remote", apIP);
webServer.on("/", handleRoot);
webServer.begin();
}
void loop() {
dnsServer.processNextRequest();
webServer.handleClient();
}
Is there something I'm doing wrong, or is this something unavoidable with the ESP itself?