TLC5940 With IR sensor problem

I have a code that checks an IR sensor for detection ( such as a hand over the sensor). When a hand is sensed the leds turn on. After the hand is moved , the code waits .5 seconds and then the leds turn off. This works but it only works smoothly for 1 or 2 leds attached to the TLC5940 at most. Once I tell it to do the exact same for more leds, the stop turning off after .5 seconds and just stay on forever. Why would this be?

Here is the code with just 1 led…

#include "Tlc5940.h"

int Threshold;
unsigned long DetectTime;

  void setup()
    {
      Tlc.init();
      Threshold = analogRead(A0);
    }

  void loop()
    {
      int NewThreshold = (Threshold - 7);
      int ReceiverVal = analogRead(A0);
      int Value;
      
      if(ReceiverVal < NewThreshold)
           {
             DetectTime = millis();
             
             
                 Tlc.set(0,500);
                 Tlc.update();
           }
     
      if((millis() - DetectTime) > 500)
           {
              Tlc.set(0,0);
              Tlc.update();
           }
            
     }

But if I add more Tlc.set() to this code, the leds stay on forever. Why would that matter?

I would try a function to do all the LEDs at once.

Like this

void All(int brightness){
  for(int chip = 0; chip < NUM_TLCS; chip++){
    for(int lights = 0; lights < 16; lights++){
      Tlc.set(lights+(chip*16), brightness);
    }
  }
  Tlc.update();
}

I tried something like this earlier… would it be the same as the above suggestion ?

