SlideShare a Scribd company logo
1. LED Interface with ESP32:
int LED = 2; // Assign LED to pin GPIO2(D2)
void setup() {
pinMode (LED, OUTPUT); //Configure LED pin as output
}
void loop() {
digitalWrite(LED, HIGH); //Command to turn ON LED
delay(1000); //1 Second delay
digitalWrite(LED, LOW); //Command to turn OFF LED
delay(1000); //1 Second delay
}
2. LED Interface with ESP32 using Relay:
int LED = 26; // Assign LED to pin GPIO26(D26)
void setup() {
pinMode (LED, OUTPUT); //Configure LED pin as output
}
void loop() {
digitalWrite(LED, HIGH); //Command to turn ON LED
delay(1000); //1 Second delay
digitalWrite(LED, LOW); //Command to turn OFF LED
delay(1000); //1 Second delay
}
Simulation Output:
ESP32 Component Connection Pin
GPIO26 (D26) Relay Coil one end
GND Relay Coil another end
Vin COM pin of Relay
- NO pin of Relay Connected to LED Anode
GND Connected to LED Cathode with resistor
3. ESP32 Switch & LED:
const int BUTTON = 5; //Connect button to D5
const int LED1=4; //Connect LED to D4
int ledState = LOW; //Default state of LED is low
int previousButtonState;
int presentButtonState;
void setup()
{
pinMode(BUTTON,INPUT); //Configure Button as input
pinMode(LED1, OUTPUT); //Configure LED as output
}
void loop()
{
presentButtonState = digitalRead(BUTTON);
if(presentButtonState==HIGH) //If Button state is high
{
digitalWrite(LED1, HIGH); //Turn ON LED
}
else //If button state is low
{
digitalWrite(LED1, LOW); //Turn LOW LED
}
}
4. Ultrasonic sensor simulation
const int trigPin = 5;
const int echoPin = 18;
//define sound speed in cm/uS
#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701
long duration;
float distanceCm;
float distanceInch;
void setup() {
Serial.begin(115200); // Starts the serial communication
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculate the distance
distanceCm = duration * SOUND_SPEED/2;
// Convert to inches
distanceInch = distanceCm * CM_TO_INCH;
// Prints the distance in the Serial Monitor
Serial.print("Distance (cm): ");
Serial.println(distanceCm);
Serial.print("Distance (inch): ");
Serial.println(distanceInch);
delay(1000);
}
5. ldr Interfacing
int sens=27;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
}
void loop() {
sens=analogRead(27);
Serial.println(sens);
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}
6. #include <ESP32Servo.h> //Header file for servomotor API
Servo servo; //Assign a variable “servo” of data type “Servo”
void setup() {
servo.attach(2); //Attach the servo motor to GPIO2
servo.write(0); //Make the position of servomotor as 0
delay(2000); //2 second delay
}
void loop() {
servo.write(180); //Rotate servomotor to 180 degree
delay(1000); //1Second delay
servo.write(0); //Rotate back the servomotor to 0 degree
delay(1000); //1 Second delay
}

More Related Content

PDF
Arduino and Robotics
PPTX
Mims effect
PPTX
Blind stick project on robotics covering basics.pptx
PPTX
Computer networks unit III CHAPTER of frameworks
PDF
The IoT Academy IoT training Arduino Part 5 Arduino peripherals
PPTX
Arduino Programming
PDF
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
PDF
Arduino based applications part 1
Arduino and Robotics
Mims effect
Blind stick project on robotics covering basics.pptx
Computer networks unit III CHAPTER of frameworks
The IoT Academy IoT training Arduino Part 5 Arduino peripherals
Arduino Programming
Arduino: Arduino para dummies 2 edición por Wiley Brand parte 2
Arduino based applications part 1

Similar to IOT excercise ESP32 Simulation projects.docx (20)

