Voltage Levels in Modern Electronics
Traditional microcontrollers like Arduino Uno operate at 5V logic levels, while modern platforms such as ESP32, Raspberry Pi, and many IoT devices use 3.3V logic. PIR sensors come in both flavors, and using the wrong voltage can damage your microcontroller or result in unreliable detection.
3.3V-Compatible PIR Sensors
These sensors are designed to operate from 3.3V supply and output 3.3V logic levels. They are safe to connect directly to 3.3V microcontrollers.
Common 3.3V Sensors:
- AM312: 2.7-12V input, output 3.0V (ideal for 3.3V systems)
- Panasonic EKMB series: Low power, 3.3V versions available
- RCWL-0516: Microwave radar, but often 3.3V compatible
- Some HC-SR501 clones: Check datasheet; many actually work at 3.3V but output may be lower.
5V PIR Sensors
Classic sensors like the original HC-SR501 require 5V supply and output 3.3V (some output 5V). They can often be used with 5V Arduinos directly.
Common 5V Sensors:
- HC-SR501: 4.5-20V input, output 3.3V (typically)
- HC-SR505: 4.5-20V input, output 3.3V
- DYP-ME003: Similar to HC-SR501
Mixing Voltage Levels: What Can Go Wrong?
Scenario A: 5V sensor output to 3.3V microcontroller input
If the sensor outputs 5V logic HIGH, it may exceed the maximum input voltage of the 3.3V pin (often 3.6V absolute max), potentially damaging the microcontroller.
Scenario B: 3.3V sensor powered by 5V
If you power a 3.3V-only sensor with 5V, you may destroy the sensor.
Scenario C: 5V sensor powered by 3.3V
The sensor may not function correctly, or may be unstable.
Level Shifting Solutions
If you have a 5V sensor and need to connect to a 3.3V microcontroller, you have options:
1. Voltage Divider
Use two resistors to divide the output voltage from 5V to ~3.3V. For example: 10kΩ from output to microcontroller pin, and 20kΩ from pin to ground. This is simple and cheap but may slow down signal edges.
2. Logic Level Converter Module
Bi-directional logic level converters (e.g., based on BSS138 MOSFET) are available for a few dollars and work well for digital signals.
3. Use a 3.3V Sensor
The easiest solution: select a sensor designed for 3.3V operation, such as AM312 or Panasonic EKMB.
Power Supply Considerations
If your system has both 5V and 3.3V rails, you can power the sensor from the appropriate rail. For example, an Arduino can provide 5V, while an ESP32 can provide 3.3V. Always check the sensor’s voltage range.
Sensor Output Voltage Measurements
Here are typical output voltages for common sensors when powered at their rated voltage:
| Sensor | Supply Voltage | Output HIGH |
|---|---|---|
| HC-SR501 | 5V | 3.3V |
| HC-SR505 | 5V | 3.3V |
| AM312 | 3.3V | 3.0V |
| Panasonic EKMB (3V) | 3V | 2.8V (open drain, requires pull-up) |
Pull-up Resistors
Some sensors (like Panasonic EKMB) have open-drain outputs, requiring an external pull-up resistor to VCC. This is actually convenient for level shifting: you can pull up to 3.3V even if the sensor is powered at 5V.
Recommendations
- For new designs with 3.3V microcontrollers, choose 3.3V-compatible sensors (AM312, Panasonic low-power series).
- If you must use HC-SR501 with 3.3V logic, use a level shifter or verify that the output is indeed 3.3V (many are).
- Always check the datasheet or test with a multimeter before connecting.
Conclusion
Voltage compatibility is a crucial consideration when integrating PIR sensors. By understanding your sensor’s output and your microcontroller’s input requirements, you can avoid damage and ensure reliable operation.
