Showing posts with label Arduino ESP32. Show all posts
Showing posts with label Arduino ESP32. Show all posts

Friday, 27 November 2026

ECG, EEG, EMG and PPG Sensors: How They Work and How to Interface Them with ESP32

Standard

 

Your body is a quiet radio. The heart, brain, muscles, eyes, and skin all produce tiny electrical or optical signals. Hospitals read them with clinical machines. Makers now read a simplified version of the same idea with breakout boards and an ESP32. That does not make a hobby kit a medical device. It does make the signals learnable, if you put the right Analog Front-End (AFE) between the electrode and the microcontroller.

This post covers ten common electrical and physiological sensors: ECG, EEG, EMG, EOG, ERG, EGG, ENG, EDA/GSR, bioimpedance (BIA/ICG), and PPG. It then answers the practical question: can they all talk to an ESP32? Yes, with an AFE or a dedicated breakout. Direct electrode-to-GPIO wiring is how you get noise, bad data, and, if you stay plugged into mains, a safety problem (SparkFun, 2024; Texas Instruments, 2017).

Key Abbreviations in This Post

  • ECG (Electrocardiography): Electrical activity of the heart.
  • EEG (Electroencephalography): Brain-wave activity from the scalp.
  • EMG (Electromyography): Electrical activity of skeletal muscle.
  • EOG (Electrooculography): Potential changes around the eyes from eye movement.
  • ERG (Electroretinography): Electrical response of the retina to light.
  • EGG (Electrogastrography): Slow electrical rhythms of the stomach.
  • ENG (Electroneurography): Conduction along peripheral nerves, often with a stimulus.
  • EDA / GSR: Electrodermal activity / galvanic skin response. Skin conductance from sweat glands.
  • BIA / ICG: Bioimpedance analysis / impedance cardiography. How tissue resists a tiny AC current.
  • PPG (Photoplethysmography): Optical measure of blood-volume change, heart rate, and often SpO₂.
  • AFE (Analog Front-End): The amp, filter, and often ADC chip between electrodes and a microcontroller.
  • ESP32: Espressif Wi-Fi/BLE microcontroller family, common in battery-powered IoT projects.
  • ADC: Analog-to-digital converter. Turns a voltage into a number.

The One-Minute Version

  • Ten signals, two physics stories: most are biopotentials (microvolts to millivolts). PPG is light. BIA injects a safe AC current and measures impedance.
  • ESP32 can host all of them if an AFE or breakout sits in the middle. Never wire bare electrodes to ADC pins and call it done.
  • Easy start: AD8232 (ECG), MyoWare (EMG), BioAmp EXG (ECG/EMG/EOG/EEG-class), Grove GSR (EDA), MAX30102 (PPG).
  • Harder: EGG, BIA/ICG, ENG, ERG. Same ESP32, more specialized chips, filters, electrodes, or a stimulator.
  • Safety rule: while electrodes are on a person, power from a battery and send data over Wi-Fi or BLE. Unplug USB from the wall and from a charging laptop (SparkFun, 2024).
  • Scope: education, research prototypes, and wearables experiments. Not diagnosis or treatment.
Ten body signals: ECG EEG EMG EOG ERG EGG ENG EDA BIA PPG

What These Sensors Actually Measure

Clinicians group them by organ. Engineers group them by signal size and frequency. Both views help when you pick an AFE.

Signal, roughly where it lives, roughly how big Sensor Source Typical use Order of size ECG Heart muscle Rhythm, rate, waveform ~0.5 to 5 mV EEG Brain (scalp) Sleep, seizures, attention ~10 to 100 µV EMG Skeletal muscle Activation, fatigue, rehab ~50 µV to few mV EOG Eye dipole Gaze, blinks, REM sleep ~0.05 to 3.5 mV ERG Retina Photoreceptor response µV to low mV EGG Stomach Gastric slow waves ~100 to 500 µV ENG Peripheral nerve Conduction speed/strength µV range + stimulus EDA/GSR Sweat glands Stress, arousal Conductance change BIA/ICG Tissue / blood Composition, stroke volume Impedance ohms PPG Blood volume (light) HR, SpO₂, wearables Optical, not volts Rule of thumb Smaller and slower signals need more gain, quieter ADCs, and better filtering. EEG and EGG are harder than ECG. PPG is easiest for a first ESP32 wearable.
Body map of where ECG EEG EMG EOG and other biosignals are measured

