Basic level: Arduino/ESP32, signals and timing

Start with GPIO, ADC, PWM and serial using compile-verified UNO R3 and ESP32 Dev Module sets. Practise reading buttons and timing before adding sensors or motors.

Last updated:

A microcontroller board connected by USB beside a breadboard with an LED and a button for practising I/O
Concept image generated with AI; it is not a screenshot or a device model confirmed to be supported

Choose to read the ADC and PWM guide to separate raw values, voltages and pulse times, with paper-based exercises

Objectives and what to prepare

This lesson trains a program to receive input and act on time, without yet connecting a motor drive. By the end you should be able to read a button, blink an LED while sending serial data, and explain how blocking waits can make some data arrive late.

You can start checking code on a computer without connecting a board. There are sets for the Arduino UNO R3 and the original ESP32 Dev Module to choose from. When you have the equipment, prepare a USB cable that carries data, a push button and an LED according to the chosen set. Check the model name, pinout, voltage levels and the manual before wiring. USB power pins and signal pins have different roles; do not assume that every kind of pin accepts the same voltage

Choose a board by the task, not by bit width alone

The original Arduino UNO R3 uses the ATmega328P with a 16 MHz clock and is well suited to getting started with I/O and serial. This information applies only to UNO R3; other UNO models may use a different MCU. See the UNO R3 documentation

ESP32 comes in many families and boards. Many tasks can take advantage of the radio and peripherals of the chosen model, but you must check whether that chip has the ADC, PWM and pins you need. You can start with the Arduino core for ESP32, then study ESP-IDF when finer system control is needed. For API examples see Arduino-ESP32 ADC

An 8-bit or 32-bit width describes only part of the processing characteristics. Actual speed also depends on the clock, instructions, FPU, memory and other concurrent tasks, so measure the timing of the tasks you need rather than assuming 32-bit is always four times faster than 8-bit.

Signals used in drone systems

Name Basic meaning What it is used to learn
GPIO Digital signal pins that read or output logic levels Reading a button and switching an LED on/off
ADC Converts an analogue signal into a digital value Reading test values, then checking range and unit conversion
PWM Switches a signal according to period and duty cycle Adjusting LED brightness; ESC protocols must be studied separately
UART Sends serial data between devices Logging messages or connecting supported modules
I2C / SPI A bus for exchanging data with devices Reading an IMU according to the module's interface and datasheet
Timer A circuit or mechanism that provides a time reference Setting read intervals and detecting late arrivals

PWM for LED brightness and the signal an ESC requires may differ in frequency, pulse width and protocol. Do not apply LED example values directly to an ESC. For ESP32, use the API matching the installed core version, such as ledcAttach(pin, frequency, resolution) and ledcWrite(pin, duty) in the current documentation, and check the return values to know whether the settings succeeded. See LEDC API

Before adding sensors, read Comparing I2C, SPI and UART together with the planning sheet and the UART timing calculation

Read ADC and PWM with the units kept distinct

Objective: explain the raw ADC value and calculate the period/duty/pulse time of PWM before choosing a sensor or output Prerequisites: know GPIO, voltage and ground from the start of the chapter Getting started: read the model below, then do the worksheet on a PC or paper; no board connection is needed yet

Concept image of an ADC and PWM study desk with a microcontroller board, a potentiometer, an LED, a resistor and unconnected wires, beside a drone frame with the propellers removed

A photorealistic image created with AI for learning context; it is not a wired circuit, a pinout or a measurement of real equipment

Separate the numbers being read or set

Quantity Meaning What to record with it
ADC raw A digital code, with no unit yet of V The ADC model, the resolution and the input range setting
Voltage A value in V or mV after conversion or reading from an API The formula/calibration method and the point measured
PWM frequency The number of periods per second, in Hz The timer/clock and the value set versus the value checked
PWM duty The fraction of time high within one period As a % or as a fraction 0-1; do not confuse it with the API's integer

An ADC is an input path, while PWM is an output signal that switches between HIGH and LOW. It is not a DAC producing a steady voltage, and more bits do not guarantee voltage accuracy

ADC - raw values, bits and voltage conversion

