void loop() {
// Read the analog value from the weight sensor
int sensorValue = analogRead(weightSensorPin);
// Map the sensor value to a range (adjust according to your sensor specifications)
int mappedValue = map(sensorValue, 0, 1023, 0, 100);
// Display the raw and mapped values
Serial.print("Sensor Value: ");
Serial.print(sensorValue);
Serial.print("\tMapped Value: ");
Serial.println(mappedValue);
// Check if weight exceeds a certain threshold (adjust as needed)
if (mappedValue > 50) {
digitalWrite(ledPin, HIGH); // Turn on the LED
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}
delay(1000); // Adjust delay based on your application's requirements
}
https://chat.openai.com/c/dde59da3-db56-4628-a737-3f64fb99131a
arduino ide
const int weightSensorPin = A0; // Analog pin connected to the weight sensor const int ledPin = 13; // Digital pin connected to an LED
void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); }
void loop() { // Read the analog value from the weight sensor int sensorValue = analogRead(weightSensorPin);
// Map the sensor value to a range (adjust according to your sensor specifications) int mappedValue = map(sensorValue, 0, 1023, 0, 100);
// Display the raw and mapped values Serial.print("Sensor Value: "); Serial.print(sensorValue); Serial.print("\tMapped Value: "); Serial.println(mappedValue);
// Check if weight exceeds a certain threshold (adjust as needed) if (mappedValue > 50) { digitalWrite(ledPin, HIGH); // Turn on the LED } else { digitalWrite(ledPin, LOW); // Turn off the LED }
delay(1000); // Adjust delay based on your application's requirements }