IR robot, avoidance mode issues (Solved)

I’m making a IR controlled bot, and are trying to by pressing the remote to make it go in auto /avoidance mode driving by itself, untill i again press a button and take control of it again, the IR part works like its supposed to, but i cant get the second loop to start, when i press the assigned button the serial registers the press with correct code but the “automode” is not starting, any advice is appreciated, my code is on codebender if any want to take a look :slight_smile:

https://codebender.cc/sketch:182249

I take it you see the number from the remote but you never see the words “Rumba mode active” in the serial terminal?

I don’t think your code is doing what you think it is. What you think is a second “loop” function is likely a function prototype. Hopefully someone will clarify this. I’m surprised the code compiles.

You should name the other loop something different. Call it “loop2” or something. You’ll also need to add a loop inside of the function. Only the function “loop” will loop on its own.

You can use “while (1)” to indefinitely loop but you probably want a way to break out of the loop. To break out of the loop you’ll need to check for input. You could use “while (state == 1)” with the ability to change the value of “state” from within the loop.

I only see the remote code as you say, not the rumba txt in serial terminal. im still new on arduino coding and the expressions :frowning: so im not sure how to do the function or make a loop inside it.
at the start of trying to add the Value8 icalled it Myloop but that messed up compiling the code.

My version of Arduino doesn’t like the some of the code so it can’t compile your code.

Here’s a version which uses functions.

Hopefully you’ll be able to see what I mean by using a loop within a function with this code.

// 26oct IR bot driven by 2 servo 9g from ebay, modded for 360 rotation, controlled by Samsung TV remote, Tamiya tank Chassis, and DCduino china counterfeit arduino uno R3.
// 27oct added change: regulair driving speed and turning speed lowered to minimise noise, added speed boost forward and reverse to volume up/down on the remote, and changed the
// uno R3 to Arduino Nano w/ ATmega 328.
// 28oct, Changed servos to better quality ones, and rebuild the whole frame around those, LIPO 7,4v 2000Mah battery as frame, Nano in dev board on top, and added headlights (LED1).
// Also made small video of the bot, and uploaded it on youtube, for visual. https://www.youtube.com/watch?v=kJf-oEHWmLE
//05nov, added police strotoscope lights on pin 2,3,4,5. 4 LEDs, sadly the delay on the leds also delayed the IR reciever, so it had delay and was impossible to control the bot
//so i added delay to line 32 at 6ms.


#include <Servo.h>
#include <IRremote.h>

#define TIME_TO_CM 582
#define TIME_SCALE 10
unsigned long Value1 = 3772778233; // FREM
//unsigned long Value2 = 3772782313; // STOP
unsigned long Value3 = 3772810873; // TILBAGE
unsigned long Value4 = 3772819033; // VENSTRE
unsigned long Value5 = 3772794553; // HoJRE
unsigned long Value6 = 3772833823; // HASTIGHED OP
unsigned long Value7 = 3772829743; // HASTIGHED NED
//unsigned long Value8 = 3772793023; // PowerButton kald RUMBA mode

const unsigned long STOP_BUTTON = 3772782313; // STOP
const unsigned long AUTONOMOUS_BUTTON = 3772793023; // PowerButton kald RUMBA mode

int RECV_PIN = 11; // IR signal pin
IRrecv irrecv(RECV_PIN);
decode_results results;

// Servo motorer i setup:
Servo Hmotor;
Servo Vmotor;
// LEDS
const int LED1 = 12; // forlys You don't need an int but it doesn't hurt since it's a constant.
const int LED2 = 8; // Baglys
//politilys:
const int ledDelay = 100; // delay by 100ms
const int redPin = 4;
const int bluePin = 2;
const int rredPin = 5;
const int bbluePin = 3;
//Ultrasonic sensor:
const int trigPin = 6; // <--------TRIG sensor
const int echoPin = 7; // <--------ECHO sensor
int cm; // I don't think you need a long here

