ESW Lab Report
ESW Lab Report
Interfacing HC-SR04, sending data to Thing Speak and controlling Servo via
website.
Team Members
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.
1
Code
Block Diagram
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.
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.
4
Code
5
Block Diagram
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.
7
Code
8
Block Diagram
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.