A 10-bit ADC has 1,024 codes, 0-1,023; a 12-bit one has 4,096 codes, 0-4,095. The document Arduino analogRead describes the range of the UNO; this example does not set the range for every board

Model problem: declare an ideal 10-bit ADC dividing the range 0 <= Vin < 5 V into 1,024 equal bins, using the lower edge to represent each code, so the bin size is 5 / 1024 = 0.0048828125 V or about 4.883 mV code 512 lies in the range 2.5 ≤ Vin < 2.5048828125 V This is a calculation from assumptions, not the error range or calibration result of a real UNO. The divisor 1,024 is used to count the bins in this model; a formula that maps the endpoints with 1,023 is a different definition, and the formula used must be stated

For the ESP32, the documentation separates analogRead() which gives raw from analogReadMilliVolts() which converts to mV using calibration. Check the resolution, attenuation, chip and usable GPIOs from Espressif ADC and do not replace the range with 3.3 V merely because the board uses 3.3 V logic. Calling the two APIs in succession gives two separate readings, so do not claim that raw and mV are the same sample

When preparing real equipment, check the input range and electrical limits from the datasheet first. Choose the calibration method/reference instrument according to the job, and record ground, noise and the readable range. Adding bits or averaging helps with some problems but does not fix a wrong formula or reference

PWM - period, duty and pulse width

Let f be the frequency in Hz, T = 1 / f the period in seconds, and D = tHigh / T the duty as a fraction, for example 25% is D = 0.25 so tHigh = D × T can be calculated

Declared examples Period T tHigh when duty is 25%
1,000 Hz 1 ms 250 µs
2,000 Hz 0.5 ms 125 µs

The same duty but different pulse lengths. If an ideal signal is declared with HIGH = 3.3 V and LOW = 0 V, the average over one period at 25% duty is 0.825 V but the signal pin still switches between two levels; this does not confirm 0.825 V DC on the pin or that the LED is 25% bright. The response depends on the circuit and the device

On the ESP32 you must choose a frequency/resolution pin that the chip and clock support, then check the return value of ledcAttach() and ledcWrite() per Espressif LEDC . Frequency and resolution have a shared limit. The API's integer duty value must be read per the SDK; this exercise does not convert duty into a board command and does not use the LED example as an ESC signal or motor command

Diagram: a 10-bit ADC has 1024 codes, and PWM at 25 percent duty at 1000 Hz has a 250 microsecond pulse, while at 2000 Hz it has a 125 microsecond pulse

A signal model based on the assumptions in the chapter. The widths in the PWM image use the same time scale; it is not a trace from an oscilloscope. Open the full-size ADC/PWM diagram

Practice steps and initial recommendations

  1. Fill in the board/chip/SDK, input/output pins and sources in the blank ADC/PWM planning sheet . Put unknown for values not yet known
  2. Separate what is set, what is read and what is calculated. Write the unit in every field. Do not convert raw to V without a stated formula or API
  3. Do the ADC/PWM paper exercises and then check your reasoning against the answers with their scope . The exercises do not add points to the earlier assessment
  4. If raw readings fluctuate, check for a floating pin/ground/input range before concluding that the sensor is faulty. If the PWM setup does not succeed, check the frequency/resolution pin and the return value before increasing the duty
  5. When you have the equipment, check it in practice per the manual and record the results separately from the settings. If you will pass the data on, read the I2C, SPI and UART guide and prepare the sources and scope of the log before concluding the results

Additional downloads: ADC/PWM set quick-start guide · ADC/PWM sources and assumptions · ADC/PWM file hash list

Example: blinking an LED while logging time

Diagram: input through GPIO/ADC -> MCU timing -> LED or serial -> check the result and read the next round

Diagram of I/O functions and timing; it cannot replace a wiring diagram. The realistic image at the top of the page is a concept image, not a pinout.

This code is an example for the Arduino UNO R3 and LED_BUILTIN compiled with Arduino CLI 1.5.1 and Arduino AVR Boards 1.8.8 on 1 October 2026, using 2,078 bytes of program space and 197 bytes of RAM. It has not been uploaded or tested on a real board It uses the timing-check principle from Blink Without Delay , with the example written to include one additional data-logging task.

