Transforming IoT Prototyping: How to Easily Send Ultrasonic Sensor Data to ThingSpeak Cloud Using ESP8266 on Proteus Simulation
This article provides a step-by-step guide to connecting ultrasonic sensors to the ThingSpeak cloud in a Proteus simulation. It includes instructions on how to set up the simulation, interface the ultrasonic sensor with a microcontroller, and transmit the sensor data to the cloud.
Proteus:
The Proteus Design Suite is software used mainly for electronic design automation. Through Proteus, we can draw schematics, visual designs, and PCB layouts and can simulate the schematics with code or flowcharts. It is developed by Labcenter Electronics Ltd.
MQTT:
MQTT stands for Message Query Telemetry Transport. It is a messaging protocol designed for devices with low bandwidth, high latency, or unreliable networks. These qualities make it an ideal protocol for Machine to Machine communication (IoT devices).
In this project, Thingspeak’s MQTT broker is used ( mqtt3.thingspeak.com). It supports both publish and subscribe services. Publish sends a message from the device to the broker (ultrasonic sensor data to ThingSpeak’s channel graphs). Subscribe is used to get updates from the broker.
Components:
The components used in this simulation include Arduino Uno, Esp8266–12E, and Grove Ultrasonic Ranger Module.
- Arduino UNO: It is an open-source microcontroller board. It can be integrated into a variety of electronics projects. Arduino is mainly used for interfacing sensors.
- Esp8266–12E: It is a low-power consumption Wi-Fi module. It is used to connect devices with wireless Wi-Fi networks, and other network capabilities. Mainly, it uses for IoT applications and mobile devices.
- Grove Ultrasonic Ranger Module: It is an ultrasonic transducer using ultrasonic waves to measure distance.
Project Setup
In this tutorial, the step-by-step process of ultrasonic simulation has been explained.
Step 1
The first step is to open the Proteus 8 Professional and click on New Project.
Step 2
New Project Wizard will pop up on the screen. Enter the Project Name and specify the path.
Step 3
Create the schematic from the given template of your choice.
Step 4
There is no need for PCB Layout in this project. So click on Do not create a PCB Layout and then Next.
Step 5
Select Create Flowchart Project and Select ARDUINO Family.
Step 6
By clicking on Finish, the project will be created.
Step 7
On the schematic Sheet, Arduino UNO will be placed with all necessary connections.
Step 8
Visual Designer Sheet will have a flowchart with Arduino Setup and Loop Blocks.
Step 9
To enable Wi-Fi, the ESP8266 module is needed. To add the ESP8266, Right-click on Peripherals > Add Peripheral.
Step 10
Navigate to the category Internet of Things.
Step 11
Select the VFP server ESP8266 and click Add to insert it into the project.
Step 12
On the schematic Sheet, ESP8266 will be placed with all necessary connections.
Step 13
In the Peripherals project tree, Right-click on ESP1: MQTT (MQTT) > Enable Peripheral.
Step 14
Double-click on ESP1: MQTT (MQTT) to get the Properties of ESP1: MQTT.
Step 15
To get these credentials, first, create a channel in ThingSpeak. Login or Create an account in MathWorks.
Step 16
Click on New Channel.
Step 17
Fill in the necessary blocks including Project Name and Column Names. As this project is about ultrasonic simulation, the project name is Ultrasonic Simulation and it has only one attribute Distance, so the field name is the distance where distance measures (values) will be stored.
Step 18
Scroll down and Click on Save changes.
Step 19
To see your channel, Click on Channels > My channels > Ultrasonic Simulation.
Step 20
The Channel ID will be given below the Project Name.
Step 21
Scroll down the page and see the graph where distance will be visualized during the simulation.
Step 22
Now to get the credentials of MQTT, create the MQTT Device. Click on Devices > MQTT.
Step 23
Click on Add a new device.
Step 24
The dialogue box will pop up, enter the name of the MQTT device and select a previously created channel.
Step 25
Click on Add Channel > Add Device.
Step 26
The dialogue box will pop up where the credentials of MQTT will be given. Click on Download Credentials.
Step 27
The MQTT credential file will be downloaded that contains the username, clientId, and password.
Step 28
Enter the above details in the properties of ESP1: MQTT (Proteus). Here the server will be mqtt3.thingspeak.com.
Step 29
Now to add the ultrasonic module, click on Peripherals > Add Peripheral.
Step 30
Navigate to the category Grove. Select Grove Ultrasonic Ranger Module > Add.
Step 31
On the schematic Sheet, Grove Ultrasonic Ranger Module will be placed with all necessary connections.
Step 32
After adding all necessary components and MQTT Configuration, design the flowchart. Drag Connect from the ESP1 project tree to the LOOP routine block.
Step 33
To read the data from Ultrasonic Module, drag readCentimeters from UR1 (Grove Ultrasonic Ranger) to the Loop Block and place it after the connect block.
Step 34
To publish the distance values from the ultrasonic sensor to ThingSpeak, drag publish from the project tree to Loop.
Step 35
The basic syntax of Topic is “channels/<channel ID>/ publish/fields/field<number>”. Enter the topic with a channel ID and field number of ThingSpeak. Enter True in the Retained block and then specify the Message (cm is a variable in which the distance from the ultrasonic module is stored).
Step 36
Run the simulation.
Step 37
The left button is used to decrease the distance and the right button is used to increase the distance.
Step 38
The distance measures achieved by simulating the ultrasonic sensor are visualized on ThingSpeak.
For practical implementation, check out this video