Each Sensor, From Basics to Use

ECG: heart electricity

ECG records the depolarization wave as it moves through the atria and ventricles. A basic single-lead hobby setup shows rate and a rough QRS shape. A clinical 12-lead study maps the heart in more detail for ischemia and rhythm diagnosis (Goldberger et al., 2017). On an ESP32, the common module is the Analog Devices AD8232 heart-rate monitor front-end: three disposable electrodes, an analog output into an ADC pin (Analog Devices, 2012).

EEG: brain waves from the scalp

EEG is smaller than ECG by an order of magnitude or more. Frequency bands (delta, theta, alpha, beta, gamma) get used in sleep studies, epilepsy work, and research BCIs. A DIY board will not replace a clinical EEG lab. It can teach sampling, referencing, and how much 50/60 Hz mains noise lives on a scalp (Niedermeyer & Lopes da Silva, 2005). Multi-channel setups often use the TI ADS1299 over SPI.

EMG: muscle activation

Surface EMG listens to motor-unit firing under the skin. Rehab, gesture control, and sports science all use it. MyoWare-class modules rectify and smooth the signal into an envelope that an ESP32 can sample slowly. Raw EMG needs a wider bandwidth and a quieter front-end (Merletti & Parker, 2004; SparkFun, 2024).

EOG: eye movement

The eye is a dipole. Move the gaze, and the potential between electrodes near the canthi or above/below the eye changes. Sleep labs use EOG for REM. HCI experiments use it for blink and glance detection. Electrically it looks a lot like a slow ECG/EEG cousin, so BioAmp EXG or a re-filtered AD8232 often appears in maker builds.

ERG: retina response

ERG needs a light flash (or pattern) synchronized with the recording. Electrodes may be corneal or skin-based depending on the protocol. The electronics resemble other biopotential AFEs. The hard parts are optics, timing, and electrode type, not the ESP32 itself (McCulloch, 2019).

EGG: stomach rhythms

Gastric slow waves sit around a few cycles per minute. That means ultra-low-frequency filters (on the order of 0.01 to 0.5 Hz) and patience with motion artifact. You can reconfigure an ADS1299 or build an instrumentation-amp front-end. This is advanced DIY, not a weekend Amazon kit.

ENG: nerve conduction

ENG often stimulates a peripheral nerve and measures the compound action potential downstream. That means a safe, controlled stimulator plus a high-gain low-noise amp. An ESP32 can time the stimulus and log the response. Designing the stimulator is the real project, and safety review matters more than the Wi-Fi stack.

EDA / GSR: skin conductance

Sweat-gland activity changes how well the skin conducts. Stress and arousal studies use this a lot. Grove-style GSR modules are a voltage divider the ESP32 can read on an ADC pin. The signal is slow. Motion and electrode dryness matter more than sample rate.

BIA / ICG: bioimpedance

A tiny AC current is injected. The measured impedance relates to body composition (BIA) or, in thoracic setups, to blood-flow related changes (ICG). Chips such as Analog Devices AD5933 (I2C impedance converter) or Maxim MAX30001 (SPI) exist for this. Do not invent your own current-injection circuit without reading the safety limits in the datasheet (Analog Devices, 2017).

PPG: light, not electrodes

