You are on page 1of 4

BITE403P - EMBEDDED SYSTEMS AND IOT LAB

LAB PROGRAMS
L29+L30 & L39+L40 – 04 JULY 2023

1. esp8266 – NodeMCU1.0- Ultrasonic Sensor

STEP 1

Install cp2102 driver to the system for serial communication

STEP 2

Select File Preferences: Add the below URL for Additional Boards

http://arduino.esp8266.com/stable/package_esp8266com_index.json

STEP 3

SELECT Tools and Boards – Board manager

Then Search for

ESP8266 COMMUNITY

Click Install

STEP 4

Select Sketch – Include Library

Search

Thingspeak mathworks

Click Install

STEP 5

Select – Tools – Boards – esp8266 – NodeMCU1.0

Then Select Port

**************************************************************

https://electronics-project-hub.com/send-ultrasonic-sensor-data-to-thingspeak/

https://www.instructables.com/How-to-Program-NodeMCU-on-Arduino-IDE/
Ultrasonic Sensor
Trig pin - D0 – GPIO16
Echo pin - D1 –GPIO5

STEP 6

Create Free Account in thingspeak.com

Then click Channel – New Channel

Then Channel Settings - Fill

Name –Ultrasonic Sensor

Field 1 –ultrasonic Sensor

Then Save Channel

Step 7

Then click API Keys in thingspeak.com

Copy Write API Key and copy in code

Step 8

Give Wi-Fi user name and Password in the code

Step 9

Fill Channelfield in code as below


long myChannelField = 123456 - Copy from Thingspeak

myWriteAPIKey = "xxxxxxxxxxx” - Copy From Thingspeak

Run the code mentioned below after completing Hardware Connection

//Program

#include "ThingSpeak.h"
#include <ESP8266WiFi.h>

//----------- Enter you Wi-Fi Details---------//


char ssid[] = "xxxxxxxx"; //SSID
char pass[] = "yyyyyyyy"; // Password
//-------------------------------------------//

const int trigger = 16;


const int echo = 5;
long T;
float distanceCM;
WiFiClient client;

unsigned long myChannelField = 123456; // Channel ID


const int ChannelField = 1; // Which channel to write data
const char * myWriteAPIKey = "xxxxxxxxxxx"; // Your write API Key

void setup()
{
Serial.begin(9600);
pinMode(trigger, OUTPUT);
pinMode(echo, INPUT);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void loop()
{
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
while (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, pass);
Serial.print(".");
delay(5000);
}
Serial.println("\nConnected.");
}
digitalWrite(trigger, LOW);
delay(1);
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
digitalWrite(trigger, LOW);
T = pulseIn(echo, HIGH);
distanceCM = T * 0.034;
distanceCM = distanceCM / 2;
Serial.print("Distance in cm: ");
Serial.println(distanceCM);
ThingSpeak.writeField(myChannelField, ChannelField, distanceCM, myWriteAPIKey);
delay(1000);
}

2. esp826- nodemcu send messages to whatsapp

https://randomnerdtutorials.com/esp8266-nodemcu-send-messages-whatsapp/

3. Create A Simple ESP8266 NodeMCU Web Server In Arduino IDE

https://lastminuteengineers.com/creating-esp8266-web-server-arduino-ide/

You might also like