The magnitude and form of signal from sensors such as microphone, gas sensors, piezo sensors are not in the form that can be sensible be read by the Arduino input pins. And so the sensor signal are often required to be conditioned, transformed into required rated input of the MCU pins. Example of signal conditioning are decreasing the magnitude of the input signal for example 5V to 3.3V using resistor voltage divider, using clamping diode so that the input is between 0V to 5V, using transistor or operational amplifier-based amplifier to amplify the small magnitude sensor signal, using external passive filters such as RC low pass filter, bandpass filter etc. Here I wanted to write about how to use clamp diode so that the Arduino 5V input is not exceeded and to protect the Arduino input pin when used with sensors. This circuit is called a rail-to-rail voltage clamping / input protection circuit for the Arduino’s analog input or any microcontroller input.
Arduino and alike micrcontroller boards have sensitive input pins. If the applied input voltage exceeds the rated MCU input pins voltage then the pin will be damaged. For example, input signal such as from piezo based sensors which can be higher than 5V, for example 6V will damage the input of Arduino Uno board which has rated voltage tolerance of 5V.
Below is circuit diagram that shows how to protect the Arduino pins from high voltage inputs from sensors or something like that.
The ATmega328P microcontroller on the Arduino Uno can be damaged if the voltage on pin A0 goes above 5.5V or below -0.5V. These two diodes prevent out-of-spec signals, static discharge (ESD), or inductive spikes from frying the input pin:
Upper Diode ($D_1$) — Overvoltage Protection:
If the input signal spikes above $+5\text{V} + V_f$ (where $V_f$ is the diode's forward voltage drop), $D_1$ becomes forward biased and dumps the excess voltage into the $+5\text{V}$ power rail.
Lower Diode ($D_2$) — Undervoltage / Reverse Protection:
If the input signal drops below $0\text{V} - V_f$ (negative voltage), $D_2$ turns on and clamps the line close to ground.
Note: For optimal protection, a current-limiting resistor (e.g., $1\text{k}\Omega$ to $10\text{k}\Omega$) should ideally be placed in series between your external signal source and the junction point of the diodes.
Exact Diode Recommendations
While internal ESD protection diodes exist inside the microcontroller, they can only handle micro-amps of current. External diodes allow the circuit to handle higher energy spikes safely.
1. Best Choice: Schottky Diodes (Recommended)
Schottky diodes have a low forward voltage drop ($V_f \approx 0.2\text{V} - 0.4\text{V}$), meaning they turn on quickly and clamp the voltage before it exceeds the ATmega328P's absolute maximum ratings.
BAT54 / BAT54S (Very popular dual-diode in a single SOT-23 package)
BAT42 or BAT43 (Through-hole / DO-35 package)
1N5711 (Fast high-frequency Schottky, DO-35 package)
2. Standard Small-Signal Diodes (Acceptable)
Standard silicon diodes have a slightly higher forward voltage ($V_f \approx 0.6\text{V} - 0.7\text{V}$), but they still offer decent protection for general-purpose circuits.
1N4148 or 1N914 (High-speed switching diodes, cheap and readily available)
Avoid Power Rectifiers
Do not use heavy power rectifier diodes like the 1N4007 or 1N5408 here. They have high junction capacitance and slow switching speeds, which can distort fast-changing signals on an analog input pin.