PPG shines LEDs into tissue and reads the reflected or transmitted light with a photodiode. Heart rate and SpO₂ wearables live here. MAX30102 / MAX30105 breakouts talk I2C to the ESP32 and are the friendliest first biosensor for most makers (Maxim Integrated, 2015).

ECG EEG EMG and EOG measurement sites on the body

Can an ESP32 Interface All of Them?

Yes, as a host. No, as a raw electrode ADC.

Biopotential amplitudes sit in the microvolt to millivolt range. The ESP32's GPIO and on-chip ADC expect volts-scale swings and are noisy near the rails. The missing piece is an AFE: gain, filtering, often driven-right-leg or bias, and preferably a dedicated ADC. Optical and impedance sensors already ship as digital breakouts, so the ESP32 only needs I2C or SPI (Espressif, 2023; Texas Instruments, 2017).

Problem: a student clips ECG electrodes to GPIO36 and sees garbage.
Cause: the heart signal is about a millivolt, buried in electrode offset and mains hum.
Effect: they blame the ESP32. Add an AD8232 (or better, a digital AFE), battery power, and a notch or digital filter. The waveform appears.

Electrodes to AFE to ESP32 signal chain
ESP32 biosensor stack from electrodes through AFE to wireless dashboard

Easy to Interface: Plug-and-Play Modules

These have hobbyist boards that speak analog, I2C, or SPI to an ESP32 without a custom PCB.

  • ECG: AD8232 (analog out) or MAX30003 (SPI digital AFE).
  • EMG: MyoWare 2.0, Gravity Analog EMG, BioAmp EXG Pill (analog).
  • EEG: BioAmp EXG Pill for single-channel experiments; TGAM-class modules; ADS1299 for multi-channel SPI.
  • EOG: BioAmp EXG Pill, or AD8232 with filter parts retuned for slower eye signals.
  • EDA / GSR: Grove GSR and similar voltage-divider modules (analog).
  • PPG: MAX30102 / MAX30105 (I2C).

MyoWare 2.0 even has an official wireless shield with an ESP32-WROOM and a LiPo, built so the muscle sensor can run isolated from the wall (SparkFun, 2024). That pattern is the right mental model for the whole list: battery on the body, radio off the body.

Plug-and-play biosensor modules for ESP32 including AD8232 MyoWare and MAX30102

Advanced: Custom Front Ends

  • EGG: ultra-low-frequency filtering. AD620-class instrumentation amp or a carefully configured ADS1299.
  • BIA / ICG: AD5933 (I2C) or MAX30001 (SPI) to inject and measure AC safely.
  • ENG: high-gain amp (INA128 / ADS1299 class) plus a synchronized stimulator. Treat stimulus current as a safety design, not a GPIO hack.
  • ERG: EEG/EOG-like electronics, plus specialized electrodes and a timed light flash.

The ESP32 still fits. The bill of materials and the validation plan get longer.

Harder biosensors: EGG BIA ENG and ERG with specialized hardware

ESP32 Tips That Actually Matter

1. Treat the built-in ADC as a last resort

The ESP32 on-chip 12-bit ADC is convenient and imperfect: noise, non-linearity near 0 V and 3.3 V, and channel restrictions depending on Wi-Fi use (Espressif, 2023). For clean biopotentials, prefer:

  • ADS1115 (I2C, 16-bit) after an analog AFE such as AD8232.
  • Digital AFEs such as ADS1299 or MAX30003 that digitize on the sensor board and speak SPI.
Comparing ESP32 ADC, ADS1115, and ADS1299 for biosignal quality

2. Electrical safety is not optional

While electrodes touch a person, run the ESP32 from a battery (LiPo or pack). Stream over Wi-Fi or BLE. Do not leave USB connected to a wall charger or to a laptop that is itself on mains. SparkFun's MyoWare docs say the same thing in blunt language: remove the shield from the sensor when charging or programming, and do not charge while attached to a user (SparkFun, 2024). Open ADS1299 + ESP32 projects repeat the rule: battery on subject, USB disconnected (Asghar, 2024).