unsigned long lastBlink = 0;
unsigned long lastReport = 0;
bool ledOn = false;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(115200);
}

void loop() {
  const unsigned long now = millis();
  if (now - lastBlink >= 500UL) {
    lastBlink = now;
    ledOn = !ledOn;
    digitalWrite(LED_BUILTIN, ledOn ? HIGH : LOW);
  }
  if (now - lastReport >= 200UL) {
    lastReport = now;
    Serial.println(now);
  }
  // Add button reading here without blocking with delay()
}

Unsigned time subtraction lets short intervals be compared across a counter wrap-around, but the program still spends time on serial printing and other work. This example therefore does not guarantee exact execution every 200 ms. The ESP32 set below uses an external LED with clearly defined pins, because the on-board LED differs between board models

Reading a button and debouncing, with time-based work

Download the UNO R3 input/debounce set (ZIP) · Compile result · File list and SHA-256

Objective: separate the raw signal from the settled button state, and read the input together with an LED and serial without blocking. This set has the sketch, header, tests and worksheet complete in the ZIP. Continuing from the LED example above, it uses the UNO R3 only . It passed the host tests and compiled on 1 October 2026 with CLI 1.5.1/AVR core 1.8.8, using 2,626 bytes of program and 203 bytes of RAM, with 4 warnings from arduino/new.cpp . No warnings were found from the example It has not been tested on a real board . For the ESP32, use the dedicated set below

Diagram: UNO R3 D2 is connected through a push button to GND using the internal pull-up, separating the raw input from the stable input after it has settled for 30 ms

A reference diagram of the example. Check the UNO R3 pinout and the button's contact pairs before wiring. The timeline explains the concept and is not a measurement on a board. Open the full-size diagram

  1. Check on a PC: extract the ZIP and compile input_led_serial according to README.md . If a C++ compiler is available, run g++ -std=c++11 -Wall -Wextra -Werror test_input.cpp -o test_input followed by ./test_input or the Windows tests executable. Check bounce on press/release, the 30 ms limit, a single event and the time-counter rollover
  2. Read the wiring: the example sets D2 as INPUT_PULLUP . The momentary button connects D2 to GND, so it reads LOW when pressed. See InputPullupSerial and do not use this circuit to command an ESC
  3. Read the state machine: when the raw input changes, start timing a new candidate; only if it stays settled for at least 30 ms does stable change and send a single event. A bounce before the time is up restarts the timing. See the principle at Debounce
  4. When you have a board: upload and open serial at 115200 baud. Record millis,raw_pressed,stable_pressed,event in the worksheet from the ZIP. The LED toggles about every 500 ms and the serial reports about every 200 ms or when an event occurs. Try pressing/releasing and pressing for less than 30 ms, and compare with the times actually received

Checking criteria: a bouncing input does not change stable before the time is up, and a change of stable produces event=1 only once. The periods set in the code are targets. Passing host tests/compile does not confirm wiring, voltage or timing on a real MCU

From the UNO to the ESP32 Dev Module

Download the ESP32 input/debounce set (ZIP) · ESP32 compile result · ESP32 file list and SHA-256

Objective: practise porting an input-reading and timing program from the UNO to another MCU family, checking that the pins, voltage and SDK match. This set uses classic ESP32 Dev Module target esp32:esp32:esp32 and Arduino-ESP32 3.3.12 (ESP-IDF 5.5.5), compiled on Windows on 1 October 2026 with CLI 1.5.1 with all warnings enabled and no warnings found, using program size 272,436 / 1,310,720 bytes and RAM 22,132 / 327,680 bytes according to the compiler. Program size is not a result of speed or of RAM during real operation

Reference circuit for the classic ESP32: GPIO27 uses the internal pull-up with a button to GND, and GPIO25 connects through a 330 ohm resistor to an external LED to GND, using 3.3 volt logic

The numbers are the chip's GPIOs, not the pin positions on the board. Check the manufacturer's pinout before wiring. This image explains the circuit; there is no hardware measurement result. Open the full-size ESP32 diagram

