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

ESW Lab Report

The lab report summarizes 3 experiments interfacing an HC-SR04 ultrasonic sensor with an ESP32 microcontroller. The first experiment tested the sensor and displayed distance readings on a serial monitor. The second sent sensor data to a ThingSpeak server via MQTT. The third used a webpage to control a servo motor by taking input prompts and communicating with the ESP32 over ThingSpeak.
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)
8 views

ESW Lab Report

The lab report summarizes 3 experiments interfacing an HC-SR04 ultrasonic sensor with an ESP32 microcontroller. The first experiment tested the sensor and displayed distance readings on a serial monitor. The second sent sensor data to a ThingSpeak server via MQTT. The third used a webpage to control a servo motor by taking input prompts and communicating with the ESP32 over ThingSpeak.
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/ 9

Lab Report 1

Interfacing HC-SR04, sending data to Thing Speak and controlling Servo via
website.

Team Members

• SANTHOSH K.M, 2022101057


• PRATHAM OMKAR PATTANAYAK, 2022101078

Experiment 1 - Make sure HC-SR04 works accordingly.

Objective

The aim of the experiment is to test the HC-SR04 sensor and display the readings on the serial monitor.

Procedure

• First connect the VCC and GND pins of the sensor with the respective terminals of the ESP32.
• We have to connect the trigger and echo pin of the sensor with GPIO pins ESP32 . We used the
pin 5 as trigger and pin 18 as the echo.

• The code is then loaded on the microcontroller and output is then displayed on the serial monitor.

Figure 1: Circuit diagram

1
Code

Block Diagram

Figure 2: Flow of data

2
Observation

The sensor starts displaying the distance values on the Serial monitor which is the distance of the object
placed near it. The values are displayed on the serial monitor in centimetre. The sensor correctly
displayed the distance on keeping the object at different distances. If nothing is kept then sensor shows
the maximum value it can measure which is about 2 metres.

Observed Value Actual Value


32.3 34
37.2 37.6
41.4 40.8
17.6 18
23.6 23.4
31 31.3

Table 1: Actual distance vs Observed distance(Ultrasonic sensor)

Figure 3: Experimental setup

Conclusion

The sensor basically measures the distance based on the ultrsasonic waves it sends through the sensor
located on it. The receiver located on it waits on the signal for a certain amount of time after which
the receiver again gets deactivated. Thus, the sensor has a limit on the maximum possible distance it
can measure which based on our experiment is roughly 2 metres. If the sensor indeed receives the signal
within the time limit then it calculates the distance based on the time taken for the echo to return.

3
Experiment 2 - Collecting the data from the sensor and sending it to Things-
peak server.

Objective

The distance measured is collected from the sensor and the aim is to now send the data to ThingSpeak
server.

Procedure

• First connect the VCC and GND pins of the sensor with the respective terminals of the ESP32.
• We have to connect the trigger and echo pin of the sensor with GPIO pins ESP32 . We used the
pin 5 as trigger and pin 18 as the echo.
• Connect to the ThingSpeak server through mqtt protocol by using the username and password.
• We have to make a channel on the website where the data can be visualised on a graph
• Since we are writing on the field of the channel the write API keys are included in the code.

• The code is then loaded on the microcontroller and output is then displayed on the serial monitor.

Figure 4: Circuit diagram

4
Code

5
Block Diagram

Figure 5: Flow of data

Observation

The data collected is send to the server based through mqtt protocol and is displayed on the screen
through a graph. The thingspeak has by default a delay of 15 seconds on plotting the data on the screen.

Figure 6: Observations

Conclusion

The data is sent using the MQTT protocol to the ThingSpeak server which acts a database and allows
interoperability as we can use the data from various sensors at one place and use the data.

6
Experiment 3 - Controlling the Servo Motor using prompts from a website.

Objective

In this part, we have to take input from a website and control the servo motor.

Procedure

• We have to first connect the servo motor with the ESP32 by connecting the VCC,GND and signal
pins

• The servo.h attach file is used in code to define the signal pin for the sensor. We have used the pin
number 13.
• The code for the HTML page to be rendered is included in the code
• The code is then run and an IP address is generated which has to be opened on the web browser.

• The switches for ON and OFF are now displayed on the screen which are ready to use.

Figure 7: Circuit diagram

7
Code

8
Block Diagram

Figure 8: Flow of data

Observation

The HTML page can be used to control the servo motor. ThingSpeak is used to pull data requests from
the API key and move the servo using the webpage. The servo motor has two states , ON and OFF
state, which are separated by 90 degrees. When we press the ON button, there are two things possible.
If the motor is in ON state then it remains in the same state or else the it switches the state. The same
thing happens for the OFF state as well.

Figure 9: Observations

Conclusion

This part shows how thingspeak can be used to do requests and demonstrates how the data can be
channelled to external sources using ThIngSpeak. This shows how IoT based solutions can be used to
remote control various electronic devices.

You might also like