Problem: 50 Hz hum ruins every plot, and a fault path to mains is possible.
Cause: the subject and the wall share a ground through USB.
Effect: bad science and real shock risk. Battery + wireless fixes both.

Unsafe mains-powered electrodes versus safe battery and BLE setup

3. Sample at the rate the physiology needs

  • ECG: often 250 to 500 Hz for a useful waveform.
  • EMG (raw): often 500 Hz to 1 kHz+; envelope outputs can be slower.
  • EEG: often 250 to 500 Hz per channel, with serious attention to referencing.
  • EDA / EGG: low rates are fine; filter design matters more.
  • PPG: tens to a few hundred Hz, depending on the chip FIFO and your algorithm.

4. Filter in hardware first, then in software

AFEs already band-limit. Add digital notch (50/60 Hz), baseline wander removal, and, for EMG, envelope or RMS features. Do not expect a raw FFT on a noisy ADC pin to look like a textbook figure.

5. Label the project honestly

Breakout vendors and open BioAmp boards say it: research, education, prototyping. Not diagnosis, not treatment, not a cleared medical device (SparkFun, 2024; Texas Instruments, 2017). If you need clinical claims, you need clinical hardware, clinical process, and regulators.

A Practical Start Path

  1. Pick one signal. PPG or ECG for a first win. EEG if you already like signal processing.
  2. Buy a matched AFE module, not bare electrodes.
  3. Power the ESP32 from a LiPo whenever a person is connected.
  4. Read via I2C/SPI if you can; otherwise analog into ADS1115 or a quiet ADC1 pin with averaging.
  5. Stream over BLE or Wi-Fi to a phone or laptop for plots.
  6. Only then attempt EGG, BIA, ENG, or ERG, with datasheets and a safety plan open.
Five-step path to start ESP32 biosensor projects safely

Module Cheatsheet

ESP32 host map Signal Common module / IC Link to ESP32 DIY difficulty ECG AD8232, MAX30003 Analog / SPI Easy EMG MyoWare, BioAmp Analog Easy EEG / EOG BioAmp, ADS1299 Analog / SPI Medium EDA/GSR Grove GSR Analog Easy PPG MAX30102 / 30105 I2C Easiest BIA/ICG AD5933, MAX30001 I2C / SPI Hard EGG / ERG / ENG Custom AFE + extras SPI / Analog Hardest Shared rules: AFE in the middle, battery on body, wireless off body, and never claim clinical use from a maker module.

The alphabet soup (ECG, EEG, EMG, and the rest) is one family of body signals plus one optical cousin. The ESP32 is a capable wireless host for all of them. The product between the skin and the chip is what decides whether you learn physiology or fight noise. Start with PPG or ECG, keep the subject on battery power, and treat every plot as a lesson, not a diagnosis.

If you remember one line: electrodes never meet the ESP32 alone. An AFE, a battery, and a radio sit in between.

References

Thursday, 1 July 2021

ESP32: The Ultimate Guide to Features, Applications, and Projects

Standard
 


ESP32

What is ESP32:

ESP32 is a system on a chip(SoC) that integrates the following features:

  • Wi-Fi (2.4 GHz band):
  • Bluetooth
  • Dual high performance cores
  • Ultra Low Power co-processor
  • Multiple peripherals

Powered by 40 nm technology, ESP32 provides a robust, highly integrated platform, which helps meet the continuous demands for efficient power usage, compact design, security, high performance, and reliability.

Espressif provides basic hardware and software resources to help application developers realize their ideas using the ESP32 series hardware. The software development framework by Espressif is intended for development of Internet-of-Things (IoT) applications with Wi-Fi, Bluetooth, power management and several other system features.

Features:

