2. FSR with led

 FSR with led

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. LED Setup:
    • Connect the positive (anode) of the LED to a digital pin (e.g., LED1 to pin 13, as per your setup).
    • Connect the negative (cathode) of the LED to a current-limiting resistor (e.g., 220Ω) and then to GND.

Code:

The code below reads the FSR value and turns on the LED 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 turn on the LED int ledPin = 13; // Pin connected to LED1 void setup() { pinMode(ledPin, OUTPUT); // Set the LED 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(ledPin, HIGH); // Turn on the LED if reading exceeds the threshold } else { digitalWrite(ledPin, LOW); // Turn off the LED if reading is below the threshold } delay(500); // Add delay for readability }

Explanation:

  1. Threshold Setting:

    • The threshold variable defines the FSR reading value needed to turn on the LED. You can adjust this threshold based on your requirements and the weight/pressure you want to detect.
  2. Reading and LED Control:

    • analogRead(fsrPin) reads the FSR value (0-1023).
    • If fsrReading exceeds the threshold, digitalWrite(ledPin, HIGH) turns on the LED. Otherwise, digitalWrite(ledPin, LOW) turns it off.
  3. Adjusting the Threshold:

    • You can test the circuit with different pressures and note the corresponding fsrReading values in the Serial Monitor. Adjust threshold accordingly to achieve the desired LED behavior.


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