FSR LED System

I also posted this in the sensor forum, let me know if crossposting is not allowed

Hi all,

I am building a small project that has 3 LEDs and an FSR sensor. Essentially, I want each LED to light up SEPARATELY as more pressure is applied. Here is what I want in pseudo code.

0-50 - no LEDs are lit
50-400 - only first LED is lit
400 - 700 - only second LED is lit
700 - 1000 - only third LED is lit

my serial print is working, and the FSR is projecting a nice range from 0-900

my code at the moment just lights up the first two, and the pressure controls brightness for some reason, even though I never defined brightness as a value.

HERE IS MY CODE

int sensorPin = A0;
int ledPin1 = 13;
int ledPin2 = 11; 
int ledPin3 = 10; 

int sensorValue = 0;
int noPressure = 50; 
int lowPressure = 400; 
int goodPressure = 700; 
int hiPressure = 1000;


void setup() {
 pinMode(sensorPin, INPUT); 
 pinMode(ledPin1, OUTPUT); 
 pinMode(ledPin2, OUTPUT); 
 pinMode(ledPin3, OUTPUT); 

 Serial.begin(9600);

}

void loop() {
 sensorValue = analogRead(sensorPin); //reads pin value, assigns it to sensorValue

 Serial.println(sensorValue);

 if (sensorValue <= noPressure)
 {
   digitalWrite(ledPin1, LOW); 
   digitalWrite(ledPin2, LOW); 
   digitalWrite(ledPin3, LOW); 
 }

 if (sensorValue < lowPressure)
 {
   digitalWrite(ledPin1, LOW); 
   digitalWrite(ledPin2, LOW); 
   digitalWrite(ledPin3, HIGH);
 }

 else(ledPin3, LOW);

 if (sensorValue < goodPressure) 
 {
   digitalWrite(ledPin1, LOW); 
   digitalWrite(ledPin2, HIGH); 
   digitalWrite(ledPin3, LOW);
 }

 else(ledPin2, LOW);

 if (sensorValue < hiPressure) 
 {
   digitalWrite(ledPin1, LOW); 
   digitalWrite(ledPin2, LOW); 
   digitalWrite(ledPin3, HIGH);
 }

 else(ledPin3, LOW);
}

Hello @georgiaes,

georgiaes:
I also posted this in the sensor forum, let me know if crossposting is not allowed

It is not. Other thread removed.

Assume sensorValue is 23. Start at the first if statement...

...
 if (sensorValue <= noPressure)
...

Work your way down through the code. Try to determine how execution flows (which then-clauses run because the if-condition is true). I find a print out and pen to be useful for such things.

Can you see why the program is doing what it is doing?

Delta_G:
Please read the "How to use this forum" thread at the top of any of the message boards. In the coding and electronics world, a good starting place is always to read the instructions.

That would also help you a lot with your current dilemma. If you'll look at some code examples, you'll notice that NONE of them look like

else(ledPin3, LOW);

Uh oh. How do you have things wired up? Do you have resistors on those LEDs?

Hi, thanks for the response. I will review other coding examples, I am pretty new to programming. Do you have any suggestions on how I can apply (properly notated) if/else statements to my project?

I am confident in my wiring, I have resistors on each LED and I have run my current set-up through a simpler project to see if each of the LEDs were working properly.