PDF
Arduino Workshop 2011.05.31
PPTX
Introduction to Arduino
PPTX
Introduction to Arduino
PPTX
Sensors and Actuators in Arduino, Introduction
PDF
PDF
Combine the keypad and LCD codes in compliance to the following requ.pdf
PPTX
Embedded Systems Lab Practical PowerPoint presentation with source code
PPTX
introduction to ARM C programming language
PPTX
INTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNO
PDF
L6 Visual Output LED_7SEGMEN_LEDMATRIX upate.pdf
PDF
L6 Visual Output LED_7SEGMEN_LEDMATRIX upate.pdf
PDF
Arduino uno basic Experiments for beginner
PPTX
Distance measurement using Ultrasonic sensor on Arduino Uno
PDF
Gaztea Tech Robotica 2016
PPTX
Arduino intro.pptx
PPT
Unit 4 Part I.ppt this contains notes for
PPTX
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
PDF
MK1_Addendum
PDF
Arduino projects &amp; tutorials
PPTX
Arduino cic3
Arduino Workshop 2011.05.31
Introduction to Arduino
Introduction to Arduino
Sensors and Actuators in Arduino, Introduction
Combine the keypad and LCD codes in compliance to the following requ.pdf
Embedded Systems Lab Practical PowerPoint presentation with source code
introduction to ARM C programming language
INTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNO
L6 Visual Output LED_7SEGMEN_LEDMATRIX upate.pdf
L6 Visual Output LED_7SEGMEN_LEDMATRIX upate.pdf
Arduino uno basic Experiments for beginner
Distance measurement using Ultrasonic sensor on Arduino Uno
Gaztea Tech Robotica 2016
Arduino intro.pptx
Unit 4 Part I.ppt this contains notes for
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
MK1_Addendum
Arduino projects &amp; tutorials
Arduino cic3
Ad

Recently uploaded (20)

PPTX
Nanokeyer nano keyekr kano ketkker nano keyer
PPTX
ERP good ERP good ERP good ERP good good ERP good ERP good
DOCX
A PROPOSAL ON IoT climate sensor 2.docx
PDF
How NGOs Save Costs with Affordable IT Rentals
PPTX
Sem-8 project ppt fortvfvmat uyyjhuj.pptx
PPT
FABRICATION OF MOS FET BJT DEVICES IN NANOMETER
PPTX
5. MEASURE OF INTERIOR AND EXTERIOR- MATATAG CURRICULUM.pptx
PPTX
Entre CHtzyshshshshshshshzhhzzhhz 4MSt.pptx
PPTX
making presentation that do no stick.pptx
PDF
Layer23-Switch.com The Cisco Catalyst 9300 Series is Cisco’s flagship stackab...
PPTX
1.pptxsadafqefeqfeqfeffeqfqeqfeqefqfeqfqeffqe
PPTX
sdn_based_controller_for_mobile_network_traffic_management1.pptx
PPTX
Wireless and Mobile Backhaul Market.pptx
PPTX
Fundamentals of Computer.pptx Computer BSC
PPTX
STEEL- intro-1.pptxhejwjenwnwnenemwmwmwm
PPT
chapter_1_a.ppthduushshwhwbshshshsbbsbsbsbsh
PPTX
Embeded System for Artificial intelligence 2.pptx
PPTX
code of ethics.pptxdvhwbssssSAssscasascc
PPTX
Prograce_Present.....ggation_Simple.pptx
PPTX
material for studying about lift elevators escalation
Nanokeyer nano keyekr kano ketkker nano keyer
ERP good ERP good ERP good ERP good good ERP good ERP good
A PROPOSAL ON IoT climate sensor 2.docx
How NGOs Save Costs with Affordable IT Rentals
Sem-8 project ppt fortvfvmat uyyjhuj.pptx
FABRICATION OF MOS FET BJT DEVICES IN NANOMETER
5. MEASURE OF INTERIOR AND EXTERIOR- MATATAG CURRICULUM.pptx
Entre CHtzyshshshshshshshzhhzzhhz 4MSt.pptx
making presentation that do no stick.pptx
Layer23-Switch.com The Cisco Catalyst 9300 Series is Cisco’s flagship stackab...
1.pptxsadafqefeqfeqfeffeqfqeqfeqefqfeqfqeffqe
sdn_based_controller_for_mobile_network_traffic_management1.pptx
Wireless and Mobile Backhaul Market.pptx
Fundamentals of Computer.pptx Computer BSC
STEEL- intro-1.pptxhejwjenwnwnenemwmwmwm
chapter_1_a.ppthduushshwhwbshshshsbbsbsbsbsh
Embeded System for Artificial intelligence 2.pptx
code of ethics.pptxdvhwbssssSAssscasascc
Prograce_Present.....ggation_Simple.pptx
material for studying about lift elevators escalation
Ad