Following block diagram explains all inbuilt features of  ESP32
Ultra­Low­Power Solution ESP32 is designed for mobile, wearable electronics, and Internet-of-Things (IoT) applications. It features all the state-of-the-art characteristics of low-power chips, including fine-grained clock gating, multiple power modes, and dynamic power scaling. For instance, in a low-power IoT sensor hub application scenario, ESP32 is woken up periodically and only when a specified condition is detected. Low-duty cycle is used to minimize the amount of energy that the chip expends. The output of the power amplifier is also adjustable, thus contributing to an optimal trade-off between communication range, data rate and power consumption.

Wi­Fi Key Features :
  • 802.11 b/g/n
  • 802.11 n (2.4 GHz), up to 150 Mbps
  • WMM 
  • TX/RX A-MPDU, RX A-MSDU 
  • Defragmentation 
  • Automatic Beacon monitoring (hardware TSF) 
  • 4 × virtual Wi-Fi interfaces 
  • Simultaneous support for Infrastructure Station, SoftAP, and Promiscuous modes 
  • Antenna diversity

BT Key Features :
  • Compliant with Bluetooth v4.2 BR/EDR and BLE specifications 
  • Class-1, class-2 and class-3 transmitter without external power amplifier 
  • Enhanced Power Control 
  • +12 dBm transmitting power 
  • NZIF receiver with –94 dBm BLE sensitivity 
  • Adaptive Frequency Hopping (AFH) 
  • Standard HCI based on SDIO/SPI/UART 
  • High-speed UART HCI, up to 4 Mbps 
  • Bluetooth 4.2 BR/EDR BLE dual mode controller 
  • Synchronous Connection-Oriented/Extended (SCO/eSCO) 
  • CVSD and SBC for audio codec 
  • Bluetooth Piconet and Scatternet 
  • Multi-connections in Classic BT and BLE 
  • Simultaneous advertising and scanning
CPU and Memory :
  • Xtensa® single-/dual-core 32-bit LX6 microprocessor(s), up to 600 MIPS (200 MIPS for ESP32-S0WD/ESP32-U4WDH, 400 MIPS for ESP32-D2WD) 
  • 448 KB ROM 
  • 520 KB SRAM 
  • 16 KB SRAM in RTC 
  • QSPI supports multiple flash/SRAM chips
Clocks and Timers :

  • Internal 8 MHz oscillator with calibration 
  • Internal RC oscillator with calibration 
  • External 2 MHz ~ 60 MHz crystal oscillator (40 MHz only for Wi-Fi/BT functionality)
  • External 32 kHz crystal oscillator for RTC with calibration 
  • Two timer groups, including 2 × 64-bit timers and 1 × main watchdog in each group 
  • One RTC timer
  • RTC watchdog

Advanced Peripheral Interfaces :
  • 34 × programmable GPIOs 
  • 12-bit SAR ADC up to 18 channels 
  • 2 × 8-bit DAC 
  • 10 × touch sensors 
  • 4 × SPI 
  • 2 × I²S 
  • 2 × I²C 
  • 3 × UART 
  • 1 host (SD/eMMC/SDIO) 
  • 1 slave (SDIO/SPI) 
  • Ethernet MAC interface with dedicated DMA and IEEE 1588 support 
  • Two-Wire Automotive Interface (TWAI®, compatible with ISO11898-1) 
  • IR (TX/RX) 
  • Motor PWM 
  • LED PWM up to 16 channels 
  • Hall sensor

Secure boot :
  • Flash encryption 
  • 1024-bit OTP, up to 768-bit for customers 
  • Cryptographic hardware acceleration: – AES – Hash (SHA-2) 
  • RSA – ECC – Random Number Generator (RNG)