Item Reference set value
Board and SDK ESP32 Dev Module original, Arduino-ESP32 3.3.12
Button GPIO27 -> momentary push button -> GND, INPUT_PULLUP, LOW when pressed
External LED GPIO25 -> 330 ohm resistor -> LED anode, cathode -> GND
Serial and timing 115200 baud; debounce 30 ms; LED toggles every 500 ms; reports every 200 ms or when an event occurs
Verified build values CPU 240 MHz, flash 4 MB, QIO/80 MHz, default partition, PSRAM disabled; for other values see the JSON result
  1. Check on a PC first: extract the ZIP and open esp32_input_serial.ino together with input_state.h in the same folder, add the stable index and install esp32 by Espressif Systems 3.3.12 per the installation guide in the IDE, select ESP32 Dev Module and press Verify; no USB connection is needed yet
  2. If using the CLI: read the installation commands in README.md and then run arduino-cli compile --fqbn esp32:esp32:esp32 --warnings all --clean esp32_input_serial record your own result and compare the core/board options with the JSON. A default that compiles successfully does not confirm that it matches every real board
  3. Check the debounce concept: the header uses the same bytes as the UNO tests on a PC, checking bounce on press/release, the 30 ms limit, a single event and time wrap-around. The C++ commands are in the guide, so this concept can be checked without an MCU
  4. When you have a real board: check that the board is a classic ESP32 with GPIO25/27 exposed, and start wiring with the power off. Check the LED polarity, the button contact pairs and the common ground, then upload for the model and open the serial monitor at 115200 baud. Fill in millis,raw_pressed,stable_pressed,event in the blank worksheet, try pressing/releasing and pressing for less than 30 ms, and add a print task to compare the actual intervals

Recommendation: GPIO uses 3.3 V logic; do not connect a 5 V signal from the UNO to the ESP32. This set uses an external LED so as not to assume the LED_BUILTIN and the on-board pins. The reference wiring values are checked from GPIO API and ESP32 datasheet If using ESP32-C3/S3 or another model , you must choose the target/pinout and recheck the compile for that model

Scope of the results: only passing compile and host tests; there is no upload and no LED/input/serial/timing result on a real ESP32. Wi-Fi/Bluetooth are not enabled and this set is not used to command an ESC. The 500/200 ms periods are targets in the code, not a guarantee of drone-system timing

Hands-on steps

  1. Check on a computer: download the practice set below, open led_serial.ino , choose the Arduino UNO and the matching core, and press Verify to compile. This step can be done without connecting a board. Record your own tool version and result
  2. Prepare the board: when you have a UNO R3, check the model name, USB cable and the board's port in the IDE, then upload per the guide. If starting from another board model, use the Blink example specific to that model first
  3. Add logging: open the serial monitor at 115200 baud, check that the time values are continuous and the LED still changes state. Fill in the times actually read in the worksheet, then find the gap between two consecutive lines
  4. Add input: change from the first LED example to the input/debounce set above, check the connection of D2 to the button per the guide, and then record raw/stable/event when the state changes. A value that bounces several times should be filtered before stable changes
  5. Compare timing: try adding more message printing, then observe the interval between reports. Record what changed and why. Stop at the LED and input in this lesson.

Download the practice set and check the compile result

Download the UNO R3 practice set: code, guide, worksheet and compile result (ZIP)

The set contains led_serial/led_serial.ino matching this example, a guide to open with an IDE/CLI, and a blank table for recording results. If you want only the worksheet, use the experiment log table (CSV) or read the practice set guide (Markdown)

The check used the target board arduino:avr:uno with all warnings enabled. 4 unused-parameter warnings from the Arduino core were found and none from the sketch, per the compiler result. See the compile result and SHA-256 of the code (JSON) and the file list and hashes (JSON) . This result confirms only that the program builds; the LED, serial, input and real timing still await testing on a board. For the classic ESP32, use the dedicated set verified above; other models must be checked separately

Evaluation criteria and advice

You should end up with an LED working alongside serial reports, a table of pin names and functions, and a record of whether the input can still be read while the LED blinks. If the program does not work, check the USB cable, port, board name, baud rate and pin connections one at a time; do not change everything at once.

