Parse bounded serial commands and return deterministic responses. The implementation must operate inside the electrical, timing and memory limits of the exact ESP32 device.
System design
Circuit & Wiring Studio
Exact target required
Drag components. In Connect mode, select one pin and then another pin.
// ESP32 — uart project
const int OUT_PIN=5,IN_PIN=6;
const float ADC_REF=3.3f,ADC_MAX=4095.0f;
bool state=false,lastRaw=false,stable=false;unsigned long changed=0;volatile unsigned long pulses=0;float integral=0;byte duty=0,step=0;
void onPulse(){pulses++;}
void setup(){Serial.begin(115200);pinMode(OUT_PIN,OUTPUT);pinMode(IN_PIN,INPUT_PULLUP);digitalWrite(OUT_PIN,LOW);Serial.println("TCS PROJECT READY");}
void loop(){static unsigned long next=0;unsigned long now=millis();if((long)(now-next)<0)return;next=now+100;if(Serial.available()){char c=Serial.read();if(c=='1')digitalWrite(OUT_PIN,HIGH);else if(c=='0')digitalWrite(OUT_PIN,LOW);Serial.println("OK");}}
Testing and observations
Inspect wiring with power disconnected.
Power from a current-limited supply.
Build with the exact target and warning level enabled.
Flash the program and capture startup output.
Measure supply and relevant I/O signals.
Inject one safe input or communication fault.
Repeat the functional test for at least 20 cycles.
Record code version, board revision and results.
Test
Expected
Instrument
Acceptance criteria
Supply rail
Within target-board tolerance
Idle current
Below approved project limit
Functional output
Matches the stated objective
Fault response
Safe and recoverable
Repeated test
20 of 20 cycles pass
Viva questions
Why was this pin selected?
Explain pin capability, boot function and voltage limit.
What fails if timing blocks?
Other work and fault response become delayed.
How was current limited?
Use a resistor, driver and protected supply as required.
What evidence proves operation?
Code version, measurements, serial output and repeated tests.
Prototype safety
Verify voltage, polarity, GPIO limits and isolation before power-up. Use current limiting and disconnect power before wiring changes.
Guided practical
Complete learning and build guide
Intermediate4–6 hoursCommunication protocols
Objective
Parse bounded serial commands and return deterministic responses.
Required knowledge
ESP32 pin functions and voltage limits
Embedded C/C++ fundamentals
Safe breadboard wiring
Serial debugging and measurement
Power and current calculation
Calculate total current from the board, sensor/module and output load. GPIO supplies only logic-level current; motors, relays, buzzers and high-current LEDs require a correctly rated driver and protected external rail. Start with current limiting and verify actual idle and peak current.
Libraries and build procedure
Libraries: Board core only; no paid API
Create a project for ESP32 using Arduino IDE / PlatformIO.
Select the exact MCU/board and clock configuration.
Paste the complete program and change only the documented pin constants.
Install only the libraries listed for this project.
Build with warnings enabled and resolve every error.
Connect the board with outputs disconnected and upload/program it.
Confirm startup diagnostics, then connect the protected load.
Record the final binary size and test evidence.
Complete source code
// ESP32 — uart project
const int OUT_PIN=5,IN_PIN=6;
const float ADC_REF=3.3f,ADC_MAX=4095.0f;
bool state=false,lastRaw=false,stable=false;unsigned long changed=0;volatile unsigned long pulses=0;float integral=0;byte duty=0,step=0;
void onPulse(){pulses++;}
void setup(){Serial.begin(115200);pinMode(OUT_PIN,OUTPUT);pinMode(IN_PIN,INPUT_PULLUP);digitalWrite(OUT_PIN,LOW);Serial.println("TCS PROJECT READY");}
void loop(){static unsigned long next=0;unsigned long now=millis();if((long)(now-next)<0)return;next=now+100;if(Serial.available()){char c=Serial.read();if(c=='1')digitalWrite(OUT_PIN,HIGH);else if(c=='0')digitalWrite(OUT_PIN,LOW);Serial.println("OK");}}
Section
Explanation
Configuration
Selects the exact target pins, baud rate and safe defaults.
Initialisation
Configures peripherals and reports startup state.
Non-blocking loop
Schedules input, processing and output without long delays.
Fault handling
Detects invalid data or timeout and selects a safe output.
Diagnostics
Prints measurements and state for repeatable testing.