Menu
Index
Engineering
Entertainment
Literature
Miscellaneous
Contact
Search
tiktok.com/@pkvi.xyz
buymeacoffee.com/pkvi
scored.co/u/pkvi_halfkdeltaxsq
Miter
Why Ayh?
Miter
@pkvi
"...may not meet professional standards."
252 miters
122 tenons
Subscribe
0.00427
NodeMCU Voice Bin Lid

NodeMCU
MG995 Servo
3D Printed Bits n' Pieces
Adhesives
Voice Attack (software)



// Jacob -> Lights -> Trash
// NodeMCU 12E
// Vije Miller

#include
#include

// Static IP
IPAddress ip(192, 168, 0, 47);
IPAddress gateway(192, 168, 0, 1);
IPAddress dns(192, 168, 0, 1);
IPAddress subnet(255, 255, 255, 0);

const char* ssid = "ssid";
const char* pass = "password";

WiFiServer server(80);

// Trash
Servo trash;
int pos = 80;
int up_lid = 145;
int down_lid = 80;
int bin_delay = 20;

// Lights
int relay = D8;
int state = 0;
int led = D0;

void setup() {
Serial.begin(115200);

pinMode(led, OUTPUT);
pinMode(relay, OUTPUT);

trash.attach(D5);
trash.write(90);

digitalWrite(led, LOW);
digitalWrite(relay, LOW);

wifi_connect();
}

void loop() {

// Check
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait
while (!client.available()) {
delay(1);
}
// Read
String query = client.readStringUntil('\r');
client.flush();

if (query.indexOf("/light") != -1) {
if (state == 0) { // off
up();
} else if (state == 1) { // on
down();
}
} else if (query.indexOf("/trash") != -1) {
trash_open();
}

// Browsers prefer content to read other wise they loop.
// Voice program attack ip+/light or ip+/trash
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("");
client.println("");
client.println("");
client.println("");
client.println("");
client.println("");

delay(1);
Serial.println("Client disonnected");
}

// Light Switch On
void up() {
digitalWrite(led, HIGH);
digitalWrite(relay, HIGH);
state = 1;
}

// Light Switch Off
void down() {
digitalWrite(led, LOW);
digitalWrite(relay, LOW);
state = 0;
}

// Trash Open + Close
void trash_open() {
for (pos = down_lid; pos <= up_lid; pos += 1) {
trash.write(pos);
delay(bin_delay);
}
delay(3000);
for (pos = up_lid; pos >= down_lid; pos -= 1) {
trash.write(pos);
delay(bin_delay);
}
}

// Wifi Dating App
void wifi_connect() {
Serial.println(ssid);
WiFi.config(ip, gateway, subnet, dns);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Connected");
server.begin();
Serial.print("http://");
Serial.print(WiFi.localIP());
Serial.println("/");
}