Chayma

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

// Constants

const int hallEffectSensorPin = 2; // Pin connected to the hall effect sensor


output
const int buzzerPin = 9; // Pin connected to the buzzer

// Variables
volatile int hallEffectPulses = 0; // Variable to store the number of pulses from
the hall effect sensor

void setup() {
// Configure the hall effect sensor pin as an input and enable its interrupt
pinMode(hallEffectSensorPin, INPUT);
attachInterrupt(digitalPinToInterrupt(hallEffectSensorPin), hallEffectInterrupt,
RISING);

// Configure the buzzer pin as an output


pinMode(buzzerPin, OUTPUT);

// Initialize the hall effect pulses variable


hallEffectPulses = 0;
}

void loop() {
// Do any other processing here

// Check the hall effect sensor pulses to see if the cane has fallen or been lost
if (hallEffectPulses >= 10) { // If 10 or more pulses have been detected
// Turn on the buzzer
digitalWrite(buzzerPin, HIGH);

// Wait for 10 seconds


delay(10000);

// Turn off the buzzer


digitalWrite(buzzerPin, LOW);

// Reset the hall effect sensor pulses


hallEffectPulses = 0;
}
}

// Interrupt service routine for the hall effect sensor


void hallEffectInterrupt() {
// Increment the hall effect sensor pulses
hallEffectPulses++;
}

You might also like