iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Yes—one Arduino codebase can power lights, relays, buttons and sensors on many ESP32 boards, but a single unchanged binary cannot guarantee identical behavior on every variant. The practical solution is a universal sketch with compile-time board profiles, pin maps and capability flags. Each profile selects the correct GPIOs and enables only peripherals that the chosen chip provides.
Keep hardware drivers and automation rules common, then isolate board differences in configuration. Add Wi-Fi station mode for normal operation, a temporary soft-access-point mode for provisioning, and an HTTP or MQTT command layer. This gives you reusable firmware without pretending that an ESP32-S3, ESP32-C6 and ESP32-H2 have the same radios, pins or peripherals.
Can one Arduino sketch run on every ESP32?
A reusable sketch can target the ESP32 family, but “every ESP32” needs qualification. Arduino-ESP32 supports the ESP32, C3, C5, C6, H2, P4, S2 and S3 families. Espressif’s feature matrix shows that GPIO, ADC, I2C, UART and Wi-Fi availability—and features such as Bluetooth Classic, Matter, motor PWM, PSRAM, Thread and USB—vary by system-on-chip (SoC).
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
That means portability has two layers:
- Source portability: the same project contains common automation logic, drivers and networking code.
- Hardware portability: a board profile supplies valid pins, available buses and feature flags for one specific board.
Compile the sketch for the selected board and profile. Do not flash one prebuilt binary across unrelated boards and assume that a relay is on the same GPIO or that every radio feature exists. Interoperability with ESP8266 and other non-ESP32 platforms is not guaranteed by the ESP32 getting-started documentation, so treat ESP8266 as a separate target.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
What should a universal ESP32 home-automation sketch contain?
Separate responsibilities so changing a board does not force you to rewrite automation rules. A robust project uses the following layers.
| Layer | Responsibility | What changes by board |
|---|---|---|
| Board profile | Pin assignments, bus instances and capability flags | Almost everything hardware-specific |
| Provisioning | Loading Wi-Fi credentials and entering setup mode | Usually only status LED and reset-button pins |
| Sensor drivers | Reading GPIO, ADC, I2C or UART devices | Pin, bus and device address |
| Actuator drivers | Setting relay, LED, dimmer or motor outputs | Output pin, polarity and supported PWM peripheral |
| Command transport | HTTP endpoints, MQTT topics or another local API | Credentials and enabled protocol |
| Automation rules | Schedules, thresholds, interlocks and scenes | Normally unchanged |
| Reliability | Reconnects, watchdog handling and safe output defaults | Timeouts and safe-state requirements |
Keep credentials outside source control. A device should start with outputs in a known safe state, connect to the network without blocking the main loop indefinitely, and continue local safety logic if the network disappears.
Which ESP32 board is a practical starting point?
The Arduino Nano ESP32 is a straightforward starter when you want a supported Arduino form factor rather than a bare module. Arduino documents it as its first board based on an Espressif ESP32 microcontroller. It uses the NORA-W106 module with an ESP32-S3 chip, includes USB-C, 16 MB (128 Mbit) flash, Wi-Fi, Bluetooth 5.0 or newer, Arduino Cloud compatibility and ESP-NOW support.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Choose a board profile only after checking the exact board pinout. Two boards using the same SoC can route pins differently, expose different voltage rails and reserve pins for flash, USB or onboard peripherals. For a project that may grow, record these decisions in a configuration header:
//#define BOARD_NANO_ESP32
//#define BOARD_CUSTOM_S3
#if defined(BOARD_NANO_ESP32)
constexpr int RELAY_PIN = D5;
constexpr int BUTTON_PIN = D2;
constexpr int STATUS_LED = LED_BUILTIN;
constexpr bool HAS_I2C = true;
#elif defined(BOARD_CUSTOM_S3)
constexpr int RELAY_PIN = 17;
constexpr int BUTTON_PIN = 18;
constexpr int STATUS_LED = 2;
constexpr bool HAS_I2C = true;
#else
#error "Select a board profile"
#endif
The pin names above illustrate the pattern; replace them with values from your board’s current pinout. Never copy a GPIO number from another model without verification.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
What parts do you need for an ESP32 automation project?
Start with a board, a stable power supply, the loads you intend to control and sensors that match your environment. Common building blocks are:
- An ESP32 development board, such as the Nano ESP32, with a USB-C data cable.
- An isolated relay module or solid-state output rated for the load. An “ESP32 relay module” is not automatically safe for mains voltage; verify contact ratings, creepage, enclosure and isolation.
- Buttons or switches for local control, with pull-up or pull-down wiring selected in the profile.
- An I2C sensor breakout or another sensor using GPIO, ADC or UART. Confirm voltage levels and the device address.
- Separate power regulation when the relay or actuator draws more current than the board’s 3.3 V rail can supply.
- Fuses, connectors and an enclosure appropriate to the installation.
Use transistor or driver stages for loads that exceed a GPIO’s current capability. A GPIO should command the driver, not power a motor, valve or lamp directly. For mains installations, use a qualified electrician and keep hazardous wiring physically separated from the low-voltage electronics.
How do Wi-Fi station and soft-access-point modes fit together?
Station mode connects the ESP32 to an existing access point and is the normal operating mode for a smart-home device. It can reach local services and, when the network allows it, the Internet. The Arduino ESP32 Wi-Fi API supports 802.11b/g/n, WPA2 and WPA3 security, and access-point scanning.
Soft-access-point mode creates a network that nearby devices can join directly. The ESP32 can then serve an HTTP or HTTPS page for first-run setup, even when it has not yet learned the household Wi-Fi credentials. A practical provisioning flow is:
- Boot with outputs disabled or in their documented safe state.
- Try saved station-mode credentials for a limited period.
- If connection fails, start a temporary soft AP with a unique setup name.
- Serve a local form that accepts the household SSID and password.
- Validate the credentials, save them in protected storage, stop the temporary AP and reconnect as a station.
- Provide a physical reset action that erases only network settings, not necessarily automation defaults.
Do not leave an open provisioning network running after setup. If the device exposes control pages beyond initial configuration, protect them with authentication and prefer HTTPS where the board’s memory and certificate handling make that practical.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
How do you structure the sketch step by step?
Build the project in layers and test each one before adding the next. This prevents a Wi-Fi problem from being mistaken for a relay or pin problem.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →- Select and validate a profile. Choose the board in the Arduino IDE, define one profile, and check every GPIO against the board pinout and the ESP32 library matrix. Mark unavailable features such as ADC, PSRAM, Thread or USB as disabled rather than probing blindly.
- Define safe startup states. Configure relay outputs before enabling automation. Account for active-low relay boards so a reset cannot briefly energize a load.
- Initialize buses and drivers. Start I2C, UART and ADC only when the profile says they exist. Give each sensor a timeout and a validity flag; a failed reading should not silently trigger an actuator.
- Implement provisioning and station mode. Keep credentials in nonvolatile storage rather than in the source file. Use reconnect backoff so a failed access point does not stall sensor polling.
- Add the command layer. Expose a small HTTP API or MQTT topic set for reading state and requesting changes. Validate ranges, reject unknown commands and return the resulting state.
- Run automation on a schedule. Use elapsed-time checks instead of long delays. Read sensors, evaluate rules and update outputs at independent intervals.
- Add recovery behavior. Detect Wi-Fi loss, restart the client without rebooting the whole controller, and use a watchdog only after ordinary fault handling is reliable.
- Log useful diagnostics. Include profile name, firmware version, reset reason, network state and sensor errors. Avoid printing passwords or tokens.
A minimal loop can look like this:
void loop() {
const uint32_t now = millis();
serviceProvisioningAndWiFi(now);
serviceHttpOrMqtt(now);
if (now - lastSensorRead >= SENSOR_PERIOD_MS) {
lastSensorRead = now;
readSensors();
}
if (now - lastRules >= RULE_PERIOD_MS) {
lastRules = now;
evaluateAutomationRules();
}
applySafeOutputPolicy();
feedWatchdog();
}
The key is not the exact function names; it is that networking, sensing and rules cooperate without blocking one another.
Should control use HTTP, MQTT or both?
HTTP is convenient for a browser, phone shortcut or simple local dashboard. MQTT is better when many devices publish state to a broker and subscribe to commands. You can support both, but define one internal command model so the relay driver does not care whether a request arrived over HTTP or MQTT.
| Transport | Best fit | Design precautions |
|---|---|---|
| HTTP/HTTPS | Direct browser control, setup pages and small integrations | Authenticate commands, validate input and return current state |
| MQTT | Multiple devices, retained state and event-driven automation | Use clear topic names, command acknowledgements and broker credentials |
| Native/local APIs | Custom controller or direct integration with an existing ecosystem | Document payloads and preserve a local fallback |
For reliability, publish state after every accepted change and again after boot. A command that times out should not be assumed to have failed; the caller should query the reported state.
Is Arduino, ESPHome or Tasmota the better firmware approach?
Arduino is the most flexible choice when you need custom hardware behavior or unusual rules. ESPHome reduces handwritten C++ by using YAML to generate firmware and offers components for Wi-Fi, MQTT, automations, sensors, web services and OTA-related functions. Tasmota provides open-source firmware with MQTT, a web UI, HTTP or serial control, timers, rules and scripts.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
| Criterion | Custom Arduino sketch | ESPHome | Tasmota |
|---|---|---|---|
| Custom code required | Highest; you own the architecture | Low for supported components; generated firmware | Low for standard features; rules and scripts extend it |
| Control style | Choose HTTP, MQTT or a native API | Configured integrations, including Wi-Fi and MQTT | Web UI, MQTT, HTTP and serial commands |
| Board-specific work | Explicit pin and capability profiles | Configuration still needs correct pins and components | Template and GPIO assignment are required |
| Debugging access | Full source-level control and serial logs | Generated-code and component logs | Built-in console, logs and rule diagnostics |
| Offline operation | Whatever local behavior you implement | Local automations can run on the device | Local web, rules and MQTT operation are available |
| Update path | USB or an OTA system you implement | Generated builds and OTA workflows | Web, serial or OTA workflows provided by the firmware |
Choose Arduino when the device is a product-like controller with specialized timing, hardware or safety logic. Choose ESPHome when declarative configuration and a broad component catalog matter more than owning every line of firmware. Choose Tasmota when ready-made local controls, MQTT and rule scripting are the priority.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.What usually goes wrong, and how do you fix it?
The sketch compiles but the relay never changes
Check that the selected profile matches the physical board, the relay is active-high or active-low as expected, and the module has a suitable supply. Test the GPIO with a low-voltage indicator before connecting the real load.
A sensor returns zeros or random values
Verify SDA and SCL assignments, pull-up requirements, address selection and logic voltage. Confirm that the profile actually enables the required I2C, ADC or UART peripheral.
Wi-Fi works once and then stops
Separate connection attempts from sensor polling, add bounded reconnect backoff and log disconnect reasons. Ensure credentials are stored correctly and that the device does not repeatedly create a provisioning AP after a temporary access-point outage.
The device resets when an actuator starts
Suspect power dips, electrical noise or inadequate grounding before blaming the network stack. Use an appropriately rated supply, decoupling, driver circuitry and physical separation; then inspect the reset reason in serial logs.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
One profile works while another fails to build
Guard optional libraries and features with compile-time flags. Keep unsupported peripherals out of the build rather than calling an API that the selected SoC or core does not provide.
How should you test a universal sketch before installation?
Test every profile on the bench with the final firmware, not just with a blink example. Use this checklist:
- Cold boot, software reset and watchdog reset all leave outputs safe.
- Wi-Fi credentials are absent, correct, incorrect and later changed.
- The station disconnects and reconnects without freezing local rules.
- The provisioning AP is unavailable after successful setup unless deliberately re-entered.
- Each sensor reports a clear invalid state when unplugged or out of range.
- Every command is authenticated as intended, rejects malformed payloads and reports resulting state.
- Relay polarity, button debounce and boot-time glitches are verified with the actual module.
- Long-duration operation is observed for memory growth, repeated reconnects and stale sensor values.
There is no single authoritative benchmark for universal-sketch speed, power draw, radio range or reliability. Those results depend on the exact board, firmware, antenna, network, power supply and connected load, so measure them on your assembled device rather than reusing a generic number.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesFrequently Asked Questions
Can the same firmware support both an ESP32-S3 and an ESP32-C6?
The same source project can support both through separate board profiles and conditional features. Build and test a binary for each target; radio and peripheral differences mean one compiled image is not a universal guarantee.
How can I change Wi-Fi credentials without recompiling?
Implement a controlled provisioning mode that starts a temporary soft access point and serves a local configuration page. Store the new credentials in protected nonvolatile storage, then require a deliberate reset action to erase them.
What is the safest way to connect a mains appliance?
Use a properly enclosed, certified relay or contactor interface with ratings above the appliance load and suitable isolation from the ESP32. Have mains wiring installed or checked by a qualified electrician; the GPIO should drive only the low-voltage control side.
Do ESPHome and Tasmota remove the need to check pin assignments?
No. Both simplify firmware creation, but the configuration still has to match the board’s exposed GPIOs, voltage levels and available peripherals. Verify the exact board definition before enabling a component or template.
Recommended Free Tools
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

