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.

  • 126 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.

Schematics

Schematic 1
Fufstkvirxtdx81 large pwvceg1xbe

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);    
  }
}

Comments

Similar projects you might like

Arduino - Have Fun with Color Sensor

Project tutorial by khanhhs

  • 348 views
  • 0 comments
  • 9 respects

Arduino - Web-Based Thermometer

Project tutorial by khanhhs

  • 554 views
  • 0 comments
  • 11 respects

Using Python and Arduino MKR1000 for Secure IoT

Project tutorial by Luigi Francesco Cerfeda

  • 1,283 views
  • 0 comments
  • 8 respects

Retro Nokia Snake Game with Arduino

Project tutorial by circuito.io team

  • 3,119 views
  • 2 comments
  • 23 respects

Play Music With Your Remote

Project tutorial by Simone Adobs

  • 603 views
  • 10 comments
  • 6 respects

Arduino Memory Game

Project showcase by MakerRobotics

  • 653 views
  • 0 comments
  • 15 respects
Add projectSign up / Login