I need help with the following code. int fsrPin = 0; int fsrReading; void setup(
ID: 673036 • Letter: I
Question
I need help with the following code.
int fsrPin = 0;
int fsrReading;
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
fsrReading = analogRead(fsrPin);
Serial.print("Analog reading = ");
Serial.print(fsrReading);
if (fsrReading > 1) {
Serial.println(" - No pressure");
} else {
Serial.println(" - Pressure");
}
delay(1000);
}
This is for Arduino UNO R3, I have connected a FSR(Force Sensing Resistor) to the Arduino. This program reads the pressure value from the Arduino but some how when I put pressure on FSR, the screen shows reading on 0, and when there is no pressure, the screen shows numbers> 0. It shoud be other way around. Pleaseprovide a solution for this problem.
Explanation / Answer
Modified Code:
int fsrPin = 0;
int fsrReading = 0;
void setup(void) {
Serial.begin(9600);
}
void loop(void) {
fsrReading = analogRead(fsrPin);
Serial.print("Analog reading = ");
Serial.print(fsrReading);
if (fsrReading < 1) {
Serial.println(" - No pressure");
} else {
Serial.println(" - Pressure");
}
delay(1000);
}