⇧
vadnica-logo
Editor My Blog Password Manager Finance My Services About the Project Telegram O meni O meni

RGB Color Picker with Arduino Nano and Three Potentiometers

Wiring the Components

In this project, we use a classic Arduino Nano to read analog values from three potentiometers. Each potentiometer represents one color component: Red (R), Green (G), and Blue (B). The result of the mixing is displayed in real-time on a 2.0" TFT LCD screen.

Connections (Nano → TFT & Potentiometers):

TFT LCD Display (SPI):

Potentiometers (Center pin):

Arduino Code

To function, you need the Adafruit GFX and Adafruit ILI9341 libraries. The code reads analog inputs and converts them into the color format for the display.

// Project: Arduino Nano RGB Color Picker with TFT Display (ST7789)
// Author: Borut Bukovnik - vadnica.org

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>

#define TFT_CS 10
#define TFT_DC 8
#define TFT_RST 9

// Initialization for the ST7789 driver
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

const int pinR = A0;
const int pinG = A1; 
const int pinB = A2;

void setup() {
    // Initialization of the ST7789 display (width: 240, height: 320)
    tft.init(240, 320);
    tft.setRotation(2); 
    tft.fillScreen(ST77XX_BLACK);
    tft.invertDisplay(true);
    
    tft.setCursor(50, 10);
    tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK);
    tft.setTextSize(2);
    tft.print("COLOR PICKER");
}

void loop() {
    int valR = analogRead(pinR);
    int valG = analogRead(pinG);
    int valB = analogRead(pinB);
    
    uint8_t r = map(valR, 0, 1023, 0, 255);
    uint8_t g = map(valG, 0, 1023, 0, 255);
    uint8_t b = map(valB, 0, 1023, 0, 255);
    
    uint16_t color = tft.color565(r, g, b);
    
    // Square with color preview
    tft.fillRect(60, 40, 120, 120, color);
    
    char buffer[40];
    sprintf(buffer, "R:%3d G:%3d B:%3d", r, g, b);
    
    tft.setCursor(20, 180);
    tft.setTextColor(ST77XX_WHITE, ST77XX_BLACK); 
    tft.setTextSize(2);
    tft.print(buffer);
    
    sprintf(buffer, "HEX: 0x%04X ", color);
    tft.setCursor(65, 210);
    tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);
    tft.print(buffer);
    
    delay(50);
}

Required Material

  1. Arduino Nano R3: Compact microcontroller.
  2. TFT LCD SPI 2.0": Color display with 240x320 resolution.
  3. 3x 10k Potentiometer: For controlling color channels.
  4. Protoboard: For quick wiring without soldering.