Multiple if...else statements in LED dimmer code

Hi there,
I am trying to adapt this LED arduino dimmer code to my project. I am having problems with syntax when I add multiple if… else statements. I am trying to have 3 LEDs respond to different ranges of an analog sensor value 0-255 and only have that particular LED lit during it’s specified value range (but also have the dimming functioning within that range). Am I going about this the right way? Do I need booleans? Cases? It seems like it should be fairly simple, but I keep getting error messages.
Any help would be appreciated thanks,


const int ledPin1 = 9;      // the pin that the LED is attached to
const int ledPin2 = 10;
const int ledPin3 = 11;

void setup()
  // initialize the serial communication:
  // initialize the ledPin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);

void loop() {
  byte brightness;

  // check if data has been sent from the computer:
  if (Serial.available()) 
    // read the most recent byte (which will be from 0 to 255):
    brightness =;
    // set the brightness of the LED:
    if (brightness >= 0 && brightness <=85);{
    analogWrite(ledPin1, brightness);}
  else {analogWrite (ledPin1, 0);}

if (brightness >= 85 && brightness <= 177);{
    analogWrite(ledPin2, brightness);
else {analogWrite (ledPin2, 0);}
   if(brightness >= 177 && brightness <=255);{
    analogWrite(ledPin3, brightness);
    }else {analogWrite (ledPin3, 0);}

You have an extra semicolon in these lines

if (brightness >= 0 && brightness <=85);{

Before copying the code you can do a CTRL-T in the IDE to beautify your code, looks better :)

(yes this only works if the pairs {} match

Posting code that builds, would help us, help help you.


Thanks @Crossroads that fixed it! :)

Glad to help - sometimes it's pretty obvious 8)