IoT on a Budget: Building a WiFi-Controlled Switch for Under ₱300
The “Internet of Things” (IoT) often sounds expensive. We imagine smart fridges that cost ₱100,000 or complex home automation systems. But for a Computer Engineer, IoT is surprisingly accessible.
Today, we are going to build a “Hello World” project for IoT: A WiFi-controlled switch that you can toggle from your phone. And we are going to do it for less than the price of a samgyupsal meal.
The Bill of Materials (BOM)
You can find these parts on Shopee or Lazada easily:
- ESP8266 (NodeMCU V3): ~₱130. This is the brain. It’s like an Arduino but with built-in WiFi.
- Relay Module (1-Channel, 5V): ~₱40. This acts as the switch. It lets the low-voltage ESP8266 control high-voltage appliances (like a lamp).
- Jumper Wires (Female-to-Female): ~₱20.
- USB Cable (Micro-USB): You probably already have one.
Total Cost: ~₱190
Step 1: The Wiring
We need to connect the ESP8266 to the Relay.
- VCC (Relay) -> VU / VIN (ESP8266) (5V power)
- GND (Relay) -> GND (ESP8266)
- IN (Relay) -> D1 (ESP8266) (GPIO 5)
Safety Warning: For this tutorial, we will verify the relay clicks (sound) and the LED turns on. DO NOT cut your 220V lamp cord unless you are supervised by a licensed electrician or engineer. High voltage kills.
Step 2: The Software (Blynk IoT)
We could write our own web server code, but let’s use a platform to make it easy.
- Download the Blynk IoT app on your phone.
- Create a new account and a “New Template.” Name it “Smart Switch.”
- Choose ESP8266 as the hardware and WiFi as the connection.
- In the “Datastreams” tab, create a Virtual Pin (V0). Set it to Integer (0-1).
- Create a Web Dashboard with a simple Switch widget linked to Datastream V0.
Step 3: The Code
Open your Arduino IDE. Make sure you have the ESP8266 board manager installed.
#define BLYNK_TEMPLATE_ID "Your_Template_ID"
#define BLYNK_DEVICE_NAME "Smart Switch"
#define BLYNK_AUTH_TOKEN "Your_Auth_Token"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Your_WiFi_Name";
char pass[] = "Your_WiFi_Password";
// The pin connected to the Relay
const int relayPin = 5; // D1 on NodeMCU is GPIO 5
void setup()
{
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
}
// This function runs every time you press the button in the app
BLYNK_WRITE(V0)
{
int pinValue = param.asInt(); // Get value (0 or 1)
if (pinValue == 1) {
digitalWrite(relayPin, HIGH); // Turn Relay ON (or OFF depending on logic)
} else {
digitalWrite(relayPin, LOW);
}
}
Step 4: Test It
Upload the code. Open your Serial Monitor to check the connection. Once connected, press the button on your phone.
Click.
That sound is the relay switching mechanically. You have just controlled a physical object over the internet. From here, you can automate anything: a fan, a door lock, or a garden sprinkler. Welcome to the world of IoT.
