Pressure Sensor Hook Up and Code: Repeat

I have been having trouble getting my pressure sensor to work with RGB LED’s. Basically the project is a pressure sensor made with conductive fabric and velostat that is hooked up to 10 RGB lED’s

What I am trying to make happen is when the pressure is low, have the LED’s to be BLUE, when the pressure is medium, the LEDs will be GREEN, and when the pressure is at it’s highest range, have the LED’s be RED.

I have been working with the code and hooking up the LED’s, but I’m at a loss. This is my code and I have a breadboard with 10 RGB LED’s connected to the 9, 10, 11 slots and my pressure sensor attached. I only get blue with this:

#define REDLED 9 // red @ 9
#define GREENLED 10 // green @10
#define BLUELED 11 // blue @ 11
#define POT1 A0 //pressure sensor

int i = 0; // We’ll use this to count up and down
int brt = 0; //pot value
int redval= 0;
int blueval = 0;
int greenval = 0;

void setup()
{
pinMode(REDLED, OUTPUT); //tell Arduino LED is an output
pinMode(GREENLED, OUTPUT); //tell Arduino LED is an output
pinMode(BLUELED, OUTPUT); //tell Arudino LED is an output
pinMode(POT1, INPUT); //tell Arduino LED is an output
Serial.begin(9600);

}

void loop(){
brt = abs(analogRead(POT1));
// Serial.print(“Sensor reading;”);Serial.println(brt);
//brt =abs((950-(brt-100)));
brt =abs(brt*3);

//blue def
blueval=((1000-brt)/4); //

//green def
if((brt>=0)||(brt<500)) //
greenval=.2*brt;
else{
{
greenval=250-((brt-500)/2); //
}
}

//red def
redval=.25*brt;

analogWrite(BLUELED, blueval);
analogWrite(GREENLED, greenval);
analogWrite(REDLED, redval);
delay(10);
}

brt = abs(analogRead(POT1));

An analogRead is hardly likely to return a negative value.

brt =abs(brt*3);

And brt is unlikely to change sign since it was assigned.

I only get blue with this:

Have you tested the other LEDs? What values are you getting from your debug prints?

I am getting -5 from my serial monitor.

Comment: brt =abs(brt*3); ----yes this was for a test, it's not in the code.

And what do you mean by what values am i sending to the LED's?

And what do you mean by what values am i sending to the LED's?

What are the values of "redval", "greenval" and "blueval"?

Should be roughly 250

What do you mean "roughly"? You should know exactly - you're calculating them/

I am getting -5 from my serial monitor

Minus 5 what?

blueval=((1000-brt)/4); //

At this point, "brt" has a potential range of 0..3069. Subtracting it from 1000 doesn't strike me as sensible.

Serial.print("Sensor reading;");Serial.println(brt);

(brt)---what I am refering to as 'brightness', but basically the pmw.. (right?)

I'm a newbie, please forgive me.

An analoguRead can't return a negative number, so I don't see where the -5 is coming from. Post your code, showing where you print the input value of "brt" and the output values of "redval" etc. When posting code, please use the # icon on the editor's toolbar to give a proper code box.

blueval=((1000-brt)/4); //

I did this because I wanted a value of 250 when the pressure was low (say 0)--which is the lowest pressure.

#define REDLED 11  //
#define GREENLED 12  //
#define BLUELED 13  //
#define POT1 A0

int i = 0;  // We'll use this to count up and down
int brt = 0;  //pot value
int redval= 0;
int blueval = 0;
int greenval = 0;

void setup() 
{
  pinMode(REDLED, OUTPUT);   //tell Arduino LED is an output
  pinMode(GREENLED, OUTPUT);  //tell Arduino LED is an output
  pinMode(BLUELED, OUTPUT); //tell Arudino LED is an output
  pinMode(POT1, INPUT);      //tell Arduino LED is an output
  Serial.begin(9600);
  


}

void loop(){
  brt = analogRead(POT1);
  
  Serial.print("Sensor reading");Serial.println(blueval);

  //blue def
  blueval=((1000-brt)/4); //
  
  //green def
  if((brt>=0)||(brt<500)){ //
    greenval=.5*brt; //
  }
  else{
    greenval=250-((brt-500)/2); // 
  }
 
  
  //red def
  redval=.25*brt; //
 
 
  
  analogWrite(BLUELED, blueval);
  analogWrite(GREENLED, greenval);
  analogWrite(REDLED, redval);
  delay(10);
  
}
 pinMode(POT1, INPUT);      //tell Arduino LED is an output

It isn’t a LED, and it is an analogue input, so it doesn’t need a pinMode.

I still can’t see where you’re printing the output values.

void setup() 
{
  pinMode(REDLED, OUTPUT);   //tell Arduino LED is an output
  pinMode(GREENLED, OUTPUT);  //tell Arduino LED is an output
  pinMode(BLUELED, OUTPUT); //tell Arudino LED is an output
  //pinMode(POT1, INPUT);      //tell Arduino LED is an output
  Serial.begin(9600);
  Serial.print(brt);Serial.println(blueval);
  


}

I must not be doing the serial print correctly.

Well doing it in "setup" isn't going to help - you haven't given values to the variables you're printing - you need to do the prints in "loop".