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);
}