TUTORIAL MENGONTROL LAMPU MENGGUNAKAN BLYNK || 2024 IOT
Table of Contents
Introduction
This tutorial will guide you through the process of controlling an LED light using Blynk and the ESP8266 microcontroller. You'll learn how to set up the necessary software and hardware, allowing you to create a simple IoT project that can be controlled via a mobile app. This project is not only a great introduction to IoT but also demonstrates how to integrate hardware and software effectively.
Step 1: Gather Required Hardware and Software
Before you begin, ensure you have the following components ready:
Hardware
- ESP8266 microcontroller
- LED light
- Resistor (appropriate for the LED)
- Breadboard and jumper wires
- Laptop or PC
Software
- Arduino IDE (download from Arduino Official Site)
- Blynk app (available on Blynk Official Site)
Step 2: Setting Up the Arduino IDE
- Install Arduino IDE on your laptop or PC.
- Add ESP8266 Board Manager:
- Open Arduino IDE.
- Go to File > Preferences.
- In the "Additional Board Manager URLs" field, add the following:
http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Click OK.
- Install ESP8266 Board:
- Navigate to Tools > Board > Board Manager.
- Search for "ESP8266" and install it.
Step 3: Create a Blynk Project
- Open the Blynk app on your mobile device.
- Create a new project:
- Select the ESP8266 as the device.
- Choose the connection type (Wi-Fi).
- Click Create.
- Get the Auth Token:
- You will receive an authentication token via email. Save this token for later use in your code.
- Add a Button Widget:
- Drag and drop a button onto the project screen.
- Configure the button:
- Set the button to switch mode.
- Assign a virtual pin (e.g., V0).
Step 4: Wiring the LED
- Connect the LED to the ESP8266:
- Connect the longer leg (anode) of the LED to a GPIO pin (e.g., GPIO2).
- Connect the shorter leg (cathode) to a resistor, and then to the ground (GND) on the ESP8266.
Step 5: Coding in Arduino IDE
- Open a new sketch in Arduino IDE.
- Include Blynk library at the top of your sketch:
#define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h>
- Define your credentials:
char auth[] = "YourAuthToken"; // Replace with your Auth Token char ssid[] = "YourNetworkName"; // Replace with your Wi-Fi SSID char pass[] = "YourNetworkPassword"; // Replace with your Wi-Fi Password
- Setup the Blynk connection in the
setup()
function:void setup() { Serial.begin(115200); Blynk.begin(auth, ssid, pass); }
- Control the LED in the
loop()
function:BLYNK_WRITE(V0) { int pinValue = param.asInt(); // Get value from button digitalWrite(2, pinValue); // Control LED on GPIO2 }
- Upload the sketch to your ESP8266.
Step 6: Testing the Setup
- Open the Blynk app on your mobile device.
- Tap the button you created to turn the LED on and off.
- Monitor the LED for responsive behavior.
Conclusion
You have successfully set up an IoT project using Blynk and the ESP8266 to control an LED. This project can be expanded to control multiple devices or integrate additional sensors. Experiment with different widgets in the Blynk app and consider exploring other IoT applications. Happy tinkering!