void setup() {

  Serial.begin(9600); // I suggest changing to 115200 so serial output is faster.
  irrecv.enableIRIn(); // Start IR Modtager

  // Saet Digital pins som output.
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);

  //politilys
  pinMode(redPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(rredPin, OUTPUT);
  pinMode(bbluePin, OUTPUT);

  //Ultrasonic Sensor:
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  //servomotors
  Hmotor.attach(10); // attatch servo1 to digital pin 10
  Vmotor.attach(9); // attatch servo2 to digital pin 9

  Hmotor.write(90); // set Hmotor til still start
  Vmotor.write(90); // set Vmotor til still start
}


void loop() {

  if (irrecv.decode(&results)) {
    Serial.println(results.value, DEC); // print resultat fra TV Remote i serial vinduet
    irrecv.resume();
  }

  //politilys
  flashTwoLeds(redPin, rredPin, ledDelay, ledDelay, 3);

  delay(50); // delay midpoint by 50ms

  flashTwoLeds(bluePin, bbluePin, ledDelay, ledDelay, 3);

  if (results.value == Value1) {
    setMotors(-20, 0); // FREM
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, LOW);
  }

  else if (results.value == STOP_BUTTON) {
    Hmotor.write(90);  // STOP
    Vmotor.write(90);
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);

  }

  else if (results.value == Value3) {
    setMotors(20, 0); // TILBAGE
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);

  }

  else if (results.value == Value4) {
    setMotors(0, -20); // VENSTRE
    Vmotor.write(110);
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);

  }

  else if (results.value == Value5) {
    setMotors(0, 20); // HoJRE
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);

  }

  else if (results.value == Value6) {
    setMotors(-67, -22);// FREM SPEED UP
    //Hmotor.write(45); // setMotors isn't exactly the same
    //Vmotor.write(180);
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, LOW);

  }

  else if (results.value == Value7) {
    setMotors(67, -22); // TILBAGE SPEED UP Did I convert to speed and turn correctly?
    //Hmotor.write(180);
    //Vmotor.write(45);
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);
  }

  else if (results.value == AUTONOMOUS_BUTTON) {
    autonomousDrive();
  }
}
void autonomousDrive()
{
  Serial.print ("Rumba mode active" );
  //Rumba mode
  //sets both servos to full speed in the same direction

  do
  {
    Hmotor.write(70);
    Vmotor.write(110);

    cm = readUltrasound(trigPin, echoPin);

    //delay(250); // why?

    //Sets object detection distance
    if (cm < 20)
    {
      Serial.println ("Close Obstacle detected!" );
      Serial.print ("distance = " );
      Serial.print (cm);
      Serial.println (" cm" );
      //stops both servos
      setMotors(0, 0);
      delay(1000);
      //sets both servos to full speed in opposite direction
      setMotors(20, 0);
      delay(1000);
      //the robot turns
      setMotors(0, 20);
      delay(1000);
    }

    if (irrecv.decode(&results))  // refresh IR result
    {
      Serial.println(results.value, DEC); // print resultat fra TV Remote i serial vinduet
      irrecv.resume();
    }
  } while (results.value != STOP_BUTTON); // continue in autonomous mode unless stop button is pressed
  setMotors(0, 0); // stop prior to exiting
}


void flashTwoLeds(byte pin0, byte pin1, byte timeOn, byte timeOff, byte flashes)
{
  for (byte i; i < flashes; i++)
  {
    digitalWrite(pin0, HIGH);
    digitalWrite(pin1, HIGH);
    delay(timeOn);
    digitalWrite(pin0, LOW);
    digitalWrite(pin1, LOW);
    delay(timeOff);

  }
}
int readUltrasound(byte tPin, byte ePin)
{
  digitalWrite(tPin, LOW);
  delayMicroseconds(2);
  digitalWrite(tPin, HIGH);
  delayMicroseconds(4);
  digitalWrite(tPin, LOW);

  pinMode(echoPin, INPUT);  // I don't think this is needed since it as set in setup.

  long duration = pulseIn(echoPin, HIGH);

  // converts the time to a distance
  duration = duration * TIME_SCALE / TIME_TO_CM; // Keep the math integer math. It's faster.

  return (duration);
}
void setMotors(int motorSpeed, int motorTurn) // positive turn to go right negative to go left
{
  Hmotor.write(90 + motorSpeed - motorTurn);
  Vmotor.write(90 - motorSpeed - motorTurn);
}

