Control NeoPixel RGB LED Color Code Using Keypad and Maker Nano

Control NeoPixel RGB LED color code using keypad and Maker Nano.

Introduction

Every NeoPixel LEDs consists of red, green and blue (RGB) LED. Each color produced, there is a color code behind it. In this tutorial, we will develop a kit using Maker Nano to light up RGB LEDs based on the color code and brightness entered from a keypad.

Video

This video shows how to control NeoPixel RGB LED color code using keypad and Maker Nano.

Hardware Preparation

This is the list of items used in the video.

Sample Program

This is Arduino sample program to control NeoPixel RGB LED color code using keypad. Please install following library through Library Manager.

  • Grove LCD RGB Backlight by Seeed Studio V1.0.0 (Manager)
  • Keypad by Mark Stanley V3.1.1 (Manager)
  • NeoPixelBus by Makuna V2.5.7 (Manager)
/*
Project: Control NeoPixel RGB LED Color Code Using Keypad and Maker Nano #ArduinoNano
Board: Arduino Nano (Maker Nano)
Connections:
Nano | I2C LCD Grove
GND – GND
5V – VCC
SDA – SDA
SCL – SCL
Nano | Keypad
12 – pin 1 (most left)
11 – pin 2
10 – pin 3
9 – pin 4
7 – pin 5
6 – pin 6
5 – pin 7
4 – pin 8
Nano | RGB LED Stick
GND – GND
5V – VCC
3 – SIG
External libraries:
– Grove LCD RGB Backlight by Seeed Studio V1.0.0 (Manager)
– Keypad by Mark Stanley V3.1.1 (Manager)
– NeoPixelBus by Makuna V2.5.7 (Manager)
*/
#include <Wire.h>
#include <rgb_lcd.h>
#include <Keypad.h>
#include <NeoPixelBrightnessBus.h>
rgb_lcd lcd;
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {7, 6, 5, 4};
byte colPins[COLS] = {12, 11, 10, 9};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
const uint16_t PixelCount = 10;
const uint8_t PixelPin = 3;
NeoPixelBrightnessBus<NeoRgbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);
#define BUZZER 8
#define NOTE_G4 392
#define NOTE_B4 494
#define NOTE_D5 587
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.print("[#]Color=000000");
lcd.setCursor(0, 1);
lcd.print("[*]Bright=050 ");
delay(1000);
strip.Begin();
strip.Show();
tone(BUZZER, NOTE_G4, 70);
delay(100);
tone(BUZZER, NOTE_D5, 70);
delay(70);
}
byte count = 0;
byte row = 0;
enum {NONE, COLOR, BRIGHT};
byte data = NONE;
String dataString = "";
char dataArray[6];
byte rgb[3];
int brightness = 50;
int pixel;
void loop()
{
char key = keypad.getKey();
if (key == '#' && data == NONE) {
lcd.setCursor(9, 0);
lcd.print("——");
count = 0;
data = COLOR;
dataString = "";
tone(BUZZER, NOTE_D5, 50);
delay(50);
}
else if (key == '*' && data == NONE) {
lcd.setCursor(10, 1);
lcd.print("");
count = 0;
data = BRIGHT;
dataString = "";
tone(BUZZER, NOTE_B4, 50);
delay(50);
}
else if (key && data == COLOR) {
tone(BUZZER, NOTE_G4, 50);
delay(50);
count++;
lcd.setCursor(9, 0);
if (key == '*') key = 'E';
else if (key == '#') key = 'F';
dataString += key;
lcd.print(dataString);
if (count == 6) {
dataString.toCharArray(dataArray, 7);
unsigned long number = strtoul(dataArray, nullptr, 16);
for (int i = 2; i >= 0; i–) {
rgb[i] = number & 0xFF;
number >>= 8;
}
// for (int i = 0; i < 3; i++) {
// Serial.print(rgb[i]);
// Serial.println();
// }
strip.SetBrightness(brightness);
for (pixel = 0; pixel < PixelCount; pixel++) {
strip.SetPixelColor(pixel, RgbColor(rgb[1],rgb[0],rgb[2]));
}
strip.Show();
data = NONE;
}
}
else if (key && data == BRIGHT) {
if (key >= '0' && key <= '9') {
tone(BUZZER, NOTE_G4, 50);
delay(50);
count++;
lcd.setCursor(10, 1);
dataString += key;
lcd.print(dataString);
}
if (count == 3) {
brightness = dataString.toInt();
if (brightness > 255) {
brightness = 255;
lcd.setCursor(10, 1);
lcd.print(brightness);
}
strip.SetBrightness(brightness);
for (pixel = 0; pixel < PixelCount; pixel++) {
strip.SetPixelColor(pixel, RgbColor(rgb[1],rgb[0],rgb[2]));
}
strip.Show();
data = NONE;
}
}
}

Thank You

References:

Thanks for reading this tutorial. If you have any technical inquiries, please post at Cytron Technical Forum.

Please be reminded, this tutorial is prepared for you to try and learn.
You are encouraged to improve the code for better application.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Send Data to Firebase Using Arduino Uno WiFi Rev2
Simple Alarm System Using Maker Nano
Program Cucumber ESP32-S2 Using CircuitPython
Face Recognition Using OpenCV on Raspberry Pi 400
Turned Your Tablet as a Display for the Raspberry Pi 400
Scroll to Top