if(yada yada)
            {
               Value = 2000;
               for(int i=0; i< 16; i++)
                  {
                     Tlc.set(i,Value)
                  }
               Tlc.update();
         else
             {
                 Value = 0;
                 for (int j=0; j<16; j++)
                   {
                      Tlc.set(j, Value)
                   }
                Tlc.update();
        }

Yes, but mine accounts for multiple TLC's. However if yours doesn't work mine will not either.

I take it your using the exact circuit from the playground?

Just trying to gather as much information as possible about your setup.

Try adding a Serial.println() to monitor ReceiverVal. You want to determine if the problem is with the input from the trigger or with the output to the Tlc.

Try adding power supply decoupling on each chip:- http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

Thanks I will try Serial.println() and the power supply decoupling and get back to you.

Quick question about decoupling though.... Since from a TLC5940 there are 2 connections to each the ground and + 5v, which do I add the de-coupling capacitors to? Or does it not matter? Also, in the link for de-coupling, it gives suggestions for the sizes of capacitors.... 47 microF and .1 microF. Are these going to be fine or are there other values that will work better? Thanks.

p.s. A simple diagram to show the caps + TLC would help please

Vcc for the chip is port 21. Look here, I believe that's were you put the decoupling capacitor.

OK so the de-coupling does not appear to be working, unless I have the 2 caps set up incorrectly. I just have a 47 micro and a .1 micro each connected from ground to + 5V. What is weird about this is the delay does work perfectly but only if I set a value to each led up to about 20. Which means they are very dim. Any value greater than that and the leds just stay on forever after I wave my hand over the sensor.

Again, here is the code…

#include "Tlc5940.h"

int Threshold;
unsigned long DetectTime;

  void setup()
    {
      Tlc.init();
      Threshold = analogRead(A0);
    }

  void loop()
    {
      int NewThreshold = (Threshold - 7);
      int ReceiverVal = analogRead(A0);
      int Value;
      
      if(ReceiverVal < NewThreshold)
           {
             DetectTime = millis();
             
                Value = 20;
                for(int i =0; i<16; i++)
                  Tlc.set(i,Value);
                 Tlc.update(); 
             
               
                 
                 
           }
     
      if((millis() - DetectTime) > 500)
           {
                 
          Value = 0;
                for(int i =0; i<16; i++)
                  Tlc.set(i,Value);
                 Tlc.update(); 
                 
           
           
              
           }
            
            
     }

poop!

Have you tried monitoring the RecieverVal yet? My bet is that your trigger, which is an optical device, is getting interference from the lights being on. I'm not sure how you have things set up, but you might try completely shielding your trigger from your lights with a piece of cardboard or something.

I have tried isolating the sensor completely from the leds without change.

Since from a TLC5940 there are 2 connections to each the ground and + 5v

No there is only one connection on a TLC5940. Just put a 0.1uF capacitor between pins 21 and 22 as close to the chip as you can manage. It should be a ceramic capacitor with the leads as short as possible. Just try controlling the LEDs without any IR sensor input. Does it work as expected, if not then try and fix that first. If it does then it is your sensors that are at fault. The trick of getting a project to work is just to take one step at a time NOT two.

I've done a little investigating with Serial.println()... Here is an example of what I got...

The threshold value of the light in the room held at a VERY constant value between 980 and 981 which is good because there was no change in light. When I put my hand over the sensor the reading dropped dramatically. But I have folded about 10 pieces of computer paper 6 times and put that in between the sensor and the leds and also put a bunch of paper of the leds, so I dont believe that the actual light from the leds is what is causing the disruption. I think because I am outputting too much power that it is somehow affecting the value that the sensor takes in. Does this sound possible or am I losing it? I hope there is some sort of solution to this problem...

Thanks

Maybe you could give us a sketch of your entire circuit (including all wires, resistors, de-coupling capacitors,etc. and where they are) and someone might be able to locate the issue. I think we've ruled out your code as the source of the problem.

Sure. Here is the setup

  • I have a high powered IR led simply attached to a resistor, and to + 5V and ground
  • I also have an IR photodiode attached close to the IR led. it is negative to A0, and also negative to +5V, and positive to ground
  • I have 9 leds attached to the TLC, negative to a pin, positive to + 5V. Then I have 1 TLC attached exactly how it is in the example on TLC in arduino playgorund WITH a .1 micro F cap between 21 and 22.
    Thats about it

If I take the delay out of the code completely it works perfectly for any number of leds, but when the delay sections are introduced it all goes to S#it after more than 2 or 3 leds.

I am sorry but we really need to see the schematic and see the code. General talking descriptions like posted last and code that says:-

if(yada yada)
            {

Is not going to cut it. A photograph would be good as well.

Here is a link to a short video I made concerning my setup.

Here is the code without the delay setup that works perfectly…

#include "Tlc5940.h"

int Threshold1;
int Threshold2;


  void setup()
    {
      Tlc.init();
      Threshold1 = analogRead(A0);
      Threshold2 = analogRead(A1);
    }

  void loop()
    {
      int NewThreshold1 = (Threshold1 - 7);
      int ReceiverVal1 = analogRead(A0);
      int Value;
      
      if(ReceiverVal1 < NewThreshold1)
           {
              Value = 3500;
              for(int i=0; i<16; i++)
                {
                  Tlc.set(i,Value);
                  Tlc.update();
                }
           }
      else if(ReceiverVal1 >= NewThreshold1)
          {
              Value = 0;
              for(int i=0; i<16; i++)
                {
                  Tlc.set(i,Value);
                  Tlc.update();
                }
          }     
            
     }

And here is the code with the delay implementation…

#include "Tlc5940.h"

int Threshold;
unsigned long DetectTime;

  void setup()
    {
      Tlc.init();
      Threshold = analogRead(A0);
    }

  void loop()
    {
      int NewThreshold = (Threshold - 7);
      int ReceiverVal = analogRead(A0);
      int Value;
      
      if(ReceiverVal < NewThreshold)
           {
             DetectTime = millis();
             
                Value = 20;
                for(int i =0; i<16; i++)
                  Tlc.set(i,Value);
                 Tlc.update(); 
             
               
                 
                 
           }
     
      if((millis() - DetectTime) > 500)
           {
                 
          Value = 0;
                for(int i =0; i<16; i++)
                  Tlc.set(i,Value);
                 Tlc.update(); 
                 
           
           
              
           }
            
            
     }

In the second listing you have:-

for(int i =0; i<16; i++)
                  Tlc.set(i,Value);
                 Tlc.update();

Should this not be:-

for(int i =0; i<16; i++) {
                  Tlc.set(i,Value);
                 Tlc.update();
                 }

to be compatible with the first listing?

ok changed it to that…

#include "Tlc5940.h"

int Threshold;
unsigned long DetectTime;

  void setup()
    {
      Tlc.init();
      Threshold = analogRead(A0);
    }

  void loop()
    {
      int NewThreshold = (Threshold - 7);
      int ReceiverVal = analogRead(A0);
      int Value;
      
      if(ReceiverVal < NewThreshold)
           {
             DetectTime = millis();
             
                Value = 1000;
                for(int i =0; i<16; i++)
                  {
                    Tlc.set(i,Value);
                    Tlc.update(); 
                  }
               
                 
                 
           }
     
      if((millis() - DetectTime) > 500)
           {
                 
          Value = 0;
                for(int i =0; i<16; i++)
                  {
                    Tlc.set(i,Value);
                    Tlc.update(); 
                  }
           
           
              
           }
            
            
     }

Same result