Applications (A Non­exhaustive List) :

  • Generic Low-power IoT Sensor Hub 
  • Generic Low-power IoT Data Loggers 
  • Cameras for Video Streaming
  • Over-the-top (OTT) Devices 
  • Speech Recognition
  • Image Recognition 
  • Mesh Network 
  • Home Automation – Light control – Smart plugs – Smart door locks 
  • Smart Building – Smart lighting – Energy monitoring 
  • Industrial Automation – Industrial wireless control – Industrial robotics 
  • Smart Agriculture – Smart greenhouses – Smart irrigation – Agriculture robotics 
  • Audio Applications – Internet music players – Live streaming devices – Internet radio players – Audio headsets 
  • Health Care Applications – Health monitoring – Baby monitors 
  • Wi-Fi-enabled Toys – Remote control toys – Proximity sensing toys – Educational toys 
  • Wearable Electronics – Smart watches – Smart bracelets 
  • Retail & Catering Applications – POS machines – Service robots

Types & Specifications:

The ESP32 series of chips includes follwing variants...

  • ESP32-D0WD-V3 
  • ESP32-D0WDQ6-V3 
  • ESP32-D0WD
  • ESP32-D0WDQ6 
  • ESP32-D2WD E
  • SP32-S0WD 
  • ESP32-U4WDH
ESP32 WROOM PINOUT:






For More Updates...Please Follow: 

For ESp32 based Development Board Variants and market price:

Firmware and Types:

ESP32 Supports many firmwares and Programming languages. It does matter for a developpper to choose right firmware before developming any product. Right firmware and supported libraries are the main building blocks for developing  a good product.

Following table represents the Firmware Types Programming Language support with Links..

Programming Language Supports:

  1. Embeddded C,C++
  2. Python
    For More Reference:

IDEs:

1. VS Code


 

2. Arduino IDE


RTOS:



Power Consumption and Modes:

 ESP32 offers 5 configurable power modes. As per the power requirement, the chip can switch between different power modes. The modes are:

  • Active Mode
  • Modem Sleep Mode
  • Light Sleep Mode

  • Deep Sleep Mode
  • Hibernation Mode




Sample Codes, Experiments and Example:

LED Blinking Code:

/*
 * ON Board LED GPIO 2
 */

#define LED 2

void setup() {
  // Set pin mode
  pinMode(LED,OUTPUT);
}

void loop() {
  delay(500);
  digitalWrite(LED,HIGH);
  delay(500);
  digitalWrite(LED,LOW);
}

O/P:



Wifi Station Code:


#include <WiFi.h>
#include <WebServer.h>

/* Put your SSID & Password */
const char* ssid = "ESP32";  // Enter SSID here
const char* password = "12345678";  //Enter Password here

/* Put IP Address details */
IPAddress local_ip(192,168,1,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);

WebServer server(80);

uint8_t LED1pin = 4;
bool LED1status = LOW;

uint8_t LED2pin = 5;
bool LED2status = LOW;

void setup() {
  Serial.begin(115200);
  pinMode(LED1pin, OUTPUT);
  pinMode(LED2pin, OUTPUT);

  WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);
  
  server.on("/", handle_OnConnect);
  server.on("/led1on", handle_led1on);
  server.on("/led1off", handle_led1off);
  server.on("/led2on", handle_led2on);
  server.on("/led2off", handle_led2off);
  server.onNotFound(handle_NotFound);
  
  server.begin();
  Serial.println("HTTP server started");
}
void loop() {
  server.handleClient();
  if(LED1status)
  {digitalWrite(LED1pin, HIGH);}
  else
  {digitalWrite(LED1pin, LOW);}
  
  if(LED2status)
  {digitalWrite(LED2pin, HIGH);}
  else
  {digitalWrite(LED2pin, LOW);}
}

