Professional Documents
Culture Documents
ESP32
ESP32
• The ESP32 has fifteen 12-bit ADC input channels. These are GPIOs that can
be used to convert the analog voltage on the pin to a digital number.
• The ADC on the ESP32 is a 12-bit ADC meaning it has the ability to detect
4096 (212) discrete analog levels.
• In other words, it will map input voltages between 0 and the operating
voltage 3.3V into integer values between 0 and 4095.
• For example, this yields a resolution between readings of: 3.3 volts / 4096
units or, 0.0008 volts (0.8 mV) per unit.
DAC Pins
• The ESP32 features two 8-bit DAC channels that can be used to convert
digital signals into analog voltages. It can be used as a “digital
potentiometer” to control analog devices.
• This dual-DAC on the ESP32 has 8-bit resolution, which means that values
between 0 and 256 will produce an analog voltage somewhere between 0
and 3.3V.
Capacitive touch GPIOs
• The ESP32 has 10 internal capacitive touch sensors. These can sense
variations in anything that holds an electrical charge, like the human skin.
So they can detect variations induced when touching the GPIOs with a
finger.
ESP32 function block diagram.
Wireless Connectivity:
• Processors:
• CPU: Xtensa dual-core (or single-core) 32-bit microprocessor,
operating at 160 or 240 MHz and performing at up to 600 DMIPS
• Ultra low power (ULP) co-processor
Controlling LED
• It comes with a built-in blue LED that is internally connected to GPIO 2.
void setup() {
// put your setup code here, to run once:
pinMode(2,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
delay(1000);
}
ESP32 Door Sensor
void loop() {
// put your main code here, to run repeatedly:
int sw_status = digitalRead(16);
if(sw_status == HIGH)
Serial.println("OPEN");
else
Serial.println("CLOSED");
delay(1000);
}
Soil Moisture sensor
}
Get the Values from Firebase
Steps:
1. call getInt() function
Syntax: Firebase.getInt (firebaseData,"IOTLAB/LEDCONTROL")
•These functions return a boolean value indicating the success of the operation, if the data
types matched between request and response.
2. Then, check if the data type is an integer with firebaseData.dataType()
3. Finally, the firebaseData.intData() gets the value stored in that node.
EX:
if ( Firebase.getInt(firebaseData,"IOTLAB/LEDCONTROL"))
{
if (firebaseData.dataType()=="int")
{
finalCmd = firebaseData.intData();
}
}
#include <WiFi.h> //Connecting to Wi-Fi network
#include "FirebaseESP32.h" WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("Connecting to Wi-Fi");
#define FIREBASE_HOST “xxxxxxxx" //Do not
include https:// in FIREBASE_HOST while (WiFi.status() != WL_CONNECTED)
{
#define FIREBASE_AUTH “xxxxxxxx"
Serial.print(".");
#define WIFI_SSID "Bhargavi" delay(300);
#define WIFI_PASSWORD “xxxxx" }
//Define Firebase Data object Serial.println();
FirebaseData firebaseData; Serial.print("Connected with IP: ");
int delayTime = 2000; Serial.println(WiFi.localIP());
Serial.println();
void setup() {
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
Firebase.reconnectWiFi(true);
pinMode(2,OUTPUT);
Serial.begin(115200); }
void loop() { if(finalCmd == 1)
// put your main code here, to run repeatedly: {
digitalWrite(2,HIGH);
Serial.println("LED ON");
int finalCmd;
Firebase.setString(firebaseData,"IOTLAB/LED STATUS","LED
if ( ON");
}
Firebase.getInt(firebaseData,"IOTLAB/LEDCON else
TROL")) {
{ digitalWrite(2,LOW);
Serial.println("LED OFF");
if (firebaseData.dataType()=="int")
Firebase.setString(firebaseData,"IOTLAB/LED
{ STATUS","LED OFF");
finalCmd = firebaseData.intData(); }
}
delay(2000);
} }
#include "SSD1306.h" void setup() {
SSD1306 display(0x3c,21,22); pinMode(trigPin, OUTPUT); // Sets the
// defines pins numbers trigPin as an Output
const int trigPin = 25; pinMode(echoPin, INPUT); // Sets the
echoPin as an Input
const int echoPin = 26;
Serial.begin(115200); // Starts the
// defines variables serial communication
long duration; OLEDInit();
int distance; }
void OLEDInit();
void OLEDUpdate();
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
void loop() { Serial.println(distance);
// Clears the trigPin OLEDUpdate();
digitalWrite(trigPin, LOW);
delay(1000);
delayMicroseconds(2);
}
// Sets the trigPin on HIGH state for 10 micro seconds void OLEDInit(){
digitalWrite(trigPin, HIGH); display.init();
delayMicroseconds(10);
digitalWrite(trigPin, LOW); display.setFont(ArialMT_Plain_24);
}
// Reads the echoPin, returns the sound wave travel void OLEDUpdate(){
time in microseconds
String d = String(distance) + " cm";
duration = pulseIn(echoPin, HIGH);
display.clear();
// Calculating the distance display.drawString(30,0,d);
distance= duration*0.034/2; display.display();
}
Ultrasonic Sensor -Firebase
delayMicroseconds(10);
delay(1000);
digitalWrite(trigPin, LOW); }