IOT excercise ESP32 Simulation projects.docx

  • 1. 1. LED Interface with ESP32: int LED = 2; // Assign LED to pin GPIO2(D2) void setup() { pinMode (LED, OUTPUT); //Configure LED pin as output } void loop() { digitalWrite(LED, HIGH); //Command to turn ON LED delay(1000); //1 Second delay digitalWrite(LED, LOW); //Command to turn OFF LED delay(1000); //1 Second delay } 2. LED Interface with ESP32 using Relay: int LED = 26; // Assign LED to pin GPIO26(D26) void setup() { pinMode (LED, OUTPUT); //Configure LED pin as output } void loop() { digitalWrite(LED, HIGH); //Command to turn ON LED delay(1000); //1 Second delay digitalWrite(LED, LOW); //Command to turn OFF LED delay(1000); //1 Second delay } Simulation Output: ESP32 Component Connection Pin GPIO26 (D26) Relay Coil one end GND Relay Coil another end Vin COM pin of Relay - NO pin of Relay Connected to LED Anode GND Connected to LED Cathode with resistor
  • 2. 3. ESP32 Switch & LED: const int BUTTON = 5; //Connect button to D5 const int LED1=4; //Connect LED to D4 int ledState = LOW; //Default state of LED is low int previousButtonState; int presentButtonState; void setup() { pinMode(BUTTON,INPUT); //Configure Button as input pinMode(LED1, OUTPUT); //Configure LED as output } void loop() { presentButtonState = digitalRead(BUTTON); if(presentButtonState==HIGH) //If Button state is high { digitalWrite(LED1, HIGH); //Turn ON LED } else //If button state is low { digitalWrite(LED1, LOW); //Turn LOW LED } } 4. Ultrasonic sensor simulation const int trigPin = 5;
  • 3. const int echoPin = 18; //define sound speed in cm/uS #define SOUND_SPEED 0.034 #define CM_TO_INCH 0.393701 long duration; float distanceCm; float distanceInch; void setup() { Serial.begin(115200); // Starts the serial communication pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); // Sets the echoPin as an Input } void loop() { // Clears the trigPin digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds duration = pulseIn(echoPin, HIGH); // Calculate the distance distanceCm = duration * SOUND_SPEED/2; // Convert to inches distanceInch = distanceCm * CM_TO_INCH; // Prints the distance in the Serial Monitor Serial.print("Distance (cm): "); Serial.println(distanceCm); Serial.print("Distance (inch): "); Serial.println(distanceInch); delay(1000); } 5. ldr Interfacing
  • 4. int sens=27; void setup() { // put your setup code here, to run once: Serial.begin(115200); Serial.println("Hello, ESP32!"); } void loop() { sens=analogRead(27); Serial.println(sens); // put your main code here, to run repeatedly: delay(10); // this speeds up the simulation } 6. #include <ESP32Servo.h> //Header file for servomotor API Servo servo; //Assign a variable “servo” of data type “Servo” void setup() { servo.attach(2); //Attach the servo motor to GPIO2 servo.write(0); //Make the position of servomotor as 0 delay(2000); //2 second delay } void loop() { servo.write(180); //Rotate servomotor to 180 degree delay(1000); //1Second delay servo.write(0); //Rotate back the servomotor to 0 degree delay(1000); //1 Second delay }