0% found this document useful (0 votes)
12 views

experiment 5

This document outlines an experiment to demonstrate remote light switching using NodeMCU (ESP8266) and a cloud platform (Blynk). It details the components required, the theory behind using a relay for controlling lights, and provides a step-by-step procedure for hardware setup, programming, and testing the system. The successful outcome is the ability to toggle a light or LED on and off remotely via the Blynk app.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

experiment 5

This document outlines an experiment to demonstrate remote light switching using NodeMCU (ESP8266) and a cloud platform (Blynk). It details the components required, the theory behind using a relay for controlling lights, and provides a step-by-step procedure for hardware setup, programming, and testing the system. The successful outcome is the ability to toggle a light or LED on and off remotely via the Blynk app.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Experiment 5

Demonstrating Remote Light Switching Using NodeMCU

Aim: To demonstrate how to remotely switch lights on and off using the NodeMCU
(ESP8266) and control it via cloud platform.

Components Required:

1. NodeMCU (ESP8266)

2. Relay module (to control the light)

3. Light bulb or LED (for demonstration)

4. Jumper wires

5. Breadboard (optional)

6. Power supply for NodeMCU (micro-USB cable)

7. Cloud platform (Blynk)

8. WiFi connection

Theory:

The NodeMCU is a low-cost WiFi-enabled microcontroller based on the


ESP8266 module, often used in IoT projects. It can be programmed using the Arduino
IDE and supports both analog and digital input/output pins. In this experiment, a
relay is used to control the switching of a light bulb.

A relay is an electrically operated switch that can control high-voltage devices


using a low-voltage signal. The NodeMCU sends a signal to the relay, which either
closes or opens the circuit connected to the light, turning it on or off. The control
signal can be sent remotely using either a local web server hosted by the NodeMCU or
a cloud platform such as Blynk.

Procedure:

1. Hardware Setup:

- NodeMCU Pin Connections:


- Relay VCC: Connect to NodeMCU's 3.3V

- Relay GND: Connect to NodeMCU's Ground (GND)

- Relay IN: Connect to GPIO pin (e.g., D1) of the NodeMCU

- Bulb/LED: Connect to relay (normally open contacts).

- Power for Light Bulb/LED: Connect a separate power supply through the relay.

2. Install Arduino IDE (if not already done):

- Download and install the Arduino IDE from [Arduino


website](https://www.arduino.cc/en/software).

- Add ESP8266 board support to the Arduino IDE:

- Go to `File -> Preferences`, and in the "Additional Boards Manager URLs", paste
this URL: `http://arduino.esp8266.com/stable/package_esp8266com_index.json`.

- Go to `Tools -> Board -> Boards Manager` and install ESP8266.

3. Install Blynk Library (optional for cloud control):

- In the Arduino IDE, go to `Sketch -> Include Library -> Manage Libraries` and
search for Blynk. Install the library.

4. Write the Program:

- You can either use Blynk (cloud platform) or set up a local web server for remote
control.

Code:

//Using Blynk for Remote Control

#define BLYNK_TEMPLATE_ID "YourTemplateID"

#define BLYNK_DEVICE_NAME "YourDeviceName"

#define BLYNK_AUTH_TOKEN "YourAuthToken"


#include <ESP8266WiFi.h>

#include <BlynkSimpleEsp8266.h>

char auth[] = "YourAuthToken"; // Blynk Auth Token

char ssid[] = "YourSSID"; // Your WiFi SSID

char pass[] = "YourPassword"; // Your WiFi Password

int relayPin = D1; // Relay connected to GPIO pin D1

void setup() {

// Begin serial communication and setup relay pin

Serial.begin(115200);

pinMode(relayPin, OUTPUT);

digitalWrite(relayPin, HIGH); // Set relay off initially

// Connect to Blynk

Blynk.begin(auth, ssid, pass);

void loop() {

Blynk.run(); // Run Blynk to maintain connection

// Blynk button widget on virtual pin V1 to control relay

BLYNK_WRITE(V1) {

int buttonState = param.asInt(); // Get the state of the button (1 or 0)


if (buttonState == 1) {

digitalWrite(relayPin, LOW); // Turn on the relay (light ON)

} else {

digitalWrite(relayPin, HIGH); // Turn off the relay (light OFF)

5. Upload Code:

- In the Arduino IDE, select the NodeMCU 1.0 (ESP-12E Module) under `Tools ->
Board`.

- Choose the correct port under `Tools -> Port`.

- Upload the code to the NodeMCU.

6. Testing the Setup:

- For Blynk: Open the Blynk app on your smartphone, create a project, add a button
widget linked to Virtual Pin V1, and test the control.

- For Web Server: Connect your phone or computer to the same network and open
the NodeMCU's IP address in a web browser (check the IP address printed in the Serial
Monitor).

Results: In the Blynk app, pressing the button widget will turn the relay (and hence
the light) on and off. The output of the system will be the successful toggling of a light
or LED, demonstrating the ability to switch a light on/off remotely using NodeMCU.

You might also like