No description
- C++ 100%
Implements a system to control two power outputs with a button. The outputs run while the button is held (up to a maximum duration), followed by a pause before re-arming. The system includes a status LED for ready/busy indication and provides serial monitor output for debugging. |
||
|---|---|---|
| README.md | ||
| SprayMotor-NoStopOnButtonRel.ino | ||
Arduino Power Control with Button Trigger
Controls two power outputs using a button with the following behavior:
- When the button is pressed and held, both power outputs run for a maximum of 3 seconds
- If the button is released before 3 seconds, the power outputs stop immediately
- After the power outputs stop, there is a 7-second pause before the power outputs can be started again
- The built-in LED indicates when the system is ready (LED on) or busy (LED off)
Pin Configuration
| Component | Arduino Pin | Notes |
|---|---|---|
| Button | Pin 2 | Active LOW (pressed = LOW, released = HIGH) |
| Power 1 | Pin 4 | Digital output |
| Power 2 | Pin 8 | Digital output |
| Status LED | LED_BUILTIN (Pin 13) | Built-in LED for ready indication |
Wiring Setup
Button Connection
- Connect one terminal of the button to Pin 2
- Connect the other terminal to GND
- The internal pull-up resistor is enabled in code, so no external resistor is needed
Power Output Connections
- Power 1: Connect to Pin 4 (through appropriate driver circuit)
- Power 2: Connect to Pin 8 (through appropriate driver circuit)
Important: Do not connect high-power loads directly to Arduino pins. Use appropriate driver circuits (like relays, MOSFETs, or transistors) to handle power requirements for your specific application.
Status LED
- Uses the built-in LED on Pin 13 (LED_BUILTIN)
- LED ON = System ready/idle
- LED OFF = Power outputs running (busy)
Operation
- Ready State: LED is ON, system waits for button press
- Button Press: Power outputs start, LED turns OFF
- Running: Power runs while button is held (max 3 seconds)
- Stop: Power stops when button is released OR after 3 seconds
- Pause: 7-second pause with LED OFF before returning to ready state
Configuration
You can modify these constants in the code:
const uint32_t K_MAXIMUM_DURATION = 3000ul; // Maximum power run time (ms)
const uint32_t K_PAUSE_DURATION = 7000ul; // Pause duration after stop (ms)
const uint32_t K_BTN_READ_TIME = 20ul; // Button debounce time (ms)
Serial Monitor
The code outputs status messages at 19200 baud:
- "Button pressed"
- "Button released"
- "Power running"
- "Power halted"
- "Armed"