Project tutorial

Controlling an RGB LED with Color Detector Camera © CERN-OHL

This tutorial shows how to control an RGB LED using an Arduino board and 1Sheeld.

  • 1,994 views
  • 0 comments
  • 1 respect

Components and supplies

Apps and online services

About this project

The key feature here is that the color is selected by detecting the color with your Android phone camera, processing its RGB value and it is sent to the Arduino which then outputs that same value.

Feel free to ask any questions in the comments, and I'll answer them as best I can.

Video below shows the final result:

Step 1: What You Need

Hardware:

  • Arduino Uno or Mega
  • 1 x RGB LED
  • 4 x Connection wires
  • 1 x Breadboard
  • 3 x 220 Ohms resistors

Software:

  • Arduino IDE, which you can download here
  • Get the 1Sheeld Arduino library and the phone app here

PS: Make sure to go through the 1Sheeld intro tutorial here and how to use 1Sheeld with different Arduino boards here. I will be using Arduino Mega for the rest of the tutorial.

Step 2: Wiring and Setup

Mount the 1Sheeld on the Arduino board. Make sure the power switch shown above is turned to 5V (for Arduino UNO users). If you're using another Arduino board, check here. Connect the 220 ohms resistors (x3) as shown. Connect the long leg of the RGB to the GND then connect the red leg to pin 9, green leg to pin 10 and blue leg to pin 11.

Step 3: Software

Simply, the code reads the values of your phone's camera then sends them to the RGB. Upload the attached code and let's move to the next step.

Use your 1Sheeld mobile app (Color Detector Shield) to scan any color you want.

PS: Make sure the 1Sheeld is in upload mode as seen in the image above.

Step 4: Putting It All Together

After connecting all components as shown:

  • Connect the Arduino to your laptop and make sure the code is uploaded.
  • Switch the 1Sheeld back to operating mode.
  • Open your 1Sheeld app and connect your phone to your 1Sheeld board (check 1Sheeld tutorial here if you haven't already).
  • Select Color Detector Shield, and press on the multiple shields icon at the top right of the app.

Now hold your phone, then scan the color of any object and watch your RGB.

Finally, feel free to ask any questions in the comments and I'll answer them as best I can.

Code

FB82K1ZIRXTDY8W.inoArduino
/*

Color Detector Shield Example

This example shows an application on 1Sheeld's color detector shield.

By using this example, you can control the color of a RGB LED according
to the color read by our color detector shield.

OPTIONAL:
To reduce the library compiled size and limit its memory usage, you
can specify which shields you want to include in your sketch by
defining CUSTOM_SETTINGS and the shields respective INCLUDE_ define. 

*/

#define CUSTOM_SETTINGS
#define INCLUDE_COLOR_DETECTOR_SHIELD

/* Include 1Sheeld library. */
#include <OneSheeld.h>

/* Reserve PWM pins for the RGB LED. */  
int redPin = 11;
int greenPin =10;
int bluePin = 9;

void setup() {
  /* Start communication. */
  OneSheeld.begin();
  /* Set the RGB LED pins as output. */
  pinMode(redPin, OUTPUT); 
  pinMode(greenPin, OUTPUT); 
  pinMode(bluePin, OUTPUT);
  /* Set the color detection palette to get only 8 different colors instead of the default 16 million. */
  ColorDetector.setPalette(_3_BIT_RGB_PALETTE);
}

void loop() {
  /* Check if there's a new color received. */
  if(ColorDetector.isNewColorReceived())
  {
    /* Read the last received color and save it locally. */
    Color readColor = ColorDetector.getLastColor();

    /* Get red, blue and green components values. */
    byte redValue = readColor.getRed();
    byte greenValue = readColor.getGreen();
    byte blueValue = readColor.getBlue();
    
    /* Output the values on the RGB LED pins. */
    digitalWrite(redPin,redValue);
    digitalWrite(greenPin,greenValue);
    digitalWrite(bluePin,blueValue);    
  }
}

Schematics

Schematic 1
Fufstkvirxtdx81 large pwvceg1xbe

Comments

Similar projects you might like

Control a RGB Led using Arduino and a smartphone's camera

Project tutorial by Mr robot Maker

  • 2,288 views
  • 0 comments
  • 8 respects

LED Color Sequencer

Project tutorial by Team thefantasticode.Group

  • 4,057 views
  • 10 comments
  • 15 respects

Arduino RGB Color Mixer

Project tutorial by FIELDING

  • 3,214 views
  • 1 comment
  • 11 respects

Multicolor Knight Rider with RGB PL9823 LED + Arduino UNO

Project tutorial by Giovanni Gentile

  • 3,925 views
  • 0 comments
  • 10 respects

Color Detector for Blind People

Project tutorial by Ahmed Elsagaan

  • 2,016 views
  • 0 comments
  • 4 respects
Add projectSign up / Login