week 5 – tom bolsover

this week i nailed down the code, this was done by much trial and error based around the sensor as well as adding time elements into the code so that the coaster can remind the user to either drink more or light up to show them that they are drinking enough.

 

int fsrPin = 0;
int fsrReading;
int fsrVoltage;
unsigned long fsrResistance;
unsigned long fsrConductance;
long fsrForce;

void setup(void) {
Serial.begin(9600);
}

void loop(void) {
fsrReading = analogRead(fsrPin);
Serial.print(“Analog reading = “);
Serial.println(fsrReading);

fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
Serial.print(“Voltage reading in mV = “);
Serial.println(fsrVoltage);

if (fsrVoltage == 0) {
Serial.println(“No pressure”);
} else {
// The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
// so FSR = ((Vcc – V) * R) / V
fsrResistance = 5000 – fsrVoltage; // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance *= 5600;
fsrResistance /= fsrVoltage;
Serial.print(“FSR resistance in ohms = “);
Serial.println(fsrResistance);

fsrConductance = 1000000; // we measure in micromhos so
fsrConductance /= fsrResistance;
Serial.print(“Conductance in microMhos: “);
Serial.println(fsrConductance);

// Use the two FSR guide graphs to approximate the force
if (fsrConductance <= 1000) {
fsrForce = fsrConductance / 80;
Serial.print(“Force in Newtons: “);
Serial.println(fsrForce);
} else {
fsrForce = fsrConductance – 1000;
fsrForce /= 30;
Serial.print(“Force in Newtons: “);
Serial.println(fsrForce);
}
}
Serial.println(“DRINK”);
delay(1000);
}