Photoresistor and strange input on analog pin

Hello All,

I am trying to know in which state a RGB LED is.

In order to accomplish that, I use a photoresistor connected to an analog pin ( arduino Pin)

The led can be in three state : RED / Orange / Green

I bought an built-in photoresistor system :here.

But, even if, the photoresistor is just in front of the led it return always the same value :
1023 for no light ( normal) and 26 for RED/Orange or green light>

You will find my code, below.

Do you have any idea ?


const int ArmP = 5;
const int disarmP = 4;
const int PartP = 3;
const int StatusP = 2;

const unsigned long PRESS_INTERVAL = 3000;
unsigned long initMillis = 0;

void setup() {

  for (int i=2; i <= 5; i++){ 
      pinMode(i, OUTPUT);
      digitalWrite(i, HIGH);


float makeAction(int action, long initMillis ) {
      int lumens = 0;
      int lumensTotal = 0;
      digitalWrite(action, LOW);
      while (initMillis + PRESS_INTERVAL >= millis()) {
        lumens = analogRead(1);
          if (lumens >= 1020)lumens = 0;
        lumensTotal += lumens;
      digitalWrite(action, HIGH);
      return lumensTotal;

void loop() {
  unsigned long currentMillis = millis();
  if (Serial.available() > 0) {
    int value =;
    initMillis = millis();

    switch (value) {
      case 68:
        Serial.println(makeAction(disarmP, initMillis));
      case 65:
        Serial.println(makeAction(ArmP, initMillis));
      case 80:
        Serial.println(makeAction(PartP, initMillis));
      case 83:
        Serial.println(makeAction(StatusP, initMillis));

question - how is that photoresistor suppose to know what color it is as apposed to there's a light on???

Each color has his own luminosity.

As example, I need to increase sensitivity in order to catch the green light.

So, In my mind. the frist step is to calibrate manually my arduino but I cannot do that because I get always the same range of value.

That module has a digital output. It is only intended to show light or no light, as the description very clearly says.

You need a different module if you want an analog output.


I am very surprised !

I checked in web and found some articles like that :

As you can see, I am in the same situation and I am using same components.

Ok I checked and you are right .

Thanks for your help

Don't waste your time with Instructables, most of the electronics or Arduino related ones are posted by people who have no idea what they are doing.

The instructable actually seems ok (I skimmed it). But the point of the instructable is not to detect what color of light a LED gives off, but to detect what color an object is by reflecting colored light off of it. When you do this, you already know what color the LED gives off, because the MCU tells it what to do. Then you use the photo resistor (bare, not in a module) to see how much of that colored light is reflected back by the object.

Your project is completely different. If you can't just read the voltage from the LED pins, you can use two LDRs with color filters, one red and one green.

Bizarre Instructable. I wonder what the author had in mind with this completely idiotic circuit:


Galfisk got what I was inferring. You need different sensors with filters. Otherwise you don’t know if the sensor is reading a color or level.

My main concerned is that my LDR module has only one digital output.

So as you said, I can only have binary data.

I found an LDR with analog output I will try it soon.

I made a hack of my alarm keyfob in order to be able to arm or disable it remotely.

I need to check the colour led to confirm that order was correctly executed.

Why not use a photodiode? Photo-resistors are basically 1960's technology, slow, non-linear, inaccurate, temperature sensistive...

Why not connect input pins to the correct terminals of the LED, and read the voltage directly?
Or replace the LEDs with a couple of optocouplers, and connect these to input pins?

It was my first idea but I am not enough accurate with my soldering iron, I used that method druing one year but I klled the LED.

I really like the idea of the LDR. Because I am not very good on electronic matter I bought a new LDR with an A0 output.

Why not use a photodiode? Photo-resistors are basically 1960’s technology, slow, non-linear, inaccurate, temperature sensistive…

Why not, I am going to buy one to test :slight_smile: But I read that photodiode can only do with two values: 0/1

I will keep you in touch

but I read that photodiode can only do with two values: 0/1

The person who wrote that is terribly misinformed.

Photodiodes are used to measure light levels over a range much larger than that of the human eye. You need a good photodiode amplifier for that range, but these much simpler circuits will work over a lower range.

Raspoutitsa: Each color has his own luminosity. As example, I need to increase sensitivity in order to catch the green light.

Green LEDs are often relatively dim - in order to not look brighter than the red and blue ones to the human eye, our eyes are particularly sensitive to green.

Maybe your best bet is by using an RGB colour sensor. Its three colour sensors should be quite well matched to the colours of the RGB LED.