A binary input is a digital circuit interface that reads physical voltage or current levels and translates them into one of two discrete logic states: ON (1/High) or OFF (0/Low). Instead of measuring the exact magnitude of a signal, a binary input simply checks if the signal crosses a specific threshold. This fundamentally changes how you design a control system: it replaces complex, noise-susceptible analog measurement circuits with robust, threshold-based state detection, allowing microcontrollers and PLCs to reliably monitor physical events like switch closures, limit triggers, or liquid levels.
People commonly confuse binary inputs with analog inputs (which measure a continuous voltage range, like 0-10V, using an ADC) and with serial digital communication (like I2C or UART, which transmit multi-bit binary data streams over time). A binary input is strictly a single-wire, single-state snapshot at any given millisecond.
Thresholds, Hysteresis, and Logic Levels
Every binary input relies on a comparator circuit—either internal to a microcontroller or external on a PLC input module—to decide if a voltage represents a logic 1 or a logic 0. This decision is never a single knife-edge line; it relies on a noise margin.
For example, according to the Espressif ESP32 GPIO documentation, a standard 3.3V logic pin defines its thresholds as follows:
- Input Low Voltage ($V_{IL}$): Maximum 0.25 × VDD (approx. 0.825V). Anything below this is guaranteed to read as a 0.
- Input High Voltage ($V_{IH}$): Minimum 0.75 × VDD (approx. 2.475V). Anything above this is guaranteed to read as a 1.
The gap between 0.825V and 2.475V is the undefined region. If your signal hovers here due to electrical noise or a floating wire, the binary input will behave erratically. To prevent this, quality binary inputs employ Schmitt trigger hysteresis, which applies two different thresholds depending on whether the voltage is rising or falling, effectively eliminating noise-induced state chatter.
Worked Example: Dropping 24V to 3.3V for an ESP32 Binary Input
Let’s look at a real-world scenario. You have a 24V DC PNP inductive proximity sensor (e.g., an Omron E2E series) and want to read its ON/OFF state into an ESP32-WROOM-32 GPIO pin.
To safely interface these two systems, we use an optocoupler (like the ubiquitous PC817) to provide galvanic isolation. Here is the exact math to size the current-limiting resistor for the optocoupler’s internal LED:
- Source Voltage ($V_{source}$): 24V DC (when the sensor triggers).
- LED Forward Voltage ($V_f$): The PC817 datasheet specifies a typical $V_f$ of 1.2V.
- Target LED Current ($I_f$): We want 5mA. This is well below the 50mA absolute maximum, ensuring the LED lasts for years without degradation, while still providing enough current to saturate the phototransistor.
Resistor Calculation:
$R = (V_{source} - V_f) / I_f$
$R = (24V - 1.2V) / 0.005A$
$R = 22.8V / 0.005A = 4560\Omega$
The nearest standard E24 resistor value is 4.7kΩ.
Power Dissipation Check:
$P = I^2 \times R$
$P = (0.005A)^2 \times 4700\Omega = 0.1175W$
Since 0.1175W is less than half the capacity of a standard 1/4W (0.25W) through-hole resistor, a 1/4W 4.7kΩ resistor is perfectly safe and will not overheat.
On the ESP32 side, you configure the GPIO as an input with an internal pull-up resistor enabled. When the 24V sensor fires, the optocoupler LED turns on, activating the phototransistor, which pulls the ESP32 pin to GND (reading as a logic LOW). You simply invert the logic in your code.
Where You Meet Binary Inputs in Practice
Binary inputs are the backbone of state monitoring across three major domains:
1. Industrial PLCs
Programmable Logic Controllers (like the Allen-Bradley Micro850 or Siemens S7-1200) use heavily isolated binary input cards to read limit switches, E-stop buttons, and photoelectric sensors. These inputs are designed to withstand massive voltage spikes and ground loops common in factory environments, often requiring 5mA to 10mA of current just to register an ON state to prevent false triggers from capacitive coupling in long cable runs.
2. Home Security and Fire Alarm Panels
Boards from DSC or Honeywell use binary inputs configured as "dry contacts" for door/window magnet switches and PIR motion sensors. Instead of just looking for a short or an open, these panels use an End-of-Line (EOL) resistor (typically 2kΩ or 5.6kΩ). The binary input circuit actually measures the resistance of the loop; if it reads the exact resistor value, the zone is secure. If it reads 0Ω (short) or infinite Ω (open/cut wire), it triggers an alarm or tamper fault.
3. Embedded Microcontroller Projects
Reading a mechanical toggle switch, a digital water leak sensor, or a rotary encoder via a GPIO pin. As detailed in Electronics Tutorials' guide on optocouplers, isolating these inputs is crucial if the external sensor shares a noisy ground plane with the microcontroller.
Sinking vs. Sourcing: The Wiring Trap
The most common reason a binary input fails to work on the bench or jobsite is a mismatch between sinking and sourcing architectures. If you wire a sourcing sensor to a sourcing PLC input, the circuit will never complete, and the input will remain dead.
| Architecture | How it Works | Common Regions / Brands | Wiring Rule |
|---|---|---|---|
| Sinking Input | The input module provides the path to Ground (0V). It "sinks" current from the sensor. | Common in Europe; Siemens PLCs. | Must be paired with a Sourcing sensor (PNP) that outputs positive voltage. |
| Sourcing Input | The input module provides the positive voltage (VCC). It "sources" current to the sensor. | Common in North America; Allen-Bradley PLCs. | Must be paired with a Sinking sensor (NPN) that connects the signal to Ground. |
For a deep dive into industrial wiring, the PLC Academy's guide on sinking vs sourcing provides excellent visual diagrams of current flow. When in doubt, use a relay or an optocoupler to break the electrical dependency and bridge the two architectures safely.
Binary Input FAQ
What is the difference between a binary input and an analog input?
A binary input acts as a simple comparator, outputting only a 1 or a 0 based on whether a voltage crosses a specific threshold (e.g., above 2.5V is ON, below 1.0V is OFF). An analog input uses an Analog-to-Digital Converter (ADC) to measure the exact voltage level across a continuous range (e.g., reading 1.73V out of a 3.3V maximum). Use binary inputs for switches and presence detection; use analog inputs for temperature, pressure, or light intensity measurement.
Can I connect a 12V sensor directly to an Arduino binary input pin?
No. Standard 5V Arduino boards (like the Uno or Mega) have an absolute maximum GPIO voltage of 5.5V. Applying 12V will fry the ATmega328P microcontroller. You must use a voltage divider (e.g., a 10kΩ and 5.6kΩ resistor network) to drop the 12V signal down to a safe ~4.3V logic HIGH, or use an optocoupler for total isolation.
Why does my PLC binary input read ON when the wire is disconnected?
This is almost always caused by capacitive coupling or "phantom voltage" in long, unshielded sensor cables running parallel to high-voltage AC mains lines. The AC electric field induces a small AC voltage in the disconnected DC wire. Because PLC binary inputs have high impedance when OFF, this induced voltage can cross the logic threshold. The fix is to install a pull-down resistor (typically 1kΩ to 4.7kΩ) across the input terminal and the 0V common to bleed off the induced charge.
How do I debounce a mechanical switch on a binary input?
Mechanical switch contacts physically bounce when closed, causing a single press to register as dozens of rapid ON/OFF transitions. You can fix this in hardware by adding an RC low-pass filter (e.g., a 10kΩ series resistor and a 100nF capacitor to ground) to smooth the voltage transition. Alternatively, handle it in software by reading the binary input state, waiting 20 to 50 milliseconds using a non-blocking timer (like millis() in Arduino), and checking the pin state again to confirm it has settled.






