How i build smart room less than $40

Fajar Firdaus, Internet of things
Back

So first things first what is internet of things ?, simply the internet of things stuff is the technology that allow you to automate something with programmed chip called microcontroller like Arduino, Nodemcu, Adafruit Feather and the others.

In this case the components i used for smart room is Nodemcu ESP8266 ($14), Relay 4 Channel ($8), Jumper Cable ($7) that cost around $30

Now we move to putting all the hardware, before you programmed the nodemcu you have to connect the D1 - D4 and VCC pin goes to VCC and GND pin goes to GND Pin into the relays with jumper cable

this is the example wiring

If all of the components done, we move to programming section which means we have to upload our program to nodemcu, before you can upload your program to nodemcu you have to install the Arduino IDE now you have to setting up the nodemcu board into Arduino IDE if the setup is done now the time to upload the program to the board

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

ESP8266WebServer server(80);

#define relay1 D1;
#define relay2 D2;
#define relay3 D3;
#define relay4 D4;

#define WLAN_SSID "yourssid";
#define WLAN_PASS "yourpass";

void relayone() {
  digitalWrite(relay1, LOW);
  server.send(200, "text/plain", "{ Relay1: ON  }");
}

void relaytwo() {
  digitalWrite(relay2, LOW);
  server.send(200, "text/plain", "{ Relay2: ON  }");
}

void relaythree() {
  digitalWrite(relay3, LOW);
  server.send(200, "text/plain", "{ Relay3: ON  }");
}

void relayfour() {
  digitalWrite(relay4, LOW);
  server.send(200, "text/plain", "{ Relay4: ON  }");
}

void relayonedie() {
    digitalWrite(relay1, HIGH);
    server.send(200, "text/plain", "{ Relay1: OFF  }");
}

void relaytwodie() {
    digitalWrite(relay2, HIGH);
    server.send(200, "text/plain", "{ Relay2: OFF  }");
}

void relaythreedie() {
    digitalWrite(relay3, HIGH);
    server.send(200, "text/plain", "{ Relay3: OFF  }");
}

void relayfourdie() {
    digitalWrite(relay4, HIGH);
    server.send(200, "text/plain", "{ Relay4: OFF  }");
}

void notfound(){
  server.send(404, "text/plain", "{ Not_Found: 404  }");
}

void setup(){
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);

  Serial.print("Connecting to ");
  Serial.println(WLAN_SSID);

  WiFi.begin(WLAN_SSID, WLAN_PASS);
  while(WiFi.status() != WL_CONNECTED){
    delay(500);
    Serial.print('.');
  }

  Serial.println("WIFI Connected");
  Serial.print("IP address : ");
  Serial.println(WiFi.localIP());


  server.on("/relay1", HTTP_POST, relayone);
  server.on("/relay2", HTTP_POST, relaytwo);
  server.on("/relay3", HTTP_POST,  relaythree);
  server.on("/relay4", HTTP_POST, relayfour);

  server.on("/relay1die", HTTP_POST, relayonedie);
  server.on("/relay2die", HTTP_POST, relaytwodie);
  server.on("/relay3die", HTTP_POST, relaythreedie);
  server.on("/relay4die", HTTP_POST, relayfourdie);

  server.onNotFound(notfound);


  server.begin();
}

void loop(){
  server.handleClient();
}

Copy this script and upload it into your Arduino IDE If the upload is done you have to connect the relay into electrical component you want to automate. like Light Bulb, Solenoid, or the others

For the application to communicate with nodemcu i used Project-365%. all the application instruction in the github

© Fajar Firdaus | Powered By Next.js.