I moved the motor control to its own function. Instead of setting the values of each servo, you set the motor speed and a turn speed. You can of course change things back to the way you had it but personally like controlling CR servos with a speed and turn parameter.

Hopefully there aren’t too many errors and you can get it to compile.

I called the second loop “autonomousDrive”. This function should stay active until it receives a stop command from the remote.

This line checks to see if the loop should end.

while (results.value != STOP_BUTTON); // continue in autonomous mode unless stop button is pressed

I changed the name of two of the buttons.

Instead of “Value2” I used “STOP_BUTTON” and instead of “Value8” I used “AUTONOMOUS_BUTTON”.

I added the “const” to “variables” which won’t change. This saves a bit of memory and the compiler will warn you if you try to change its value (or so I assume).

Hopefully this is enough to get you going again.

Gotta love that use of "loop();"
And surprisingly, in V1.6.5 that code compiled fine.

On my car, I used the main loop for "Auto" mode, and then used a second function, 'manualMode()', for manual mode, duh, with a 'while(true)' loop inside it. Both operating modes check the IR remote for input, then if in "Auto" mode and a "Manual" command arrives, the program calls "manualMode()".
If in "Manual" mode and an "Auto" command arrives, the program 'returns' from the 'manualMode()' function.
All other commands like "forward", "turnLeft", "turnRight", "Reverse" etc are in separate functions.
I also used a separate function for handling the IR commands, 'translateCmd()'.
And I set up all unused IR remote buttons as "Stop", rather than leave them unused.
I hope I've explained it well enough to understand.

OldSteve:
Gotta love that use of "loop();"
And surprisingly, in V1.6.5 that code compiled fine.

I figure "loop():" was treated as a function prototype but I think it's strange the compiler didn't mind where they were located.

I'm really surprised the compiler didn't complain about the extra code at the end.

I think my computer must be glitching. I thought I had compiled it but when I tried later it complained about one of the library files.

Did the code I posted compile?

I'll restart my computer and see it clears things up. (I have new PC in a box I purchased yesterday. I hate setting up new computers.)

DuaneDegn:
Did the code I posted compile?

Yep. :slight_smile:

OldSteve:
Yep. :slight_smile:

Thanks for checking (and for catching my mistake (now edited and lost to history)).

I don't have a IR receiver handy. I hope the OP will let us know if it works as expected. I'm sure he will what to fine tune some of the times and speeds, but hopefully the overall structure works as expected.

@rero9900, You might want to take a look at the "newPing" library. I haven't used it myself yet but I believe it will monitor the ultrasound sensor "behind the scenes". At least that's my present understanding of it. The guy who wrote strikes me as someone who knows what he's doing.

Speaking of ultrasound code, I change the calculation in your code to use only integers. Integer math is much faster than floating point math. Whenever it's possible (and practical) you're better of using integers instead of floating point values. You didn't have any floating point variables but I believe some of your calculations caused the some switching back and forth between floating point numbers and integer numbers. I'm not sure how all that works but I think it's safe to say using integers when possible is a good idea.

DuaneDegn:
@rero9900, You might want to take a look at the "newPing" library. I haven't used it myself yet but I believe it will monitor the ultrasound sensor "behind the scenes". At least that's my present understanding of it. The guy who wrote strikes me as someone who knows what he's doing.

There's a small problem with this. 'NewPing' does have a 'ping_timer' method, which uses a timer and works behind-the-scenes, but it conflicts with the 'IRremote' library and it's timer usage.
I disabled the timer method of 'NewPing' in the *.h file, (the comments make it clear how to do this), and just use the standard 'NewPing' functions in my code. The interruption isn't really a problem right now.

I discussed this briefly with Tim, (teckel), in the 'NewPing' thread the other day and he did mention there are other ways around the conflict as well, without disabling the 'ping_timer' method, but I haven't gone more deeply into that yet. (Been busy with other aspects of my code.)

If rero9900 is interested in 'NewPing', and does want to use the 'ping_timer' method, it's worth posting in the 'NewPing' thread in the "Sensors" section and asking Tim for details. (And I'll keep an eye on it too, because I was planning to ask him myself sometime soon.)

OldSteve:
If rero9900 is interested in 'NewPing', and does want to use the 'ping_timer' method, it's worth posting in the 'NewPing' thread in the "Sensors" section and asking Tim for details. (And I'll keep an eye on it too, because I was planning to ask him myself sometime soon.)