void handle_OnConnect() {
  LED1status = LOW;
  LED2status = LOW;
  Serial.println("GPIO4 Status: OFF | GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,LED2status)); 
}

void handle_led1on() {
  LED1status = HIGH;
  Serial.println("GPIO4 Status: ON");
  server.send(200, "text/html", SendHTML(true,LED2status)); 
}

void handle_led1off() {
  LED1status = LOW;
  Serial.println("GPIO4 Status: OFF");
  server.send(200, "text/html", SendHTML(false,LED2status)); 
}

void handle_led2on() {
  LED2status = HIGH;
  Serial.println("GPIO5 Status: ON");
  server.send(200, "text/html", SendHTML(LED1status,true)); 
}

void handle_led2off() {
  LED2status = LOW;
  Serial.println("GPIO5 Status: OFF");
  server.send(200, "text/html", SendHTML(LED1status,false)); 
}

void handle_NotFound(){
  server.send(404, "text/plain", "Not found");
}

String SendHTML(uint8_t led1stat,uint8_t led2stat){
  String ptr = "<!DOCTYPE html> <html>\n";
  ptr +="<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\">\n";
  ptr +="<title>LED Control</title>\n";
  ptr +="<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}\n";
  ptr +="body{margin-top: 50px;} h1 {color: #444444;margin: 50px auto 30px;} h3 {color: #444444;margin-bottom: 50px;}\n";
  ptr +=".button {display: block;width: 80px;background-color: #3498db;border: none;color: white;padding: 13px 30px;text-decoration: none;font-size: 25px;margin: 0px auto 35px;cursor: pointer;border-radius: 4px;}\n";
  ptr +=".button-on {background-color: #3498db;}\n";
  ptr +=".button-on:active {background-color: #2980b9;}\n";
  ptr +=".button-off {background-color: #34495e;}\n";
  ptr +=".button-off:active {background-color: #2c3e50;}\n";
  ptr +="p {font-size: 14px;color: #888;margin-bottom: 10px;}\n";
  ptr +="</style>\n";
  ptr +="</head>\n";
  ptr +="<body>\n";
  ptr +="<h1>ESP32 Web Server</h1>\n";
  ptr +="<h3>Using Access Point(AP) Mode</h3>\n";
  
   if(led1stat)
  {ptr +="<p>LED1 Status: ON</p><a class=\"button button-off\" href=\"/led1off\">OFF</a>\n";}
  else
  {ptr +="<p>LED1 Status: OFF</p><a class=\"button button-on\" href=\"/led1on\">ON</a>\n";}

  if(led2stat)
  {ptr +="<p>LED2 Status: ON</p><a class=\"button button-off\" href=\"/led2off\">OFF</a>\n";}
  else
  {ptr +="<p>LED2 Status: OFF</p><a class=\"button button-on\" href=\"/led2on\">ON</a>\n";}

  ptr +="</body>\n";
  ptr +="</html>\n";
  return ptr;
}

O/P:



WiFi Client Code:


WiFi OLED DIsplay(0.96inch I2C):

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display(-1);

void setup()   
{                
	// initialize with the I2C addr 0x3C
	display.begin(SSD1306_SWITCHCAPVCC, 0x3C);  

	// Clear the buffer.
	display.clearDisplay();

	// Display Text
	display.setTextSize(1);
	display.setTextColor(WHITE);
	display.setCursor(0,28);
	display.println("Hello world!");
	display.display();
	delay(2000);
	display.clearDisplay();

	// Display Inverted Text
	display.setTextColor(BLACK, WHITE); // 'inverted' text
	display.setCursor(0,28);
	display.println("Hello world!");
	display.display();
	delay(2000);
	display.clearDisplay();

	// Changing Font Size
	display.setTextColor(WHITE);
	display.setCursor(0,24);
	display.setTextSize(2);
	display.println("Hello!");
	display.display();
	delay(2000);
	display.clearDisplay();

	// Display Numbers
	display.setTextSize(1);
	display.setCursor(0,28);
	display.println(123456789);
	display.display();
	delay(2000);
	display.clearDisplay();

	// Specifying Base For Numbers
	display.setCursor(0,28);
	display.print("0x"); display.print(0xFF, HEX); 
	display.print("(HEX) = ");
	display.print(0xFF, DEC);
	display.println("(DEC)"); 
	display.display();
	delay(2000);
	display.clearDisplay();

	// Display ASCII Characters
	display.setCursor(0,24);
	display.setTextSize(2);
	display.write(3);
	display.display();
	delay(2000);
	display.clearDisplay();

	// Scroll full screen
	display.setCursor(0,0);
	display.setTextSize(1);
	display.println("Full");
	display.println("screen");
	display.println("scrolling!");
	display.display();
	display.startscrollright(0x00, 0x07);
	delay(2000);
	display.stopscroll();
	delay(1000);
	display.startscrollleft(0x00, 0x07);
	delay(2000);
	display.stopscroll();
	delay(1000);    
	display.startscrolldiagright(0x00, 0x07);
	delay(2000);
	display.startscrolldiagleft(0x00, 0x07);
	delay(2000);
	display.stopscroll();
	display.clearDisplay();

	// Scroll part of the screen
	display.setCursor(0,0);
	display.setTextSize(1);
	display.println("Scroll");
	display.println("some part");
	display.println("of the screen.");
	display.display();
	display.startscrollright(0x00, 0x00);
}

void loop() {}


O/P:

.....Many More



BLE Code:


#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEServer.h>


#define SERVICE_UUID        "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");

  BLEDevice::init("Long name works now");
  BLEServer *pServer = BLEDevice::createServer();
  BLEService *pService = pServer->createService(SERVICE_UUID);
  BLECharacteristic *pCharacteristic = pService->createCharacteristic(
                                         CHARACTERISTIC_UUID,
                                         BLECharacteristic::PROPERTY_READ |
                                         BLECharacteristic::PROPERTY_WRITE
                                       );

  pCharacteristic->setValue("Hello World says Neil");
  pService->start();
  // BLEAdvertising *pAdvertising = pServer->getAdvertising();  // this still is working for backward compatibility
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(true);
  pAdvertising->setMinPreferred(0x06);  // functions that help with iPhone connections issue
  pAdvertising->setMinPreferred(0x12);
  BLEDevice::startAdvertising();
  Serial.println("Characteristic defined! Now you can read it in your phone!");
}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
}

