IoT Switch | Blynk (ESP 32)
This project is used to turn on/off the leds or home appliances through
internet from any part of the world.
THINGS NEEDED
- ESP 32
- 1K Resistor
- LED'S
- BreadBoard
- Jumper Wire's
CIRCUIT DIAGRAM
WIRING
LED'S TO ESP32
- Connect the LED which you want to adjust the brightness to D2 (GPIO 2) of ESP32.
- Connect LED 1 to D5 (GPIO 5) of ESP32.
- Connect LED 2 to D18 (GPIO 18) of ESP32.
- Connect LED 3 to D 19 (GPIO 19) of ESP32.
- Connect LED 4 to D 21 (GPIO 21) of ESP32.
IN BLYNK
CODE
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
BlynkTimer timer;
// OUTPUT PIN'S
#define led1 5
#define led2 18
#define led3 19
#define led4 21
// PWM PIN
#define led 2
// VARIABLE FOR PWM IN ESP32
const int freq = 5000;
const int ledChannel = 0;
const int resolution = 8;
// AUTHENTICATION TOKEN WHICH WILL BE SEND TO YOUR RESISTERED EMAIL ID
char auth[] = "-----------------------";
// FOR ESP32 TO CONNECT TO ROUTER TO INTERNET
char ssid[] = "----------"; // WIFI NAME
char pass[] = "----------"; // WIFI PASSWORD
// BUTTON'S ON BLYNK APP
BLYNK_WRITE(V0)
{
int pinValue = param.asInt();
digitalWrite(led1, pinValue);
}
BLYNK_WRITE(V1)
{
int pinValue = param.asInt();
digitalWrite(led2, pinValue);
}
BLYNK_WRITE(V2)
{
int pinValue = param.asInt();
digitalWrite(led3, pinValue);
}
BLYNK_WRITE(V3)
{
int pinValue = param.asInt();
digitalWrite(led4, pinValue);
}
// SLIDER ON BLYNK
BLYNK_WRITE(V4)
{
int pinValue = param.asInt();
ledcWrite(ledChannel,pinValue);
}
void setup()
{
// SET PIN'S AS OUTPUT
pinMode(led1 ,OUTPUT);
pinMode(led2 ,OUTPUT);
pinMode(led3 ,OUTPUT);
pinMode(led4 ,OUTPUT);
pinMode(led ,OUTPUT);
Serial.begin(9600); // BEGIN SERIAL COMMUNICATION
WiFi.begin(ssid, pass); // ESP32 TO CONNECT TO YOUR WIFI
Blynk.config(auth); // FOR CONNECT TO BLYNK SERVER
// FOR PWM
ledcSetup(ledChannel, freq, resolution);
ledcAttachPin(led, ledChannel);
}
void loop(){
Blynk.run(); // TO START THE BLYNK SERVER TO
COMMUNICATE WITH ESP32
}
THANK YOU
Vist our YT Channel
ReplyDelete