uint8_t fsrPin = 7;
uint8_t redLed = A1;
uint8_t greenLed = A2;
uint8_t buzzer = 11;
int force = 0;
void setup() {
Serial.begin(115200);
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
scale.begin(dataPin, clockPin);
// calibrate();
// load cell calibration factor
scale.set_scale(123.456); // this value is obtained by calibrating the scale with known weights
// reset the scale to zero = 0
scale.tare(20);
}
void loop() {
delay(1000);
force = scale.get_units();
Serial.print("Force :");
Serial.println(force);
if(force < 25){
// LED lights up green under 25 pounds
digitalWrite(greenLed, 1);
digitalWrite(redLed, 0);
// when it’s under 25 pounds a buzzer turns on
digitalWrite(buzzer, 1);
}
if(force > 25){
// LED lights up red over 25 pounds
digitalWrite(redLed, 1);
digitalWrite(greenLed, 0);
// when it’s over 25 pounds a buzzer goes off
digitalWrite(buzzer, 0);
}
}
void calibrate(){
if (scale.is_ready()) {
scale.set_scale();
Serial.println("Tare... remove any weights from the scale.");
delay(5000);
scale.tare();
Serial.println("Tare done...");
Serial.print("Place a known weight on the scale...");
delay(5000);
long reading = scale.get_units(10);
Serial.print("Reading: ");
Serial.println(reading);
Serial.println("\nCalibration factor will be the (Reading)/(known weight)");
}
}