Skip to content
Back to skills

Esp32 Isolated Digital Input

ASecurity

Use when an ESP32 reads 24 V industrial signals - a PLC output, a proximity sensor, a dry contact - and the input must survive reverse polarity and ground differences. Covers opto input design, thresholds and debounce.

  • 16 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 7, 2026
ai-agentsgit

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned November 7, 2026

npx -y skills add Esmail-sarhadi/esp32-agent-skills --skill esp32-isolated-digital-input --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Esp32 Isolated Digital Input?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Esp32 Isolated Digital Input
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/esmail-sarhadi-esp32-isolated-digital-input/badge)](https://www.skillsdirectory.com/skills/esmail-sarhadi-esp32-isolated-digital-input)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: esp32-isolated-digital-input
description: Use when an ESP32 reads 24 V industrial signals - a PLC output, a proximity sensor, a dry contact - and the input must survive reverse polarity and ground differences. Covers opto input design, thresholds and debounce.
license: MIT
---

# 24 V digital inputs on ESP32

A 24 V signal cannot touch a GPIO. The interface is an optocoupler, a resistor
and a decision about polarity.

## The basic chain

```
24V field --[ R ]--+-- opto LED --> opto transistor -- pull-up --> GPIO
                   |
                 reverse diode
```

- **R** sets the LED current. A typical opto wants 5 to 10 mA; at 24 V that is
  2.2 to 4.7 kohm, and the resistor dissipates 0.1 to 0.25 W - use a 0.5 W part.
- **Reverse diode** across the LED protects against a miswired supply. Without
  it, reverse polarity destroys the opto instantly.
- **The transistor side** pulls the GPIO low when active; enable the internal
  pull-up, or fit an external 10 kohm.

## Thresholds that match real sensors

| Input | Typical on-state |
|---|---|
| PLC output (sourcing) | 24 V, 7 mA minimum per IEC 61131-2 type 1 |
| Proximity sensor PNP | 24 V, 10 to 200 mA |
| Dry contact | needs wetting current, 5 to 10 mA |

A dry contact with 1 mA of wetting current will eventually fail to make contact -
oxide builds up. If the input is a relay contact, keep at least 5 mA through it.

## Speed vs protection

An opto with a 4.7 kohm resistor and no speed-up capacitor is slow: 10 to 50 us.
That is fine for a pushbutton and wrong for an encoder. For fast inputs, use a
digital isolator (Si8610, ISO7721) instead of an opto.

## Debounce belongs in the firmware, not the hardware

20 ms of software debounce covers contact bounce and survives a firmware change.
A hardware RC that is too slow hides fast pulses and cannot be tuned later.

## Symptom table

| Symptom | Usually |
|---|---|
| input reads active with nothing connected | no pull-up, floating opto collector |
| reads inactive at 24 V | LED current too low, resistor too large |
| dies on reverse polarity | no reverse diode |
| counts on every motor start | no common-mode filtering, shared return |
| misses short pulses | opto too slow, or debounce too long |

## Agent rules

- State the resistor value, its power rating and the resulting LED current.
- Say whether the input is sinking or sourcing, and match the sensor type.
- Keep field ground and logic ground separate; the opto is the only bridge.

Files in this skill

  • LICENSE.txt857 B
  • SKILL.md2.4 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.