Hello everyone
i bought a HDJD-S822 Color Sensor from sparkfun. I search the hole internet but i found just one code for it
/*
An Arduino code example for interfacing with the
HDJD-S822-QR999 Color Sensor. Put an object in front of the
sensor and look at the serial monitor to see the values the sensor
is reading. Scaling factors and gains may have to be adjusted
for your application.
by: Jordan McConnell
SparkFun Electronics
created on: 1/24/12
license: OSHW 1.0, http://freedomdefined.org/OSHW
Connect the gain pins of the sensor to digital pins 7 - 12 (or ground).
Connect the led pin to digital 13.
Connect Vr to analog 0, Vg to analog 1, and Vb to analog 2.
*/
// Define pins
const int ledpin = 13;
const int GSR1 = 12;
const int GSR0 = 11;
const int GSG1 = 10;
const int GSG0 = 9;
const int GSB1 = 8;
const int GSB0 = 7;
int redpin = A0;
int greenpin = A1;
int bluepin = A2;
// Sensor read values
int red = 0;
int green = 0;
int blue = 0;
void setup()
{
Serial.begin(9600);
pinMode(ledpin, OUTPUT);
pinMode(GSR1, OUTPUT);
pinMode(GSR0, OUTPUT);
pinMode(GSG1, OUTPUT);
pinMode(GSG0, OUTPUT);
pinMode(GSB1, OUTPUT);
pinMode(GSB0, OUTPUT);
// Turn on the LED
digitalWrite(ledpin, HIGH);
// Set the gain of each sensor
digitalWrite(GSR1, LOW);
digitalWrite(GSR0, LOW);
digitalWrite(GSG1, LOW);
digitalWrite(GSG0, LOW);
digitalWrite(GSB1, LOW);
digitalWrite(GSB0, LOW);
}
void loop()
{
// Read sensors
// On page 7 of the datasheet, there is a graph of the
// spectral responsivity of the chip. Scaling factors were
// selected based on this graph so that the gain of each
// color is closer to being equal
red = analogRead(redpin) * 10;
green = analogRead(greenpin) * 14;
blue = analogRead(bluepin) * 17;
// Print values to the serial monitor
Serial.print("Red: ");
Serial.print(red, DEC);
Serial.print("\t\tGreen: ");
Serial.print(green, DEC);
Serial.print("\tBlue: ");
Serial.println(blue, DEC);
delay(200);
}
i connected the pins as it says then i get this result now i don't know what to do with these?
Red: 20 Green: 350 Blue: 153
Red: 20 Green: 364 Blue: 153
Red: 10 Green: 280 Blue: 119
Red: 0 Green: 336 Blue: 221
Red: 0 Green: 336 Blue: 221
Red: 160 Green: 336 Blue: 204
Red: 160 Green: 336 Blue: 204
Red: 150 Green: 294 Blue: 170
Red: 170 Green: 336 Blue: 204
Red: 160 Green: 308 Blue: 187
Red: 180 Green: 378 Blue: 255
Red: 170 Green: 336 Blue: 204
Red: 170 Green: 336 Blue: 221
Red: 170 Green: 336 Blue: 204
Red: 180 Green: 364 Blue: 238
Red: 170 Green: 336 Blue: 204
Red: 180 Green: 378 Blue: 238
Red: 170 Green: 336 Blue: 204
Red: 180 Green: 37
i want to make something like when it detect red write in serial monitor red, same for other colors?
Please help me and i will be thanks full
thanks for replaying