OTA Update Code and Support:

#include <WiFi.h>
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>

const char* ssid = "..........";
const char* password = "..........";

void setup() {
  Serial.begin(115200);
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  // Port defaults to 3232
  // ArduinoOTA.setPort(3232);

  // Hostname defaults to esp3232-[MAC]
  // ArduinoOTA.setHostname("myesp32");

  // No authentication by default
  // ArduinoOTA.setPassword("admin");

  // Password can be set with it's md5 value as well
  // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

  ArduinoOTA
    .onStart([]() {
      String type;
      if (ArduinoOTA.getCommand() == U_FLASH)
        type = "sketch";
      else // U_SPIFFS
        type = "filesystem";

      // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
      Serial.println("Start updating " + type);
    })
    .onEnd([]() {
      Serial.println("\nEnd");
    })
    .onProgress([](unsigned int progress, unsigned int total) {
      Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
    })
    .onError([](ota_error_t error) {
      Serial.printf("Error[%u]: ", error);
      if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
      else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
      else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
      else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
      else if (error == OTA_END_ERROR) Serial.println("End Failed");
    });

  ArduinoOTA.begin();

  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  ArduinoOTA.handle();
}

For More in Details: htpts://lastminuteengineers.com/esp32-ota-updates-arduino-ide/...


Bibliography:

https://circuits4you.com/2018/02/02/esp32-led-blink-example/

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

https://randomnerdtutorials.com/esp32-bluetooth-low-energy-ble-arduino-ide/

https://www.espressif.com/en/products/modules

https://www.youtube.com/

https://www.google.com/

https://www.instructables.com/

https://stackoverflow.com/

http://esp32.net/

https://en.wikipedia.org/wiki/ESP32

https://aws.amazon.com/