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

Book

The document outlines a project integrating a NodeMCU ESP8266 with an Ultrasonic sensor for IoT cloud functionalities. It details the apparatus, theory, advantages, code, and procedure for setting up the system to measure distances and transmit data to cloud platforms like ThingSpeak. The project enables real-time monitoring and centralized data access, making it suitable for various smart device applications.
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)
13 views

Book

The document outlines a project integrating a NodeMCU ESP8266 with an Ultrasonic sensor for IoT cloud functionalities. It details the apparatus, theory, advantages, code, and procedure for setting up the system to measure distances and transmit data to cloud platforms like ThingSpeak. The project enables real-time monitoring and centralized data access, making it suitable for various smart device applications.
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/ 4

Aim:

IOT in the cloud using NodeMCU and InfraRed sensor: integrate NodeMCU with an Ultrasonic
sensor to enable Iot cloud-based functionalities.

Apparatus:

- NodeMCU ESP8266 board


- IR Sensor (HC-SR04)
- Jumper wires
- Breadboard
- Micro USB cable

Theory: The NodeMCU ESP8266 is a powerful microcontroller board with built-in Wi-Fi
connectivity, making it an excellent choice for IoT applications. It allows for seamless integration
with various sensors and cloud platforms to collect, process, and visualize data in real time.

The Ultrasonic sensor (HC-SR04) operates on the principle of emitting high-frequency sound
waves and measuring the time taken for the echo to return after bouncing off an object. The
formula used to compute the distance is:

Distance = (Time × Speed of Sound) / 2.

In this experiment, the Ultrasonic sensor acts as a data source, measuring distances and sending
the data to the NodeMCU. The NodeMCU processes this data and transmits it over Wi-Fi to a
cloud platform such as ThingSpeak or Firebase for further analysis and visualization. This setup
enables remote monitoring, making it useful for applications like object detection, obstacle
avoidance, and real-time monitoring in smart devices.

Advantages of IoT Cloud Integration:

1. Real-time Data Access: Enables users to monitor data from anywhere with an internet
connection.
2. Centralized Monitoring: Allows multiple sensors to transmit data to a single cloud
platform for easy visualization.
3. Scalability: IoT systems can be easily expanded with additional devices and sensors.
Code:
#include <ESP8266WiFi.h>
#include <ThingSpeak.h>

const char* ssid = "STAFF";


const char* password = "sTAFF@2024";
WiFiClient client;
unsigned long myChannelNumber =34676522;
const char* myWriteAPIKey = "RTOHGEVJK007";

#define TRIG_PIN D5
#define ECHO_PIN D6

void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
ThingSpeak.begin(client);

pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}

void loop() {
long duration, distance;
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH);
distance = duration * 0.034 / 2;

Serial.print("Distance: ");
Serial.println(distance);
ThingSpeak.setField(1, distance);
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
delay(15000);
Procedure:

1. Hardware Connections:

• Connect the VCC pin of the Ultrasonic sensor to the 3.3V pin of the NodeMCU.
• Connect the GND pin of the Ultrasonic sensor to the GND pin of the NodeMCU.
• Connect the TRIG pin of the Ultrasonic sensor to D5 (GPIO14) of the NodeMCU.
• Connect the ECHO pin of the Ultrasonic sensor to D6 (GPIO12) of the NodeMCU.

2. Software Setup:

• Install the required libraries in Arduino IDE, including ESP8266 and relevant IoT
platform libraries.
• Write a program to read distance values from the Ultrasonic sensor, process them, and
upload data to the IoT platform.
• Configure the cloud platform (e.g., ThingSpeak, Firebase) to receive and visualize data.
• Upload the program to the NodeMCU and establish a Wi-Fi connection.

Verify that distance readings are successfully transmitted to the cloud and displayed on the
platform.

Precautions:
- Ensure proper power supply to the NodeMCU.
- Avoid miswiring, as it may damage components.
- Test the IR sensor in a stable environment for accurate readings.

Result:

You might also like