Go Down

Topic: Project 4 - Trying to achieve a better understanding of the RGB LED (Read 1 time) previous topic - next topic

Rinhes

Hello everyone,

So after successfully completing Project 4 I went ahead and decided that I wanted to do a small change to the result of the project and change the brightness of the LED depending on current light in the room, due to the way the project is setup if you are in a room with an intense white light the LED will also be bright and if you lower the intensity of the light the LED will lower its intensity also. So I wanted to completely turn this around, and have a brighter LED on darker light. After reading about the sensors and the characteristics of the LED I am starting to think this LED might not be too good for that.

In any case you can see my code attached, I managed to invert the brightness (darker room brighter LED) but at normal levels of light the change is unnoticeable,  I can see it change when I am flashing directly with a flashlight but not from ambient light. Any thoughts on this will be greatly appreciated.

Code for reference (PasteBin link):

Code: [Select]

// ATTEMPTED TO MODIFY FOR INVERSE LIGHTING I.E. LESS AMBIENT LIGHT
// BRIGHTER LED, PARTIALLY ACCOMPLISHED (LOOK AT COMMENTS) WORK IN PROGRESS
// DUE TO NOT BEEN ABLE TO ACHIEVE A CHANGE AS HIGH AS EXPECTED ON BRIGHTNESS

const int redLEDPin = 11;
const int greenLEDPin = 9; // LED order R - G B
const int blueLEDPin = 10;

const int redSensorPin = A0;
const int greenSensorPin = A1;
const int blueSensorPin = A2;

int redValue = 0;
int greenValue = 0;
int blueValue = 0;

int redSensorValue = 0;
int greenSensorValue = 0;
int blueSensorValue = 0;

void setup(){
  Serial.begin(9600);
 
  pinMode(redLEDPin, OUTPUT);
  pinMode(greenLEDPin, OUTPUT);
  pinMode(blueLEDPin, OUTPUT);
}

void loop(){
  redSensorValue = analogRead(redSensorPin);
  delay(5); // Acomodates for analog read delay
  greenSensorValue = analogRead(greenSensorPin);
  delay(5); // Acomodates for analog read delay
  blueSensorValue = analogRead(blueSensorPin);
 
  Serial.print("Raw Sensor Values \t Red: ");
  Serial.print(redSensorValue);
  Serial.print("\t Green: ");
  Serial.print(greenSensorValue);
  Serial.print("\t Blue: ");
  Serial.println(blueSensorValue);
 
  redValue = (redSensorValue / 4);
  greenValue = (greenSensorValue / 4);
  blueValue = (blueSensorValue / 4);
 
  Serial.print("Mapped Sensor Values \t Red: ");
  Serial.print((255 - redValue) / 2); // substracted from 255 to inverse
  // intensity (i.e. less light more brightness), divided by 2 in an attempt
  // to get LED intensity within human perception
  Serial.print("\t Green: ");
  Serial.print((255 - greenValue) / 2);
  Serial.print("\t Blue: ");
  Serial.println((255 - blueValue) / 2);
 
  analogWrite(redLEDPin, (255 - redValue) / 2);
  analogWrite(greenLEDPin, (255 - greenValue) / 2);
  analogWrite(blueLEDPin, (255 -blueValue) / 2);
}




xinatron

Hi

I'm not an expert but i think because you divided your inverse of the input by 2, the change is much less sensitive. To be honest I didn't even know the green was unseeable by the human eye. You could try making a threshhold under which the will/will not burn, even though there is/isn't light. This will make the led a bit more sensitive.

I hoped my insights helped a bit

Go Up