Adding Controlled RGB Leds to RAMPS

The RAMPS 1.4 EFB Pin Connections

Place a jumper over VCC and 5V to provide power to the servo + and – pins. Next use the Servo pins D11, D6 and D5 to connect the RGB led to the Servos Header via appropriate resistors to the PWA via the J7  flat ribbon cable as shown below:

*The RGB on the front panel can also be connected to D0, D1 and D11.

In Configuration.h  ( line c2348) change the following lines to read

* LED Type. Enable only one of the following two options.
#define RGB_LED
//#define RGBW_LED

  #define RGB_LED_R_PIN D11
  #define RGB_LED_G_PIN D6
  #define RGB_LED_B_PIN D5
  //#define RGB_LED_W_PIN -1
 * Printer Event LEDs
 * During printing, the LEDs will reflect the printer status:
 *  – Gradually change from blue to violet as the heated bed gets to target temp
 *  – Gradually change from violet to red as the hotend gets to temperature
 *  – Change to white to illuminate work surface
 *  – Change to green once print has finished
 *  – Turn off after the print has finished and the user has pushed a button

Testing the A4988 Stepper Motor Driver

The Arduino Mega 2560 sketch is used to test a single Driver using the code below:

/* Demo of A4988 micro-stepping motor driver
   Arduino Uno
   Arduino IDE 1.8.10

   Uses button debounce library

   Gadget Reboot
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 22, en = 24, d4 = 26, d5 = 28, d6 = 30, d7 = 32;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#include <Bounce2.h>

// stepper control outputs
#define motStepPin     2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           // White
#define motDirPin      3 // Yellow

#define motMS1Pin      4 // Green
#define motMS2Pin      5 // Blue
#define motMS3Pin      6 // Purple

// button inputs
#define buttonDir      7 // Brown
#define buttonRun      8 // Grey
#define buttonMS       9 // Purple

#define motMS1Led      10 // Green
#define motMS2Led      11 // Amber
#define motMS3Led      12 // Red

// speed control pot
#define speedPot       A8 // Purple

// create debounce instances for 3 buttons
Bounce dirIn   = Bounce();  // motor direction toggle
Bounce runIn   = Bounce();  // motor run for 200 steps
Bounce msIn    = Bounce();  // cycle through microstep options

// list of microstep config pin outputs in binary notation B[MS1][MS2][MS3]
byte microSteps[5] = {
  B000,  // full step
  B100,  // 1/2  step
  B010,  // 1/4  step
  B110,  // 1/8  step
  B111,  // 1/16 step

// start with full stepping:  microSteps[0] gives MS1=0 MS2=0 MS3=0
byte msMode = 0;

void setup() {
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Stepper Testing");
  lcd.print("push run button");
  Serial.print("Stepper Testing");
  // assign actual input pins to debounce instances with a certain debounce time
  dirIn.attach(buttonDir, INPUT_PULLUP);
  runIn.attach(buttonRun, INPUT_PULLUP);
  msIn.attach(buttonMS, INPUT_PULLUP);

  // configure initial motor settings
  digitalWrite(motStepPin, LOW);
  digitalWrite(motDirPin, HIGH);
  digitalWrite(motMS1Pin, LOW);
  digitalWrite(motMS2Pin, LOW);
  digitalWrite(motMS3Pin, LOW);

  pinMode(motStepPin, OUTPUT);
  pinMode(motDirPin, OUTPUT);
  pinMode(motMS1Pin, OUTPUT);
  pinMode(motMS2Pin, OUTPUT);
  pinMode(motMS3Pin, OUTPUT);
  pinMode(motMS1Led, OUTPUT);
  pinMode(motMS2Led, OUTPUT);
  pinMode(motMS3Led, OUTPUT);

  for(int x = 3; x < 8; x++) {
    digitalWrite(motMS1Led, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(100);                      // wait for a second
    digitalWrite(motMS1Led, LOW);    // turn the LED off by making the voltage LOW
    delay(100);                      // wait for a second
    digitalWrite(motMS2Led, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(100);                      // wait for a second
    digitalWrite(motMS2Led, LOW);    // turn the LED off by making the voltage LOW
    digitalWrite(motMS3Led, HIGH);   // turn the LED on (HIGH is the voltage level)
    delay(100);                      // wait for a second
    digitalWrite(motMS3Led, LOW);    // turn the LED off by making the voltage LOW
 }void loop() {
  // update button debounce status

  // if any buttons are pressed, perform actions
  // toggle motor direction output pin
  if (dirIn.fell()) {
    digitalWrite(motDirPin, !digitalRead(motDirPin));

  // run motor for 200 steps
  if (runIn.fell()) {
    for (int i = 0; i < 200; i++) {
      // read pot and set a delay to control speed
      int motSpeed = map(analogRead(speedPot), 0, 1023, 5000, 200);
      Serial.println("Feed Rate");
      lcd.print("Step Number  ");
      lcd.print("Feed Rate     ");
      // advance motor one step at the pot delay setting/speed
      digitalWrite(motStepPin, HIGH);
      digitalWrite(motStepPin, LOW);

  // cycle through micro step configuration options
  if (msIn.fell()) {
    // reset all leds
    digitalWrite(10, LOW); // Green
    digitalWrite(11, LOW); // Amber
    digitalWrite(12, LOW); // Red
    if (msMode >= 5) msMode = 0;
    digitalWrite(motMS1Pin, bitRead(microSteps[msMode], 2));
     digitalWrite(motMS1Led, bitRead(microSteps[msMode], 2));
    digitalWrite(motMS2Pin, bitRead(microSteps[msMode], 1));
     digitalWrite(motMS2Led, bitRead(microSteps[msMode], 1));
    digitalWrite(motMS3Pin, bitRead(microSteps[msMode], 0));
     digitalWrite(motMS3Led, bitRead(microSteps[msMode], 0));
The Wiring is show below but does not include the 3 MS Leds