3.FSR with Buzzer
- Get link
- X
- Other Apps
FSR with Buzzer
Circuit:
- FSR Setup:
- Connect one end of the FSR to 5V.
- Connect the other end of the FSR to an analog pin (e.g., A0) and a 10kΩ resistor.
- Connect the other side of the resistor to GND.
- Buzzer Setup:
- Connect the positive terminal of the buzzer to a digital pin (e.g., pin 11).
- Connect the negative terminal of the buzzer to GND.
Code:
The code below reads the FSR value and activates the buzzer if the force exceeds a defined threshold.
C++Code
int fsrPin = A0; // Analog pin connected to FSR
int fsrReading; // Variable to store the FSR reading
int threshold = 600; // Threshold value to activate the buzzer
int buzzerPin = 11; // Pin connected to the buzzer
void setup() {
pinMode(buzzerPin, OUTPUT); // Set the buzzer pin as an output
Serial.begin(9600); // Start serial communication at 9600 baud
}
void loop() {
fsrReading = analogRead(fsrPin); // Read the value from FSR
Serial.print("FSR Reading: ");
Serial.println(fsrReading); // Print the FSR reading
if (fsrReading > threshold) {
digitalWrite(buzzerPin, HIGH); // Turn on the buzzer if reading exceeds the threshold
} else {
digitalWrite(buzzerPin, LOW); // Turn off the buzzer if reading is below the threshold
}
delay(500); // Add delay for readability
}
Explanation:
Threshold Setting:
- The
threshold
value defines the FSR reading that will activate the buzzer. Adjust this value depending on how much force you want to trigger the buzzer.
- The
Buzzer Control:
digitalWrite(buzzerPin, HIGH)
will activate the buzzer when the FSR reading exceeds the threshold.digitalWrite(buzzerPin, LOW)
will deactivate the buzzer when the reading is below the threshold.
Testing and Calibration:
- Use the Serial Monitor to observe the
fsrReading
values when different weights or forces are applied. - Adjust the
threshold
based on your needs to ensure the buzzer activates appropriately.
- Use the Serial Monitor to observe the
- Get link
- X
- Other Apps
Comments
Post a Comment