TCS Pune

ESP32 — GPIO LED and Safe Current

Embedded Project Builder

ESP32 — GPIO LED and Safe Current

Drive an LED with a calculated resistor and verify HIGH/LOW voltage. Program and practical guide for ESP32.

Problem statement

Drive an LED with a calculated resistor and verify HIGH/LOW voltage. 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.

Rich media learning

Print lab worksheet

Instructor media is being prepared for this project.

Project execution and evidence

Log in to start this practical, save readings and submit evidence.

Log in to start

Recommendations & learning path

Bookmark project

Equivalent and related projects

Components required

ComponentQtyNotes
LED and 220–1 kΩ resistor1Verify voltage/current rating
Breadboard and insulated jumpers1Inspect before power
USB data/programming cable1Must support data
Digital multimeter1Lab tool
Current-limited bench supply1Lab tool

Pin-connection table

Controller pinConnected deviceDevice pinVoltage / notes
Board supplyTarget VCCConfirm exact board input and regulator
Board groundModule groundShared reference unless isolated
GPIO / timer outputSelected peripheral pins3.3 V maximum; confirm pin mux
Protected outputDriver inputNever power high-current load from GPIO

Project files

Source-code files

Instructor file pending.

PCB and Gerber files

Instructor file pending.

Enclosure design files

Instructor file pending.

Target-specific program

Toolchain: · Language:

// ESP32 — gpio 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;digitalWrite(OUT_PIN,state);state=!state;}

Testing and observations

  1. Inspect wiring with power disconnected.
  2. Power from a current-limited supply.
  3. Build with the exact target and warning level enabled.
  4. Flash the program and capture startup output.
  5. Measure supply and relevant I/O signals.
  6. Inject one safe input or communication fault.
  7. Repeat the functional test for at least 20 cycles.
  8. Record code version, board revision and results.
TestExpectedInstrumentAcceptance criteria
Supply railWithin target-board tolerance
Idle currentBelow approved project limit
Functional outputMatches the stated objective
Fault responseSafe and recoverable
Repeated test20 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

Beginner2–3 hoursBeginner GPIO and LED projects

Objective

Drive an LED with a calculated resistor and verify HIGH/LOW voltage.

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

  1. Create a project for ESP32 using Arduino IDE / PlatformIO.
  2. Select the exact MCU/board and clock configuration.
  3. Paste the complete program and change only the documented pin constants.
  4. Install only the libraries listed for this project.
  5. Build with warnings enabled and resolve every error.
  6. Connect the board with outputs disconnected and upload/program it.
  7. Confirm startup diagnostics, then connect the protected load.
  8. Record the final binary size and test evidence.

Complete source code

// ESP32 — gpio 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;digitalWrite(OUT_PIN,state);state=!state;}
SectionExplanation
ConfigurationSelects the exact target pins, baud rate and safe defaults.
InitialisationConfigures peripherals and reports startup state.
Non-blocking loopSchedules input, processing and output without long delays.
Fault handlingDetects invalid data or timeout and selects a safe output.
DiagnosticsPrints measurements and state for repeatable testing.

Expected Serial Monitor output

TCS ESP32 PROJECT
SELFTEST: PASS
STATE: READY
VALUE: 0
FAULTS: 0
PointExpectedToleranceInstrument
Board supplyRated board logic rail±5%DMM
GPIO LOW0 VWithin datasheet VOLDMM/oscilloscope
GPIO HIGH3.3 VWithin datasheet VOHDMM/oscilloscope
Signal timingProgrammed period±5%Oscilloscope/logic analyser
SignalTest pointReference
Digital/PWM outputConfigured output pinClean transitions inside 3.3 V limits
Serial outputUART TXStable frames at configured baud
Sensor busSDA/SCL or SCK/dataValid idle level, timing and acknowledgements

Troubleshooting decision tree

SymptomCheckCorrective action
Board not detectedUSB cable, driver, boot mode and targetUse data cable and correct programmer settings
No outputSupply, ground, pin mapping and safe defaultCorrect one item with power disconnected
Wrong readingsReference voltage, scaling and sensor rangeCompare raw value and DMM result
Random resetsCapture supply during peak loadImprove supply/decoupling and separate load power
Communication failsLogic voltage, pull-ups, mode/address and baudMatch both endpoints and use common reference

Extension challenges

  • Replace blocking timing with a state machine.
  • Add calibrated measurement and retained configuration.
  • Add serial commands with bounds checking and timeout.
  • Measure active and sleep current.
  • Create a PCB-ready pin and connector table.
  • Add watchdog recovery and diagnostic export.

Project-report guidance

Include objective, exact MCU/board, schematic, pin table, BOM, complete code, compiler/tool versions, expected and measured readings, waveform evidence, fault injection, corrections, limitations and extension results.

Ready when you are

Need help with your laptop or computer?

Send us the model and fault details. Start your repair request online or contact TCS Pune directly.

WA