NodeMCU Voice Bin Lid
Just .. out .. of .. reach. The solution is of course to waste additional resources bcz what is it to be modernly alive if not burdening others, from the unseen to those cherished. To hell with them all bcz the bin is aesthetically more appealing out of reach.


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

Notations
1. This project was least about creative thinking and more about episodic novelty practicality .. a form of selling out .. in my mind.
2. The feisty bot is K∞e (pronounced Katey). She/it will co-star in several upcoming engineering episodes bcz she/it does not demand scale.
3. The code presented features both the trash bin lid and a light switch relay.
4. Program voice cmd to call url http://192.168.0.47/trash -> or go to url and press 'trash' button.

Code Dumpster Fire (Relay (Light Switch) + Servo (Trash Bin))
// Jacob -> Lights -> Trash
// NodeMCU 12E
// Vije Miller

#include <ESP8266WiFi.h>
#include <Servo.h>

// 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("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<a href=\"/light\"\"><button> Light </button></a>");
client.println("<a href=\"/trash\"\"><button> Trash </button></a>");
client.println("</html>");

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("/");
}

Archive
https://hackaday.io/project/166736-nodemcu-voice-bin-lid
https://voiceattack.com/