Tim certainly seems willing to help people (he strikes me as a really nice guy) but I think the ultrasound code currently used in the program should work well.

DuaneDegn:
Tim certainly seems willing to help people (he strikes me as a really nice guy) but I think the ultrasound code currently used in the program should work well.

I agree. It's only if it gets in the way that the 'ping_timer' method from the library would be needed. Mind you, NewPing's 'ping_median' method is pretty handy if there's any false-triggering with the basic method. Takes a series of range measurements and averages them. Still, that's not hard to do manually either. Good for lazy types like me though. :slight_smile:

wow thanks a lot, code looks much cleaner this way, and it compiles fine :slight_smile:
all the IR works like a charm, i'll have to look into my wiring now, i think there may be some fault since the flashing lights dont flash, anymore.
Checked the old code and uploaded it again and the lights do flash without problems, i cannot figure out where in the new flash part to look for the solution.

i swapped the trigger and echo in code so the sensor match the wiring there :smiley: and rumba runs fine.
the speed that you //questioned in the code matched fine, i still need to figure out the servo speeds, as i thought 180 was max forward and 45 max reverse :frowning:

can i add more buttons to "while (results.value != STOP_BUTTON);" some how? seperated by commas perhaps? it could be nice to break the loop by pressing any key to manual control it again

rero9900:
i still need to figure out the servo speeds, as i thought 180 was max forward and 45 max reverse :frowning:

180 is max speed in one direction, and 0 is max speed in the other direction.
I wrote a small library for my robot car, "CarServo", which has commands like "move(direction,left speed,right speed)". Then I wrote defines for a few speed presets.
If I use a command like "move(FWD, SLOW,SLOW)", my library function automatically runs one motor in one direction and the other in the other direction. Speeds are 0 to 90, and the lib function adds that value to 90 for one wheel and subtracts it from 90 for the other wheel, making operation much more comprehensive.

can i add more buttons to "while (results.value != STOP_BUTTON);" some how? seperated by commas perhaps? it could be nice to break the loop by pressing any key to manual control it again

To do this, you can add a line to go into manual mode in this if statement:-

if (irrecv.decode(&results))  // refresh IR result
{
    Serial.println(results.value, DEC); // print resultat fra TV Remote i serial vinduet
    irrecv.resume();
}

In my robot car code, I do it like this. (There's a bit more going on than in your car, but you'll get the idea.):-

   if(irrecv.decode(&result))                      // If an IR code is received, decode it to a 32-bit value.
    {
        irData=(unsigned int)result.value&0xFFFFU;  // Isolate the low word, (actual data).
        if(irData==0x00FF)                          // MANUAL/AUTO mode pressed - switch to 'MANUAL' mode
            currentMode=MANUAL_MODE;                // Flag 'MANUAL' mode.
        irrecv.resume();                            // Receive the next value.
    }

    if(currentMode==MANUAL_MODE)
    {
        cs.stop();                                  // Stop the car.
        digitalWrite(ledPin,0);                     // Turn the flashing red/blue LED off.
        if(!headServo.attached())                   // If the ultrasonic head servo isn't attached,
            headServo.attach(headServoPin);         // attach it now.
        headServo.write(centreScanPos);             // Centre the head.
        delay(300);                                 // Delay for head centring.
        headServo.detach();                         // Stop driving the head servo.
        manualMode();                               // Switch to 'MANUAL' mode.
    }

I only used a simple blocking 'delay' here during head centring, because when I switch to manual mode I want the car to stop until I press FWD, REV, LEFT or RIGHT on the remote control, so the delay doesn't affect operation. Everywhere important I use millis-based delays.

Ah ok Cool :slight_smile: think i get it now :stuck_out_tongue:

i tried to move them flashing lights so they only flash when in rumba mode, but they are totally dead, i have tried to understand the shorting of the flashing part, to fix the problem but with no luck sadly :frowning:

i uploaded the code to the arduino as it is here: will-y IR+Rumbamode refined code by rero9900

rero9900:
i tried to move them flashing lights so they only flash when in rumba mode, but they are totally dead, i have tried to understand the shorting of the flashing part, to fix the problem but with no luck sadly :frowning:

