Loading...
Pages: [1] 2   Go Down
Author Topic: HDJD-S822 Color Sensor Code?  (Read 1014 times)
0 Members and 1 Guest are viewing this topic.
Sulaymaniyah-Kurdistan
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone
i bought a HDJD-S822 Color Sensor from sparkfun. I search the hole internet but i found just one code for it
Code:
/*
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?
Code:
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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 315
Posts: 35519
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i connected the pins as it says then i get this result now i don't know what to do with these?
Without telling us what you were pointing the sensor at, we can't tell whether the results are reasonable, or not.

Without knowing whether the results are reasonable, or not, we can not advise you about how to proceed.
Logged

Sulaymaniyah-Kurdistan
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for replaying, i just test some sticker papers , 5 cm away from the sensor
Logged

UK
Offline Offline
Tesla Member
***
Karma: 89
Posts: 6386
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i want to make something like when it detect red write in serial monitor red, same for other colors?

What 'other colors' do you need to detect? If the choices are nothing/red/green/blue then you could do it by finding the hue with the greatest intensity and comparing it with a threshold. Of course, you'd need to confirm that your sensor and code to read it actually return RGB values that correspond to the colour actually in front of the sensor - garbage in, garbage out.
Logged

Sulaymaniyah-Kurdistan
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

could give an anther code example and can you give sketch if you can
with my best regards
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 315
Posts: 35519
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i just test some sticker papers , 5 cm away from the sensor
The purpose of the test was to determine a correlation between the input and the output. If you are not going to do that, then the answer to your question "i want to make something like when it detect red write in serial monitor red, same for other colors?" is "send whatever you feel like".

If you'd like to try again, you'll say something like "I held a yellow sheet of paper in front of the sensor, and I got this output (followed by some output). Then, I held a red sheet of paperin front of the sensor, and I got this output (followed by some output)."
Logged

Sulaymaniyah-Kurdistan
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

does it need to be in a dark room or the room light doesn't affect it?
does it need to switch on the led on the board, or not?
please explain more clearly cuz i'm a newbie
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 315
Posts: 35519
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
does it need to be in a dark room or the room light doesn't affect it?
That is something that you need to experiment with, to determine.

If you hold a red sheet of paper in front of the sensor, and it shows a value for red, and no values for green or blue, regardless of the amount of, or type of, room lighting, then the answer is no, room light does not affect it. Otherwise, the answer is yes, room light matters.

Quote
does it need to switch on the led on the board, or not?
Yes. Or maybe no. Post a link to, not a description of, the sensor.

Turning the onboard LED on for sufficient light to activate the sensor is not going to happen. Unless you are referring to an LED on the sensor board.
Logged

Sulaymaniyah-Kurdistan
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yellow paper
Code:
Red: 210 Green: 392 Blue: 136
Red: 180 Green: 336 Blue: 119
Red: 190 Green: 350 Blue: 119
Red: 180 Green: 336 Blue: 119


red paper
Code:
Red: 100 Green: 140 Blue: 731
Red: 100 Green: 140 Blue: 612
Red: 100 Green: 140 Blue: 476
Red: 100 Green: 140 Blue: 357
Red: 100 Green: 154 Blue: 306
Red: 100 Green: 154 Blue: 238
Red: 100 Green: 140 Blue: 170
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 315
Posts: 35519
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'd suggest that there is either something wrong with your sensor, your wiring, or your lighting, then. The output does not correlate well with the input.
Logged

Sulaymaniyah-Kurdistan
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

can your give me the sketch?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 315
Posts: 35519
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
can your give me the sketch?
What sketch?

There are still no links to the sensor you are using.
Logged

Sulaymaniyah-Kurdistan
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ah sorry here
https://www.sparkfun.com/products/10904

but the red rgb is 255,0,0
like if you put a red paper will it also be 255,0,0 or different because i think the light also effect it
thanks for helping me bro
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 138
Posts: 19067
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Red: 100      Green: 140   Blue: 731

Quote
but the red rgb is 255,0,0
Doesn't seem likely, given that blue value.
Logged

Pete, it's a fool looks for logic in the chambers of the human heart.

Sulaymaniyah-Kurdistan
Offline Offline
Jr. Member
**
Karma: 0
Posts: 89
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what should i do to make it better?
Logged

Pages: [1] 2   Go Up
Print
 
Jump to: