Pages

Monday, 16 September 2019

ESP32-MQTT

ESP32-MQTT

Aim:
To interface Wi-Fi module with ESP32 to receive data from cloud using RDL ESP32 Development board.

Description:

Interfacing wi-fi module with the cloud MQTT to receive and send data using ESP32 microcontroller.

Hardware required:

ESP32-Microcontroller development board.

Pin connection:


Procedure:

Uploading and Receiving Data from Cloud using ESP32

1.        Create an Account in www.cloudmqtt.com




2.        Create an instance which will be used in the program to publish data to the cloud.






3.    Select the Instance name (test_1) and use the details of the same in the code. Include the code.


5.        Enter the details given under server, port, user, ssl port in the given program.


const char* mqttServer =”m16.mqtt.com”; const int mqttPort = 18215;
const char* mqttUser = “ofmydmjh”;;
const char* mqttPassword = “c5goIEjTCGRn”;
6.        In order to send a message to the CloudMQTT, include the line client.publish("topic_name", "Message");

7.        To send data from CloudMQTT ,include the line client.subscribe("Topic_name");\


5.        8. The following code prints the received data from the cloud in the Serial Monitor                      void callback(char* topic, byte* payload, unsigned int length)
{
uint8_t s;
Serial.print("Message arrived in topic: "); 
Serial.println(topic); Serial.print("Message:");
for (int i = 0; i < length; i++)
{
s= payload[i]; 
Serial.write(s);
}
}

5.        The final Program:

#include <WiFi.h>
#include <PubSubClient.h> const char* ssid = "userid";
const char* password = "*********";
/* Details from the instance created */
const char* mqttServer = "m16.cloudmqtt.com"; const int mqttPort = 18215;
const char* mqttUser = "ofmydmjh";
const char* mqttPassword = "c5g0IEjTCGRn"; WiFiClient espClient;
PubSubClient client(espClient); void setup(void)
{
Serial.begin(115200); WiFi.begin(ssid, password);
/* Connecting ESP8266 to WiFi */
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.write('.');
}
Serial.println("Connected to the WiFi network"); client.setServer(mqttServer, mqttPort); client.setCallback(callback);
/* Connecting to CloudMqtt */ while (!client.connected())
{
Serial.println("Connecting to MQTT...");
if (client.connect("ESP32Client", mqttUser, mqttPassword ))
{
Serial.println("connected");
}
else
{
Serial.print("failed with state "); Serial.print(client.state()); delay(2000);
}
}
/* Sending message to Topic "test1" */ client.publish("ABC", "Hello from RDL_IOT");
client.subscribe("test"); //Receives message sent to the topic "test"
}
/* This function is used to print the incoming data sent to the topic "test" */ void callback(char* topic, byte* payload, unsigned int length)
{
uint8_t s;
Serial.print("Message arrived in topic: "); Serial.println(topic); Serial.print("Message:");
for (int i = 0; i < length; i++)
{
s= payload[i];
Serial.write(s);
}
}

void loop(void)
{
client.loop();
}


Output:

ESP32-IR(Infrared) SENSOR

ESP32-IR(Infrared) SENSOR

Aim:
To extract information from IR sensor.

Description:

To learn how to read values from an IR sensor using ESP32-Microcontroller.

Hardware required:

ESP32-Microcontroller Development board,
IR sensor 

Pin connection:

Pin Mapping:

IR SENSOR
ESP32
5V
5V
GND
GND
A/O
IO12

Procedure:
1.        The above pin connection shows how to read values from a IR sensor using ESP32 board.
2.        Do the connections as shown in the pin diagram and pin mapping.
3.        Connect the USB cable to the board.
4.        Open Arduino IDE .Select DOIT ESP32 DEVKIT V1 in boards and select COM port.
5.        Verify the program and upload it.
6.        Now you can see the output on the serial monitor.


Program:

/* the setup function runs once when you press reset or power the board */ 
void setup(void)
{
/* initialize digital pin 12 as an input */ pinMode(12,INPUT);
Serial.begin(9600);
}