I think you'll find that the LEDS are flashing. Try increasing ledDelay to a more reasonable length, like 500, to test this. At the moment, you're getting 3 LED flashes 100mS long, so they're very short and finished very quickly.

i uploaded the code to the arduino as it is here: will-y IR+Rumbamode refined code by rero9900

It would be much easier for us if you posted the code here, between code tags as we've been doing, rather than on another site.

Ok i set it to 800ms to test, but there is still no lights, i pasted the code to this topic as you recommended :slight_smile:
i moved the

flashTwoLeds(redPin, rredPin, ledDelay, ledDelay, 3);

  delay(50); // delay midpoint by 50ms

  flashTwoLeds(bluePin, bbluePin, ledDelay, ledDelay, 3);

to the Rumba part, so it only flash when in rumba mode :slight_smile:

#include <Servo.h>
#include <IRremote.h>

#define TIME_TO_CM 582
#define TIME_SCALE 10
unsigned long Value1 = 3772778233; // FREM
//unsigned long Value2 = 3772782313; // STOP
unsigned long Value3 = 3772810873; // TILBAGE
unsigned long Value4 = 3772819033; // VENSTRE
unsigned long Value5 = 3772794553; // HoJRE
unsigned long Value6 = 3772833823; // HASTIGHED OP
unsigned long Value7 = 3772829743; // HASTIGHED NED
//unsigned long Value8 = 3772793023; // PowerButton kald RUMBA mode

const unsigned long STOP_BUTTON = 3772782313; // STOP
const unsigned long AUTONOMOUS_BUTTON = 3772793023; // PowerButton kald RUMBA mode

int RECV_PIN = 11; // IR signal pin
IRrecv irrecv(RECV_PIN);
decode_results results;

// Servo motorer i setup:
Servo Hmotor;
Servo Vmotor;
// LEDS
const int LED1 = 12; // forlys You don't need an int but it doesn't hurt since it's a constant.
const int LED2 = 8; // Baglys
//politilys:
const int ledDelay = 800; // delay by 100ms
const int redPin = 4;
const int bluePin = 2;
const int rredPin = 5;
const int bbluePin = 3;
//Ultrasonic sensor:
const int trigPin = 7; // <--------TRIG sensor
const int echoPin = 6; // <--------ECHO sensor
int cm; // I don't think you need a long here

void setup() {

  Serial.begin(115200); // I suggest changing to 115200 so serial output is faster.
  irrecv.enableIRIn(); // Start IR Modtager

  // Saet Digital pins som output.
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);

  //politilys
  pinMode(redPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(rredPin, OUTPUT);
  pinMode(bbluePin, OUTPUT);

  //Ultrasonic Sensor:
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  //servomotors
  Hmotor.attach(10); // attatch servo1 to digital pin 10
  Vmotor.attach(9); // attatch servo2 to digital pin 9

  Hmotor.write(90); // set Hmotor til still start
  Vmotor.write(90); // set Vmotor til still start
}


