Skip to content

Tailslide/BlastGateServo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BlastGateServo

Blast gate servo controller for Arduino

See 3d printed parts at : https://www.thingiverse.com/thing:3301904

Features

  • Allows a single push button to switch between different blast gates, with only a single one open at a time
  • Currently open blast gate is indicated by an LED
  • Optional automatic control using AC current sensors to detect active tools
  • Debug output support for troubleshooting
  • Configurable servo positions for precise gate control

Hardware Requirements

Development Setup

  1. Install Visual Studio Code
  2. Install PlatformIO IDE extension for VSCode
  3. Open this project folder in VSCode
  4. PlatformIO will automatically install required dependencies:
    • Servo library (v1.2.1 or later)

Building and Uploading

  1. Connect your Arduino Uno to your computer via USB
  2. In VSCode:
    • Click the PlatformIO icon in the sidebar
    • Under Project Tasks:
      • Click "Build" to compile
      • Click "Upload" to flash to Arduino
    • Use "Monitor" to view serial output (when debugging is enabled)
  3. Serial monitor is configured at 9600 baud

Operation Modes

  • Normal Mode: Use the push button to cycle through gates. After selecting a gate, wait briefly and it will open automatically.
  • Meter Mode: For calibrating AC sensors:
    1. Power off the Arduino
    2. Press and hold the button
    3. While holding the button, power on the Arduino
    4. Release the button after power-up
    5. LEDs will now act as signal strength indicators:
      • Each LED corresponds to an AC sensor
      • Turn on a device on the cable being calibrated
      • Rotate the sensor clamp around the cable
      • LED will blink faster (or become solid) when sensor is optimally positioned
  • Debug Mode: Enable detailed serial output by setting DEBUG flag (enabled by default)
  • LED Test Mode: Enable by uncommenting DEBUG_LED_TEST in Configuration.h. Flashes each LED in sequence to verify connections.
  • Servo Test Mode: Enable by uncommenting DEBUG_SERVO_TEST in Configuration.h. Opens and closes a specified servo with each button press without initializing other components. Set TEST_SERVO_INDEX in Configuration.h to select which servo to test (1 = first servo, 2 = second servo, etc.). Useful for testing servo functionality and calibration. The system will properly handle disabled servos (pins set to -1) by controlling only the LED while skipping servo movement.

Configuration

All settings can be adjusted in Configuration.h:

Basic Settings

  • Number of gates (NUM_GATES) - up to 5 supported
  • Number of AC sensors (NUM_AC_SENSORS) - typically one per gate
  • Number of LEDs (NUM_LEDS) - typically one per gate
  • Button pin assignment (BUTTON_PIN)

Timing Settings

  • CLOSE_DELAY - Time it takes for a gate to close (ms)
  • OPEN_DELAY - Time after last button push to open gate (ms)
  • MAX_BLINK_LEN - LED blink rate (adjusted automatically in debug mode)

AC Sensor Settings

  • NUM_OFF_SAMPLES - Number of samples for checking average sensor off values
  • NUM_OFF_MAX_SAMPLES - Milliseconds to sample for max off value at startup
  • AVG_READINGS - Number of readings to average when triggering gates (max 50)
  • AC_SENSOR_SENSITIVITY - Trigger threshold multiplier (2.0 = twice max off reading)

Flutter Protection Settings

The system includes comprehensive protection against AC sensor flutter that could cause rapid servo cycling and potential hardware damage:

  • AC_SENSOR_SENSITIVITY_ON (default: 2.0) - Threshold multiplier to turn tool ON
  • AC_SENSOR_SENSITIVITY_OFF (default: 1.5) - Threshold multiplier to turn tool OFF (creates hysteresis)
  • DEBOUNCE_STABLE_READINGS (default: 3) - Number of consecutive stable readings required before state change
  • MIN_SERVO_INTERVAL_MS (default: 2000) - Minimum milliseconds between operations on the same gate
  • MAX_OPS_PER_MINUTE (default: 10) - Maximum operations per minute before emergency shutdown
  • ERROR_FLASH_INTERVAL_MS (default: 200) - LED flash interval when in error state

