3.FSR with Buzzer

 FSR with Buzzer

Circuit:

  1. 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.
  2. 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:

  1. 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.
  2. 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.
  3. 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.


Comments

Popular posts from this blog

2.Controlling LEDs with a Keypad and Arduino

Measuring and Displaying Solar Panel Voltage on an LCD using Arduino

4.Displaying Weight and Force from an FSR on an I2C LCD using Arduino