Efficient and Safe ESP32 designs using NO and NC buttons

Protonest IoT
3 min readFeb 5, 2024

--

In embedded systems and IoT devices, especially those powered by the versatile ESP32 microcontroller(Amazon), the efficient and safe use of digital inputs like buttons can significantly impact the overall performance and reliability of an application.

This article discusses the Normally Open (NO) and Normally Closed (NC) buttons, exploring their applications, energy efficiency, and safety implications. With practical code snippets and wiring diagrams, we’ll guide you on harnessing these components effectively, ensuring your ESP32 projects stand out in both functionality and resilience.

Understanding NO and NC Buttons

let’s clarify what we mean by NO and NC buttons,

- Normally Open Amazon (NO) buttons are in an open circuit state when at rest. Pressing the button closes the circuit, allowing current to flow.

- Normally Closed Amazon (NC) buttons, conversely, start in a closed circuit state, with the circuit opening upon pressing the button.

Energy Efficiency with Normally Open Buttons

  • NO buttons are important in designs where energy conservation is essential.
  • In their default open state, no current flows, making them ideal for battery-operated or low-power ESP32 applications.
  • They’re commonly used in user interfaces, remote controls, and situations where the input is active only occasionally.

Wiring

GPIO Pin (configured with internal pull-up)↔ NO Button↔ GND

#define BUTTON_PIN 0 // Use an appropriate GPIO pin

void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), buttonPressHandler, FALLING);
}

void buttonPressHandler() {
// Handle button press event
}

In this setup, the ESP32 wakes from sleep mode to perform actions only on the button press, conserving energy during idle periods.

Safety with Normally Closed Buttons

NC buttons are used in safety-critical applications. Their default closed state means any wire break or failure leads to an open circuit, immediately signaling the system to take protective action, such as shutting down machinery or triggering an alarm.

Wiring

GPIO Pin ↔ NC Button↔ VCC

GPIO Pin ↔ 10KΩ Pull-Down Resistor ↔ GND

#define SAFETY_BUTTON_PIN 2 // Use an appropriate GPIO pin

void setup() {
pinMode(SAFETY_BUTTON_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(SAFETY_BUTTON_PIN), emergencyStopHandler, RISING);
}

void emergencyStopHandler() {
// Execute emergency stop routines
}

This configuration ensures that any failure in the button’s circuit prompts an immediate response, enhancing the system’s safety.

When designing with the ESP32, the strategic use of NO and NC buttons can markedly improve your project’s energy efficiency and safety profile.

Whether you’re developing a power-sensitive remote sensor or a fail-safe industrial control system, understanding and applying these principles will elevate your designs.

Remember, the choice between NO and NC isn’t just technical — it reflects your project’s priorities and values.

By incorporating these insights and code examples into your ESP32 projects, you’re not just building circuits, you’re engineering smarter, safer, and more sustainable solutions.

Contact us for any IoT prototype

Protonest for more details.

Protonest specializes in transforming IoT ideas into reality. We offer prototyping services from concept to completion. Our commitment ensures that your visionary IoT concepts become tangible, innovative, and advanced prototypes.

Our Website: https://www.protonest.co/

Email: udara@protonest.co

If you enjoyed this article and would like to show some support, consider buying me a coffee on Ko-Fi.

Your support not only helps me keep creating content like this but also fuels me! ☕️📚

Thank you for being an amazing reader!

Here’s my Ko-Fi link: https://ko-fi.com/udarakumarasena

Cheers!

--

--

Protonest IoT
Protonest IoT

Written by Protonest IoT

We make your IoT ideas a reality

No responses yet