Color Picking Plate

From Wiki

Jump to: navigation, search

Kit List

Introduction:
Arduino advanced kit provided by ELECFREAKS is based on our starter kit to expand more and more popular modules owing the characteristics of plug and use without any requirement of soldering. We have well prepared six courses for learners to learn the usage of modules in an intersting environment which is better for stimulating your thinking mind. For example,Tetris games help us to study the usage of the LCD screen and Arduino program. Color picker used can help us to learn the color sensor as well as BLE Bluetooth communication and Android interface development ... Practical Course included LCD screen, sensor, MP3, BLE, WIFI, Android development, and image interaction (processing), make you open-minded!

Part4 Color Picking Plate

Product introduction:
AD-part-4.gif This is an interesting project, you can paint the color you see to the phone via Bluetooth.
Color 1.png Color 2.png
Materials:
an Uno board, a color sensor, a mobile phone with Android 4.3 or above prepared by yourself, we now only developed APK for android phone
*1xFreaduino Uno;
*1xColor Sensor;
*1xBle;

Parameter and IO definition:
1.3.3V power supply to mainboard
2.Color Sensor access to board. #define S0 D6 // Please notice the Pin's define,D(digital pin) #define S1 D5 #define S2 D4 #define S3 D3 #define OUT D2 #define VCC V(power supply) #define GND G(ground) #define OE G(ground)
Notes
A.Color Sensor power supply can not be higher than 4V, so please adjust arduino board power supply to 3.3V
Uno 1.jpg B.Color sensor needs white balance correction for normal use.
C.Uno board can not program procedures when connect to a Bluetooth module, because serial port is occupied. When programming process, you need to disconnect the Bluetooth module
 Working principles:
1.After connection and at the beginning of powered Uno board, it will do white balance correction to color sensor. That is it will identify the first color it detected as white, ie RGB values are 255,255,255. So when you perform white balance correction, just try to capture an value very access to white, and distance is better to be within 10 cm. If you are not satisfied with the corrected color, you can also control it to do white balance correction again by phone
2.Apk introduction(need apk and Source code,please downloadpart4.zip):
A.Only support Android 4.3 or above, being restricted by Bluetooth 4.0 communications protocol, otherwise it can not open the program
B.Its interface is very simple, just with simple buttons, so you can operate easily.
C.If you are not satisfied with the color you got, try to test in a good lighting environmentor click "Balance" to do white balance correction again. If you want to improve it, we offer you Apk source code, so that you can develop it once again.
Color table:
ColorSensor1.png
ColorSensor2.png
ColorSensor3.gif
ColorSensor3-2.gif

Arduino code

part4.zip


 /*
  PART4 Communicate with Android phone via Bluetooth 4.0 and color sensors
  1. You need a Uno, a color sensor, a BLE and one support, Bluetooth 4.0 android phone
  2. When you put these are connected, you also need to install a specific apk to communicate with it
 */
#include <TimerOne.h>
void TSC_WB(int Level0, int Level1);
#define S0     6   // Please notice the Pin's define
#define S1     5
#define S2     4
#define S3     3
#define OUT    2

int   g_count = 0;    // count the frequecy
int   g_array[3];     // store the RGB value
int   g_flag = 0;     // filter of RGB queue
float g_SF[3];        // save the RGB Scale factor
 
 
// Init TSC230 and setting Frequency.
void TSC_Init()
{
  pinMode(S0, OUTPUT);
  pinMode(S1, OUTPUT);
  pinMode(S2, OUTPUT);
  pinMode(S3, OUTPUT);
  pinMode(OUT, INPUT);
 
  digitalWrite(S0, LOW);  // OUTPUT FREQUENCY SCALING 2%
  digitalWrite(S1, HIGH);
}
 
// Select the filter color
void TSC_FilterColor(int Level01, int Level02)
{
  if(Level01 != 0)
    Level01 = HIGH;
 
  if(Level02 != 0)
    Level02 = HIGH;
 
  digitalWrite(S2, Level01);
  digitalWrite(S3, Level02);
}
 
void TSC_Count()
{
  g_count ++ ;
}
 
void TSC_Callback()
{
  switch(g_flag)
  {
    case 0:
         Serial.println("->WB Start");
         TSC_WB(LOW, LOW);              //Filter without Red
         break;
    case 1:
         Serial.print("->Frequency R=");
         Serial.println(g_count);
         g_array[0] = g_count;
         TSC_WB(HIGH, HIGH);            //Filter without Green
         break;
    case 2:
         Serial.print("->Frequency G=");
         Serial.println(g_count);
         g_array[1] = g_count;
         TSC_WB(LOW, HIGH);             //Filter without Blue
         break;
 
    case 3:
         Serial.print("->Frequency B=");
         Serial.println(g_count);
         Serial.println("->WB End");
         g_array[2] = g_count;
         TSC_WB(HIGH, LOW);             //Clear(no filter)
         break;
   default:
         g_count = 0;
         break;
  }
}
 
void TSC_WB(int Level0, int Level1)      //White Balance
{
  g_count = 0;
  g_flag ++;
  TSC_FilterColor(Level0, Level1);
  Timer1.setPeriod(250000);             // set 1s period
}
 
void setup()
{
  TSC_Init();
  Serial.begin(115200);
  Timer1.initialize(250000);             // defaulte is 1s
  Timer1.attachInterrupt(TSC_Callback);
  attachInterrupt(0, TSC_Count, RISING);
 
  delay(4000);
 
  for(int i=0; i<3; i++)
    Serial.println(g_array[i]);
 
  g_SF[0] = 255.0/ g_array[0];     //R Scale factor
  g_SF[1] = 255.0/ g_array[1] ;    //G Scale factor
  g_SF[2] = 255.0/ g_array[2] ;    //B Scale factor
 
  Serial.println(g_SF[0]);
  Serial.println(g_SF[1]);
  Serial.println(g_SF[2]);
 
}
 
void loop()
{
	if(Serial.available()){
		if(Serial.readString()=="Balance"){
		Serial.println("Initializing... the ColorSensor , please wait...");
		TSC_Init();
		delay(1000);
 
		  for(int i=0; i<3; i++)
		    Serial.println(g_array[i]);
 
		  g_SF[0] = 255.0/ g_array[0];     //R Scale factor
		  g_SF[1] = 255.0/ g_array[1] ;    //G Scale factor
		  g_SF[2] = 255.0/ g_array[2] ;    //B Scale factor
 
		  Serial.println(g_SF[0]);
		  Serial.println(g_SF[1]);
		  Serial.println(g_SF[2]);
		Serial.println("White Balance is OK");
		}
	  }
	   g_flag = 0;
	   for(int i=0; i<3; i++){
		Serial.print(',');
	    Serial.print(int(g_array[i] * g_SF[i]));
	    }
	   Serial.println(',');
	   delay(1000);
 
}

Personal tools
Namespaces
Variants
Actions
Navigation
Support
Toolbox