second code day 2

second code day 2

Yichao Xie and Shiran Guo
// Define the pin connected to the pressure sensor (FSR)const int fsrPin = A0;  // FSR sensor connected to analog pin A0
// Define the pin for the LED (pin 13 in this case)const int ledPin = 13;  // LED connected to pin 13
// Define the threshold value to detect pressureint threshold = 300;  // Adjust this value based on your sensor's response
void setup() {  // Start the serial communication  Serial.begin(9600);
  // Wait for the serial port to connect  while (!Serial) {    ; // Wait for the serial port to connect. Needed for native USB port boards.  }
  // Set the LED pin as an output  pinMode(ledPin, OUTPUT);
  // Print a startup message  Serial.println("Pressure Sensor with LED Example Initialized");}
void loop() {  // Read the analog value from the sensor (0 to 1023)  int sensorValue = analogRead(fsrPin);
  // Print the sensor value to the serial monitor (optional)  Serial.print("FSR Value: ");  Serial.println(sensorValue);
  // Check if the sensor value exceeds the threshold  if (sensorValue > threshold) {    Serial.println("Pressure Sensed");  // Print when pressure is detected
    // Turn on the LED when pressure is sensed    digitalWrite(ledPin, HIGH);  } else {    // Turn off the LED when no pressure is sensed    digitalWrite(ledPin, LOW);  }
  // Add a small delay to make the serial output readable  delay(500);  // 500ms delay}