Before moving to the next lesson, you should be able to answer which tasks delay() stops, what units ADC values must be converted to, and why signal pins of different models cannot be connected together without checking voltages. Then go to Applied: IMU and communication

Self-check of understanding

Open the three-level assessment with reasons with 4 questions per level, recording the before-reading/after-review rounds only in the browser. It uses the same questions and is not a measurement of real learners or a certificate

Prepare to collect evidence from a real board

A guide to preparing UNO/ESP32/STM32 experiments, with worksheets Check the wiring version, source/core clock and raw files before concluding the results. The guide is ready to use, but the real upload/measurement still awaits equipment

Separating Verify, port, upload, Serial and log-file problems with a blank problem-record form. You can start checking code locally; the parts that use a board still await real equipment

Practise reading a button, debounce and non-blocking timing

Objective: separate raw, candidate, stable and event, and calculate unsigned time before moving from the UNO to the ESP32 Prerequisites: boolean, if, units of ms and basic C/C++ Suggested time: 45-60 minutes, not yet measured with learners. CSV/JSON or paper can be used without a board

Debounce diagram: a new candidate starts when raw changes; at 139 ms (elapsed 29) stable has not yet changed, but at 140 ms (elapsed 30) an event occurs; holding the button does not repeat the event, and a release can also produce an event

The sequence of 15 update calls and four due examples was read from the earlier host test and then calculated; they are declared exercises, not a log measured on a board or a new run result. The earlier photorealistic image and circuit diagram are retained

Download how to practise buttons and timing, the 8-question foundation worksheet, the declared call sequence, the blank state table, the blank due table and the blank report form before reading the answers with reasoning, the state answers and the due answers . Check the source/SHA-256 from manifest

1. Choose the set and trace the states - B1-B2

Read the button and LED pins of each sketch and fill in raw -> candidate -> stable -> event, with a new initial state for each sequence. Recommendation: LOW is converted to raw_pressed=true in this INPUT_PULLUP set. The UNO/ESP32 headers have the same bytes, but the SDK pins and voltage must be checked per board; do not move the circuit by pin numbers alone

2. The 30 ms limit and a single event - B3-B5

Trace the bouncing press at 100/105/110 ms, then compare the elapsed values at 139/140, along with the release interval and the wrap. Recommendation: a raw change starts a new candidate; an event means stable changed, on either press or release. Use unsigned elapsed with the limit >=30 but the exercise does not certify the real signal between calls or every kind of button

3. Separate the set period from the report - B6-B7

Compute the four due cases, then read the condition of an event or a completed report period. Recommendation: the LED 500 ms/report 200 ms are sketch settings; do it once and then set last=now, without catching up for every period that passed; the every-update table is not a serial capture. Having no delay() still requires measuring the time of Serial and other work

4. Write a conclusion from the exercise - B8

Choose one interval, cite the call, unit and boundary, and then separate what can be calculated -> what is not yet known -> additional evidence Recommendation: both of the earlier observations.csv files are still empty. The earlier compile result confirms the build target, while wiring/LED/Serial/timing on a board must be collected for real. Do not enter these calculated values as experimental results

Self-check: proposed at 2 points per question (answer 1 + reason/unit/boundary 1), 16 in total, for choosing what to review; it does not replace the earlier worksheet or learner results. This round checked the source bytes, numbers and explanations; there was no new run of host tests/compile/upload. Once you can explain it, continue with sensors and communication

Choose the next practice set or review

Return to the index of the 10 MCU practice sets to choose a scenario according to your goal and the background you should know, or take the 12-question understanding assessment to find the topics to review

After checking the answers, record the answers you corrected, the reasons, and what the evidence still does not confirm, then choose the next set that helps answer that question. The worksheet score and the assessment are separate parts, used for choosing your own review

Used in courses

How to cite this page

Drone Institute, Rangsit University. (2026). Basic level: Arduino/ESP32, signals and timing. In UAS Technology Knowledge Hub (B.Tech.). https://rsu-uat.pk-research.work/en/kb/knowledge/microcontrollers/basic/

Original from Drone-Hub: https://drone.pk-research.work/knowledge/microcontrollers/basic/ · © PK-Research