void loop() {

  if (irrecv.decode(&results)) {
    Serial.println(results.value, DEC); // print resultat fra TV Remote i serial vinduet
    irrecv.resume();
  }


  if (results.value == Value1) {
    setMotors(-20, 0); // FREM
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, LOW);
    //Serial.print ("Frem" );
  }

  else if (results.value == STOP_BUTTON) {
    Hmotor.write(90);  // STOP
    Vmotor.write(90);
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);
    //Serial.print ("Stop" );

  }

  else if (results.value == Value3) {
    setMotors(20, 0); // TILBAGE
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);
    //Serial.print ("Tilbage" );

  }

  else if (results.value == Value4) {
    setMotors(0, -20); // VENSTRE
    Vmotor.write(110);
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);
   // Serial.print ("Venstre" );

  }

  else if (results.value == Value5) {
    setMotors(0, 20); // HoJRE
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);
   // Serial.print ("Højre" );

  }

  else if (results.value == Value6) {
    setMotors(-67, -22);// FREM SPEED UP
    //Hmotor.write(45); // setMotors isn't exactly the same
    //Vmotor.write(180);
    digitalWrite(LED1, HIGH);
    digitalWrite(LED2, LOW);
    //Serial.print ("Frem Fuld Fart" );

  }

  else if (results.value == Value7) {
    setMotors(67, -22); // TILBAGE SPEED UP Did I convert to speed and turn correctly?
    //Hmotor.write(180);
    //Vmotor.write(45);
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);
    //Serial.print ("Tilbage Fuld Fart" );
  }

  else if (results.value == AUTONOMOUS_BUTTON) {
    autonomousDrive();
  }
}
void autonomousDrive()
{
  Serial.print ("Rumba mode active" );
      digitalWrite(LED1, LOW);
    digitalWrite(LED2, LOW);
  //Rumba mode
  //sets both servos to full speed in the same direction
  //politilys
  flashTwoLeds(redPin, rredPin, ledDelay, ledDelay, 3);

  delay(50); // delay midpoint by 50ms

  flashTwoLeds(bluePin, bbluePin, ledDelay, ledDelay, 3);
  
  do
  {
    Hmotor.write(45);
    Vmotor.write(180);

    cm = readUltrasound(trigPin, echoPin);

    delay(250); // why?

    //Sets object detection distance
    if (cm < 10)
    {
      Serial.println ("Close Obstacle detected!" );
      Serial.print ("distance = " );
      Serial.print (cm);
      Serial.println (" cm" );
      //stops both servos
      setMotors(0, 0);
      delay(1000);
      //sets both servos to full speed in opposite direction
      setMotors(67, -22);
      delay(1000);
      //the robot turns
      setMotors(0, 50);
      delay(1000);
    }

    if (irrecv.decode(&results))  // refresh IR result
    {
      Serial.println(results.value, DEC); // print resultat fra TV Remote i serial vinduet
      irrecv.resume();
    }
  } while (results.value != STOP_BUTTON); // continue in autonomous mode unless stop button is pressed
  setMotors(0, 0); // stop prior to exiting
}


void flashTwoLeds(byte pin0, byte pin1, byte timeOn, byte timeOff, byte flashes)
{
  for (byte i; i < flashes; i++)
  {
    digitalWrite(pin0, HIGH);
    digitalWrite(pin1, HIGH);
    delay(timeOn);
    digitalWrite(pin0, LOW);
    digitalWrite(pin1, LOW);
    delay(timeOff);

  }
}
int readUltrasound(byte tPin, byte ePin)
{
  digitalWrite(tPin, LOW);
  delayMicroseconds(2);
  digitalWrite(tPin, HIGH);
  delayMicroseconds(4);
  digitalWrite(tPin, LOW);

  pinMode(echoPin, INPUT);  // I don't think this is needed since it as set in setup.

  long duration = pulseIn(echoPin, HIGH);

  // converts the time to a distance
  duration = duration * TIME_SCALE / TIME_TO_CM; // Keep the math integer math. It's faster.

  return (duration);
}
void setMotors(int motorSpeed, int motorTurn) // positive turn to go right negative to go left
{
  Hmotor.write(90 + motorSpeed - motorTurn);
  Vmotor.write(90 - motorSpeed - motorTurn);
}

I've changed this reply. I completely misunderstood you. I'll try again:-

Is this being printed in the serial monitor:- "Rumba mode active"

And are the red LEDs connected correctly to pin 4 and pin 5?

:slight_smile: i have 4 leds in the lights, they are connected to same GND and each positive leg i have connected to 2,3,4,5 i dont know if this is the most optimal setup.

const int ledDelay = 800; // delay by 100ms
const int redPin = 4;
const int bluePin = 2;
const int rredPin = 5;
const int bbluePin = 3;

sorry for all the newbie questions, you have been a great help :slight_smile:

Do you also have a current-limiting resistor in series with each LED?

And I ask again. (This is important, so please answer this time.)
When you press the button to go into "Rumba mode", is this being printed in the serial monitor:- "Rumba mode active"?

Edit: Is your robot running OK, and is the only problem the fact that the LEDs are not lighting?

I was reading your answer while in the waiting room at the dentist, and got called in as i was writing the answer, sorry.
the rumba works fine, everything works fine, serial prints rumba active and only leds flashing don't work, but they was driving my girlfriend nuts so i decided to not use them.
anyways thanks for your patience and help, was great.
:slight_smile: