#include // Pin Definitions #define SENSOR_PIN A0 // Analog Pin for Step Response #define PIN D10 #define NUMPIXELS 5 // Number of LEDs in the strip // Threshold Settings #define CALI_CNT 50 // Calibration samples #define THRESHOLD 50 // Sensitivity threshold Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); #define DELAYVAL 1000 // Time (ms) to pause between pixels // Variables int baseline = 0; // Calibration baseline bool ledState = false; // false = OFF, true = ON void setup() { Serial.begin(9600); // For debugging pinMode(PIN, OUTPUT); // Initial Calibration baseline = calibrate(SENSOR_PIN); Serial.print("Calibration Baseline: "); Serial.println(baseline); // INITIALIZE NeoPixel strip object (REQUIRED) pixels.begin(); pixels.clear(); pixels.show(); } void loop() { int reading = stepResponseRead(SENSOR_PIN); Serial.print("Reading: "); Serial.println(reading); if (reading > (baseline + THRESHOLD)) { delay(200); // Debounce delay // Toggle LED State ledState = !ledState; // Flip state if (ledState) { // Turn ON LED for(int i=0; i (baseline + THRESHOLD)) { delay(10); } } } // Step Response Read Function int stepResponseRead(int pin) { pinMode(pin, OUTPUT); digitalWrite(pin, HIGH); delayMicroseconds(50); // Charge the pin pinMode(pin, INPUT); // Switch to input delayMicroseconds(100); // Wait a bit int value = analogRead(pin); // Measure discharge return value; } // Calibration Function int calibrate(int pin) { long sum = 0; for (int i = 0; i < CALI_CNT; i++) { sum += stepResponseRead(pin); delay(200); } return (sum / CALI_CNT); // Return average }