Class Project issue

Hi i’m french so sorry for my bad english :frowning:
But i have a project in class and i have an issue

So i have a arduino uno and a color sensor ( tcs34725 ) but the light of this sensor is too bright so i need to control this led . My prof said me to use a PWM port for control that but I don’t know how link this to my captor and how i can modifie this valor thanks to the code for control the led intensify …

I will link my program below

#include <Wire.h>
#include "Adafruit_TCS34725.h"

#define commonAnode true

byte gammatable[256];

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

const int sLED = 3; //Control LED brightness on PWM pin for added calibration

void setup() {
  Serial.begin(9600);
  Serial.println("Color View Test!");

  if (tcs.begin()) {
    Serial.println("Found sensor");
  } else {
    Serial.println("No TCS34725 found ... check your connections");
    while (1); // halt!
  }
  for (int i=0; i<256; i++) {
    float x = i;
    x /= 255;
    x = pow(x, 2.5);
    x *= 255;
      
    if (commonAnode) {
      gammatable[i] = 255 - x;
    } else {
      gammatable[i] = x;      
    }
  }
}


void loop()
{
   uint16_t clear, red, green, blue;

  tcs.setInterrupt(false); 

  delay(6000);
  
  tcs.getRawData(&red, &green, &blue, &clear);

  tcs.setInterrupt(true);
  
  Serial.print("C:\t"); Serial.print(clear);
  Serial.print("\tR:\t"); Serial.print(red);
  Serial.print("\tG:\t"); Serial.print(green);
  Serial.print("\tB:\t"); Serial.print(blue);

  uint32_t sum = clear;
  float r, g, b;
  r = red; r /= sum;
  g = green; g /= sum;
  b = blue; b /= sum;
  r *= 256; g *= 256; b *= 256;
  Serial.println();
  Serial.print("C:\t"); Serial.print(clear);
  Serial.print("\tR255:\t"); Serial.print((int)r);
  Serial.print("\tG255:\t"); Serial.print((int)g);
  Serial.print("\tB255:\t"); Serial.print((int)b);
  Serial.println();
}

Can you help me please :wink:

I have some clue like to use an PWM port of my arduino uno and link this to the 3.3V port of my color sensor but i don't sure and like i'm really bad at arduino code i don't understand what code to put forcontrol the brightness (or reduce) of this led :frowning:

Just the link of my sensor : RGB Color Sensor with IR filter and White LED - TCS34725 : ID 1334 : $7.95 : Adafruit Industries, Unique & fun DIY electronics and kits

thanks

I don’t see any code that controls or even turns the LED on...
(the adafruit datasheet images are too small on my ipad)

You’ll probably need to drive the LED from a PWM capable pin on your processor, then analogwrite() allows you to set the on/off duty cycle.

I’m not sure, but varying the brightness of the light source may skew your colour gamma tables, but you need to try it first.

lastchancename:
I don’t see any code that controls or even turns the LED on...
(the adafruit datasheet images are too small on my ipad)

You’ll probably need to drive the LED from a PWM capable pin on your processor, then analogwrite() allows you to set the on/off duty cycle.

I’m not sure, but varying the brightness of the light source may skew your colour gamma tables, but you need to try it first.

Thank you

the sensor have a led port but I really can't be able to see if it's for the control

I will try this tuesday because I have no class before and so I don't have acces to my prototype but I'll let you know after I do this ...

thank you for respond me !

crapouss:
Hi i’m french so sorry for my bad english :frowning:
But i have a project in class and i have an issue

So i have a arduino uno and a color sensor ( tcs34725 ) but the light of this sensor is too bright so i need to control this led . My prof said me to use a PWM port for control that but I don’t know how link this to my captor and how i can modifie this valor thanks to the code for control the led intensify …

I will link my program below

#include <Wire.h>

#include “Adafruit_TCS34725.h”

#define commonAnode true

byte gammatable[256];

Adafruit_TCS34725 tcs = Adafruit_TCS34725(TCS34725_INTEGRATIONTIME_50MS, TCS34725_GAIN_4X);

const int sLED = 3; //Control LED brightness on PWM pin for added calibration

void setup() {
  Serial.begin(9600);
  Serial.println(“Color View Test!”);

if (tcs.begin()) {
    Serial.println(“Found sensor”);
  } else {
    Serial.println(“No TCS34725 found … check your connections”);
    while (1); // halt!
  }
  for (int i=0; i<256; i++) {
    float x = i;
    x /= 255;
    x = pow(x, 2.5);
    x *= 255;
     
    if (commonAnode) {
      gammatable[i] = 255 - x;
    } else {
      gammatable[i] = x;     
    }
  }
}

void loop()
{
  uint16_t clear, red, green, blue;

tcs.setInterrupt(false);

delay(6000);
 
  tcs.getRawData(&red, &green, &blue, &clear);

tcs.setInterrupt(true);
 
  Serial.print(“C:\t”); Serial.print(clear);
  Serial.print("\tR:\t"); Serial.print(red);
  Serial.print("\tG:\t"); Serial.print(green);
  Serial.print("\tB:\t"); Serial.print(blue);

uint32_t sum = clear;
  float r, g, b;
  r = red; r /= sum;
  g = green; g /= sum;
  b = blue; b /= sum;
  r *= 256; g *= 256; b *= 256;
  Serial.println();
  Serial.print(“C:\t”); Serial.print(clear);
  Serial.print("\tR255:\t"); Serial.print((int)r);
  Serial.print("\tG255:\t"); Serial.print((int)g);
  Serial.print("\tB255:\t"); Serial.print((int)b);
  Serial.println();
}





Can you help me please :wink:

Your prof must have been absent from the physics class when you were told that PWM will reduce the brightness the sensor sees. Brightness is a human perception and will certainly be reduced by PWM on the LED, but will NOT change the amount of light emitted when the LED is turned on. It will however, modulate the output of your color sensor, and will certainly show up in the output of the sensor.

What tells you the white LED is too bright? The sensor specs show it has a IR filter. If the light going to the sensor is too great, the answer is a neutral filter for the sensor, in addition to the IR filter.

Paul