How Flutter Protection Works

  1. Hysteresis: Uses different thresholds for turning ON (2.0x baseline) vs turning OFF (1.5x baseline) to prevent rapid toggling around a single threshold
  2. Debouncing: Requires 3 consecutive stable sensor readings before changing gate state, filtering out momentary noise spikes
  3. Minimum Interval with Queuing: Enforces 2-second minimum between operations on the same gate
    • If a gate operation is requested during the cooldown period, it is automatically queued
    • The queued operation executes automatically once the minimum interval expires
    • This ensures responsive operation while preventing rapid cycling
    • Example: If you turn on a tool immediately after turning it off, the gate will open automatically 2 seconds later
  4. Rate Limiting: Tracks operations per minute and enters error state if limit exceeded
  5. Error State: When too many operations detected (flutter condition):
    • All LEDs flash rapidly in error pattern
    • All automatic gate operations are disabled
    • System requires restart to recover
    • Alerts user to problematic sensor or configuration issue

Pin Assignments

  • Servo pins (SERVO_PIN_1 through SERVO_PIN_5)
    • Set any servo pin to -1 to disable that servo while maintaining the gate numbering
    • Example: Setting SERVO_PIN_2 to -1 disables the second servo but keeps gate 3 as "gate 3" in the UI
  • AC sensor pins (AC_SENSOR_PIN_1 through AC_SENSOR_PIN_5)
  • LED pins (LED_PIN_1 through LED_PIN_5)

Servo Position Configuration

  • SERVO_MAX_x - Maximum position for each servo (typically 180 degrees)
  • SERVO_MIN_x - Minimum position for each servo (typically 0 degrees)
  • GATE_CLOSED_AT_MAX_x - Determines gate orientation:
    • Set to true (default) if gate is closed when servo is at max position
    • Set to false if gate is open when servo is at max position (inverted)
  • Set any servo's MAX/MIN values even if the pin is disabled (-1) to maintain consistent configuration

Project Structure

  • src/BlastGateServo.cpp - Main program file with setup and loop
  • include/Configuration.h - All user configurable settings
  • include/GateServos.h/cpp - Servo control and position management
  • include/AcSensors.h/cpp - AC current sensor reading and threshold detection
  • include/Debug.h - Debug output macros and configuration
  • platformio.ini - PlatformIO project configuration and library dependencies

Changes

  • Created 2019-01-02 - Greg Pringle
  • Updated 2019-01-20 - Greg Pringle - Added AC sensor support
  • Updated 2025-01-26 - Added VSCode/PlatformIO support
  • Updated 2025-02-16 - Added detailed configuration documentation and converted to proper C++ structure
  • Updated 2025-02-26 - Added support for disabling specific servos (set pin to -1) while maintaining gate numbering
  • Updated 2025-02-26 - Fixed button timing logic to properly open gates after selection
  • Updated 2025-02-26 - Improved timer logic to ensure gates open/close reliably, reduced OPEN_DELAY to 800ms
  • Updated 2025-02-26 - Implemented proper button debouncing and state machine for more reliable operation
  • Updated 2025-02-26 - Fixed issue with servos not moving when button was pressed
  • Updated 2025-02-26 - Enhanced gate selection to automatically skip disabled gates when cycling through options
  • Updated 2025-02-27 - Fixed compiler warnings in Configuration.h (removed redundant header guard and corrected version number format) and in GateServos.h (fixed signed/unsigned comparison by changing opendelay type to unsigned long)
  • Updated 2025-02-27 - Added gate orientation configuration (GATE_CLOSED_AT_MAX_x) to support different physical gate setups where gates may be open when up or closed when up
  • Updated 2025-12-08 - Implemented comprehensive flutter protection system to prevent AC sensor flutter from damaging hardware:
    • Added hysteresis (different ON/OFF thresholds) to prevent rapid state toggling
    • Implemented debouncing requiring 3 consecutive stable readings before state change
    • Added minimum 2-second interval between servo operations on same gate with automatic queuing
    • Operations requested during cooldown are queued and execute automatically when interval expires
    • Implemented rate limiting with emergency shutdown if more than 10 operations per minute
    • Added error state with flashing LED pattern and system halt on flutter detection
    • All protection settings are configurable in Configuration.h

About

Blast gate servo controller for Arduino

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published