/* the loop function runs over and over again forever */ 
void loop(void)
{
int value=digitalRead(12); if(digitalRead(12)==HIGH)
{
Serial.print("no obstacle:"); Serial.println(value); delay(1000);
}
else if(digitalRead(12)==LOW)
{
Serial.print("obstacle present:"); Serial.println(value); delay(1000);
}
}

Output:

Sunday, 15 September 2019

ESP32-TEMPERATURE SENSOR

ESP32-TEMPERATURE SENSOR

Aim:
To extract information from temperature sensor.

Description:

To learn how to read values from a temperature sensor connected to analog pin using ESP32- Microcontroller.

Hardware required:

ESP32-Microcontroller Development board Temperature sensor.

Pin connection:

Pin Mapping:

TEMPERARUTE SENSOR
ESP32
5V
5V
GND
GND
A/O
IO35

Procedure:
1.        The above pin connection shows how to read values from a sensor using ESP32 board.
2.        Do the connections as shown in the pin diagram and pin mapping.
3.        Connect the USB cable to the board.
4.        Open Arduino IDE .Select DOIT ESP32 DEVKIT V1in boards and select COM port.
5.        Verify the program and Upload it.
6.        Now you can see the output on the serial monitor.

PROGRAM:

float temp; 
float value; 
float valuec;
int tempPin = 35;

void setup() 
{
Serial.begin(9600);
}

void loop() {
temp = analogRead(tempPin);
// read analog volt from sensor and save to variable temp 
value=( temp/2048.0)*3300;
valuec=value*0.1;                      //converts to degree celsius
// convert the analog volt to its temperature equivalent Serial.print("temperature in C = "); 
Serial.println(valuec); // display temperature value Serial.println();
Serial.print("temperature = ");
Serial.println(value);
delay(1000); // update sensor reading each one second
}

Output:


ESP32-VIBRATION SENSOR

ESP32-VIBRATION SENSOR

Aim:
To extract information from vibration sensor.

Description:

To learn how to read values from a vibration sensor connected to analog pin using ESP32- Microcontroller.

Hardware required:

ESP32-Microcontroller Development board Vibration sensor.

Pin connection:


Pin Mapping:

VIBRATION SENSOR
ESP32
5V
5V
GND
GND
A/O
IO12
Procedure:
1.        The above pin connection shows how to read values from a vibration sensor using ESP32 board.
2.        Do the connections as shown in the pin diagram and pin mapping.
3.        Connect the USB cable to the board.
4.        Open Arduino IDE .Select DOIT ESP32 DEVKIT V1 in boards and select COM port.
5.        Verify the program and upload it.
6.        Now you can see the output on the serial monitor.

Program:

void setup()
{
pinMode(35INPUT);
Serial.begin(9600);
}

void loop()
{
int sensorvalue = analogRead(35); if(sensorvalue>1000)
{
Serial.print("Sensor value is : ");
Serial.println(sensorvalue); 
delay(2000);
}
}

Output:




Friday, 13 September 2019

ESP32-OLED

ESP32-OLED
Aim:

This experiment shows how to display the message on OLED using ESP32-Microcontroller.

Description:

To display message on OLED screen. 

Hardware required:

ESP32-Microcontroller Development board

Pin connection:

Pin Mapping:

OLED
ESP32
5V
5V
SCL
IO22
SDA
IO21
Procedure:
1.        The above pin connection shows how to interface OLED with ESP32 board.
2.        Do the connections as shown in the pin diagram and pin mapping.
3.        Connect the USB cable to the board.
4.        Open Arduino IDE .Select DOIT ESP32 DEVKIT V1in boards and select COM port.
5.        Verify the program and Upload it.
6.    Now you can see the output displaying the message on OLED of ESP32 microcontroller board.

Program:

#include<Wire.h> #include"SSD1306.h"
/* SDA=21,SCL=22 */
SSD1306 display(0x3c,21,22); void setup(void)
{

display.init();
/* display message in OLED */ display.drawString(0,0,"RDL Technologies PVT. LTD."); display.display();
}

void loop(void)
{

}

Output: