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
}
Ad

More Related Content

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

Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Amarjeetsingh Thakur
 
Introduction to Arduino
Introduction to ArduinoIntroduction to Arduino
Introduction to Arduino
Amarjeetsingh Thakur
 
Sensors and Actuators in Arduino, Introduction
Sensors and Actuators in Arduino, IntroductionSensors and Actuators in Arduino, Introduction
Sensors and Actuators in Arduino, Introduction
BibekPokhrel13
 
robotics presentation for a club you run
robotics presentation for a club you runrobotics presentation for a club you run
robotics presentation for a club you run
SunilAcharya37
 
Lab5
Lab5Lab5
Lab5
Nathan Wendt
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
forwardcom41
 
introduction to ARM C programming language
introduction to ARM C programming languageintroduction to ARM C programming language
introduction to ARM C programming language
Pratik Gohel
 
INTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNO
INTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNOINTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNO
INTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNO
vasankarponnapalli2
 
Arduino uno basic Experiments for beginner
Arduino uno basic Experiments for beginnerArduino uno basic Experiments for beginner
Arduino uno basic Experiments for beginner
YogeshJatav7
 
Distance measurement using Ultrasonic sensor on Arduino Uno
Distance measurement using Ultrasonic sensor on Arduino UnoDistance measurement using Ultrasonic sensor on Arduino Uno
Distance measurement using Ultrasonic sensor on Arduino Uno
Aswin KP
 
Arduino intro.pptx
Arduino intro.pptxArduino intro.pptx
Arduino intro.pptx
SanthanaMari11
 
Unit 4 Part I.ppt this contains notes for
Unit 4 Part I.ppt this contains notes forUnit 4 Part I.ppt this contains notes for
Unit 4 Part I.ppt this contains notes for
vaishnavibhapkar1207
 
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Irfan Qadoos
 
MK1_Addendum
MK1_AddendumMK1_Addendum
MK1_Addendum
Brandon Hargrave
 
Arduino projects &amp; tutorials
Arduino projects &amp; tutorialsArduino projects &amp; tutorials
Arduino projects &amp; tutorials
Anshu Pandey
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
Jeni Shah
 
Mom presentation_monday_arduino in the physics lab
Mom presentation_monday_arduino in the physics labMom presentation_monday_arduino in the physics lab
Mom presentation_monday_arduino in the physics lab
Annamaria Lisotti
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
The IOT Academy
 
Arduino: Analog I/O
Arduino: Analog I/OArduino: Analog I/O
Arduino: Analog I/O
June-Hao Hou
 
(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-program(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-program
Dimz I
 
Sensors and Actuators in Arduino, Introduction
Sensors and Actuators in Arduino, IntroductionSensors and Actuators in Arduino, Introduction
Sensors and Actuators in Arduino, Introduction
BibekPokhrel13
 
robotics presentation for a club you run
robotics presentation for a club you runrobotics presentation for a club you run
robotics presentation for a club you run
SunilAcharya37
 
Combine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdfCombine the keypad and LCD codes in compliance to the following requ.pdf
Combine the keypad and LCD codes in compliance to the following requ.pdf
forwardcom41
 
introduction to ARM C programming language
introduction to ARM C programming languageintroduction to ARM C programming language
introduction to ARM C programming language
Pratik Gohel
 
INTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNO
INTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNOINTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNO
INTODUCTION OF IOT AND INTERFACING WITH ARDUINO UNO
vasankarponnapalli2
 
Arduino uno basic Experiments for beginner
Arduino uno basic Experiments for beginnerArduino uno basic Experiments for beginner
Arduino uno basic Experiments for beginner
YogeshJatav7
 
Distance measurement using Ultrasonic sensor on Arduino Uno
Distance measurement using Ultrasonic sensor on Arduino UnoDistance measurement using Ultrasonic sensor on Arduino Uno
Distance measurement using Ultrasonic sensor on Arduino Uno
Aswin KP
 
Unit 4 Part I.ppt this contains notes for
Unit 4 Part I.ppt this contains notes forUnit 4 Part I.ppt this contains notes for
Unit 4 Part I.ppt this contains notes for
vaishnavibhapkar1207
 
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Temperature Sensor with LED matrix Display BY ►iRFAN QADOOS◄ 9
Irfan Qadoos
 
Arduino projects &amp; tutorials
Arduino projects &amp; tutorialsArduino projects &amp; tutorials
Arduino projects &amp; tutorials
Anshu Pandey
 
Arduino cic3
Arduino cic3Arduino cic3
Arduino cic3
Jeni Shah
 
Mom presentation_monday_arduino in the physics lab
Mom presentation_monday_arduino in the physics labMom presentation_monday_arduino in the physics lab
Mom presentation_monday_arduino in the physics lab
Annamaria Lisotti
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
The IOT Academy
 
Arduino: Analog I/O
Arduino: Analog I/OArduino: Analog I/O
Arduino: Analog I/O
June-Hao Hou
 
(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-program(381877808) 102054282 5-listing-program
(381877808) 102054282 5-listing-program
Dimz I
 

Recently uploaded (20)

Intro to Windows Presentation for CSS NC-2.pptx
Intro to Windows Presentation for CSS NC-2.pptxIntro to Windows Presentation for CSS NC-2.pptx
Intro to Windows Presentation for CSS NC-2.pptx
HelenAvila17
 
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctr
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctrMayur Seminar.pptxbgvyezuvdt as bijvyivutctr
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctr
vaishnavishitole195
 
Lecture 1 BASIC TERMINOLOGY of kinematics.ppt
Lecture 1 BASIC TERMINOLOGY of kinematics.pptLecture 1 BASIC TERMINOLOGY of kinematics.ppt
Lecture 1 BASIC TERMINOLOGY of kinematics.ppt
MusniAhmed1
 
Unidad Pedagogica 3ro-4to.documento090904
Unidad Pedagogica 3ro-4to.documento090904Unidad Pedagogica 3ro-4to.documento090904
Unidad Pedagogica 3ro-4to.documento090904
maylingcastro9
 
Concavity_Presentation_Updated.pptx rana
Concavity_Presentation_Updated.pptx ranaConcavity_Presentation_Updated.pptx rana
Concavity_Presentation_Updated.pptx rana
ranamumtaz383
 
TR INGLES TECNICO ECCU-211 1[mmmm1].pptx
TR INGLES TECNICO ECCU-211 1[mmmm1].pptxTR INGLES TECNICO ECCU-211 1[mmmm1].pptx
TR INGLES TECNICO ECCU-211 1[mmmm1].pptx
EnocngelArcentalesVa
 
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdfchapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
edget1
 
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptxCrim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
russelrosas
 
网上可查学历(美国CU毕业证)康伯斯威尔大学假毕业证
网上可查学历(美国CU毕业证)康伯斯威尔大学假毕业证网上可查学历(美国CU毕业证)康伯斯威尔大学假毕业证
网上可查学历(美国CU毕业证)康伯斯威尔大学假毕业证
Taqyea
 
Ch 2 The Microprocessor and its Architecture.ppt
Ch 2 The Microprocessor and its Architecture.pptCh 2 The Microprocessor and its Architecture.ppt
Ch 2 The Microprocessor and its Architecture.ppt
ermiasgesgis
 
REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682
REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682
REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682
REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682
 
Week 2 lecture PCD 203skoacolacbabolabiocasoc
Week 2 lecture PCD 203skoacolacbabolabiocasocWeek 2 lecture PCD 203skoacolacbabolabiocasoc
Week 2 lecture PCD 203skoacolacbabolabiocasoc
saidraqb5
 
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptxParmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
rahulrajbanshi981052
 
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
v65176016
 
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdfENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
edget1
 
Ricoh-Aficio-MP-301SP--301SPF-Parts-Catalog-Europe-66d777e9c05a1.pdf
Ricoh-Aficio-MP-301SP--301SPF-Parts-Catalog-Europe-66d777e9c05a1.pdfRicoh-Aficio-MP-301SP--301SPF-Parts-Catalog-Europe-66d777e9c05a1.pdf
Ricoh-Aficio-MP-301SP--301SPF-Parts-Catalog-Europe-66d777e9c05a1.pdf
MarioAlbertoAcostaAl
 
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptxFeed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
newhopemojokerto90
 
Musicfy lolMusicfy lolMusicfy lolMusicfy lol
Musicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lol
Musicfy lolMusicfy lolMusicfy lolMusicfy lol
bilalshah786104
 
JOINING ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON WHATSAPP+256782561496/0756...
JOINING ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON WHATSAPP+256782561496/0756...JOINING ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON WHATSAPP+256782561496/0756...
JOINING ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON WHATSAPP+256782561496/0756...
REAL ILLUMINATI UGANDA CALL WhatsApp number on0782561496/0756664682
 
Chapter Five main management of memory .ppt
Chapter Five main management of memory  .pptChapter Five main management of memory  .ppt
Chapter Five main management of memory .ppt
YoomifTube
 
Intro to Windows Presentation for CSS NC-2.pptx
Intro to Windows Presentation for CSS NC-2.pptxIntro to Windows Presentation for CSS NC-2.pptx
Intro to Windows Presentation for CSS NC-2.pptx
HelenAvila17
 
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctr
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctrMayur Seminar.pptxbgvyezuvdt as bijvyivutctr
Mayur Seminar.pptxbgvyezuvdt as bijvyivutctr
vaishnavishitole195
 
Lecture 1 BASIC TERMINOLOGY of kinematics.ppt
Lecture 1 BASIC TERMINOLOGY of kinematics.pptLecture 1 BASIC TERMINOLOGY of kinematics.ppt
Lecture 1 BASIC TERMINOLOGY of kinematics.ppt
MusniAhmed1
 
Unidad Pedagogica 3ro-4to.documento090904
Unidad Pedagogica 3ro-4to.documento090904Unidad Pedagogica 3ro-4to.documento090904
Unidad Pedagogica 3ro-4to.documento090904
maylingcastro9
 
Concavity_Presentation_Updated.pptx rana
Concavity_Presentation_Updated.pptx ranaConcavity_Presentation_Updated.pptx rana
Concavity_Presentation_Updated.pptx rana
ranamumtaz383
 
TR INGLES TECNICO ECCU-211 1[mmmm1].pptx
TR INGLES TECNICO ECCU-211 1[mmmm1].pptxTR INGLES TECNICO ECCU-211 1[mmmm1].pptx
TR INGLES TECNICO ECCU-211 1[mmmm1].pptx
EnocngelArcentalesVa
 
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdfchapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
chapter-11.pdfchapter-11.pdfchapter-11.pdfchapter-chapter-11.pdf.pdf
edget1
 
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptxCrim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
Crim-Proc-PPT-for-lecture-in-May-2025-Learners.pptx
russelrosas
 
网上可查学历(美国CU毕业证)康伯斯威尔大学假毕业证
网上可查学历(美国CU毕业证)康伯斯威尔大学假毕业证网上可查学历(美国CU毕业证)康伯斯威尔大学假毕业证
网上可查学历(美国CU毕业证)康伯斯威尔大学假毕业证
Taqyea
 
Ch 2 The Microprocessor and its Architecture.ppt
Ch 2 The Microprocessor and its Architecture.pptCh 2 The Microprocessor and its Architecture.ppt
Ch 2 The Microprocessor and its Architecture.ppt
ermiasgesgis
 
Week 2 lecture PCD 203skoacolacbabolabiocasoc
Week 2 lecture PCD 203skoacolacbabolabiocasocWeek 2 lecture PCD 203skoacolacbabolabiocasoc
Week 2 lecture PCD 203skoacolacbabolabiocasoc
saidraqb5
 
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptxParmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
Parmila_nsnsnjnsnsnnwDevi_Rajbanshi.pptx
rahulrajbanshi981052
 
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
Py-Slides-1.pptPy-Slides-1.pptPy-Slides-1.pptPy-Slides-1.ppt
v65176016
 
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdfENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
ENSA_Module_12 - Network Troubleshooting.pdfchapterchapter-11.pdf.pdf
edget1
 
Ricoh-Aficio-MP-301SP--301SPF-Parts-Catalog-Europe-66d777e9c05a1.pdf
Ricoh-Aficio-MP-301SP--301SPF-Parts-Catalog-Europe-66d777e9c05a1.pdfRicoh-Aficio-MP-301SP--301SPF-Parts-Catalog-Europe-66d777e9c05a1.pdf
Ricoh-Aficio-MP-301SP--301SPF-Parts-Catalog-Europe-66d777e9c05a1.pdf
MarioAlbertoAcostaAl
 
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptxFeed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
Feed sampling MLA&dfsfdsfdsfsdfPPLA.pptx
newhopemojokerto90
 
Musicfy lolMusicfy lolMusicfy lolMusicfy lol
Musicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lolMusicfy lol
Musicfy lolMusicfy lolMusicfy lolMusicfy lol
bilalshah786104
 
Chapter Five main management of memory .ppt
Chapter Five main management of memory  .pptChapter Five main management of memory  .ppt
Chapter Five main management of memory .ppt
YoomifTube
 
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 }
  翻译: