Need some help with simple LED project that's gone awry...

Hi everyone,

I am currently doing a little arduino project for a digital representation unit on my Masters of Architecture course. I'm really enjoying learning about this style of representation but I need some guidance!

My original concept was to wire 100 LEDs to my arduino and have them go off one by one when you go near them, but these LEDs were to be spread across a tree, so the idea would be that you would never be able to capture the light from the tree because it would go out before you got there. This idea was conceived when I knew VERY little about arduino and the complexities this would involve!!

I have scaled it waaaay down and have just managed to charlieplex 20 LEDs to 5 pins with the idea of making them responsive to an LDR.

I am about 1/2 way through trying to edit my charlieplexing code to make this happen, but upon introducing Serial.begin to the code for it to read the analog input from the LDR, all of my LEDs go haywire and start cycling through random sequences.

My question is, is it even possible to make charlieplexed LEDs respond to an analog input?

Or, should I give up now and only use as many LEDs as I can wire to individual pins? This would be a pretty huge scale back from my original proposition and I would be super disappointed to have to give up all the hard work I have put in to understanding charlieplexing.

What do you guys think?

P.s. this project is due in in a couple of days so I don't have time to buy any new components or anything to make this happen, I have my arduino, a bunch of LEDs, 3 LDRs and a bunch of jump leads!

I think you should post your code.

You do not need a serial command to read LDRs, so you are doing your hardware wrong, so you better post your schematic as well.

I hope you have resistors with those LEDs otherwise your project is going nowhere.

Oh dear,

I thought I needed the serial.begin function to get all the values from the LDR in to the serial monitor? To then get the min and max vals.

I THINK my wiring is okay because it cycles through each LED with the designated code perfectly, I will attach the schematic I followed, and a photo of my actual board.

With regards to resistors, yes sir I am using them because otherwise the LEDs are too bright for me to even see to work afterwards! I’m not sure I am using them how you would recommend but they are doing the job for me.

Here is the code - I have taken code from an instructable about cycling through charlieplexed LEDs and I am trying to edit it by adding bits of code I have for using an LDR to turn 10 LEDs on and off. (this is where the serial function has come from…)

As you’ve probably guessed, I don’t really have any idea what I’m doing. With my current skill set I feel a bit like a surgeon who needs to perform open heart surgery but only has a knife and fork to do it.

So in this code, I have left Serial.begin in, and my LEDs go mental, but if I comment it out then they all come on and stay on perfectly.

//BOARD LAYOUT 
#define A 8
#define B 9
#define C 10
#define D 11
#define E 12
#define DELAY 500
#define sensor 1
int val=0;
int level=0;
int c[5][4][2] = {
{ {A, B}, {A, C}, {A, D}, {A, E} },
{ {B, A}, {B, C}, {B, D}, {B, E} },
{ {C, A}, {C, B}, {C, D}, {C, E} },
{ {D, A}, {D, B}, {D, C}, {D, E} },
{ {E, A}, {E, B}, {E, C}, {E, D} }
};
int frames[][5] = 
{
  // Twenty LED s on:
  /*{ 0b1111,
   0b1111,
   0b1111,
   0b1111,
   0b1111
   }*/
};

//SETUP
void setup()
{
  for (int k=0; k<c[5][4][2];k++)
  {
    pinMode( A, INPUT );
    pinMode( B, INPUT );
    pinMode( C, INPUT );
    pinMode( D, INPUT );
    pinMode( E, INPUT );
  }

}
void display( int frame[5], int duration )

{
  int times = 0;
  int x = 0;
  int y = 0;
  while( times < duration )
  {
    for( y = 0; y < 5; y++ )
    {
      for( x = 0; x < 4; x++ )
      {
        setup();
        if( frame[y] & (0b1111>> x) )
        {
          light( c[y][x] );
          delayMicroseconds(DELAY);
          times++;
        }
      }
    }
  }
}

void light( int pins[2] ){
  pinMode( pins[0], OUTPUT );
  digitalWrite( pins[0], HIGH );
  pinMode( pins[1], OUTPUT );
  digitalWrite( pins[1], LOW );
}
void test( int pins[2] ){
  setup();
  light(pins);
  delay(500);
}
void test_loop(){
  for( int i=0; i<5; i++ ){
    for( int j=0; j<4; j++ ){
      test(c[i][j]);
    }
  }
  Serial.begin(9600);
}

//LOOP
void loop()
{
  val=analogRead(sensor);
  Serial.println(val);
  {
    int i;
    for( i = 1; i < 20; i++ )
      //{
      //display( frames[i], 2000 );
      //}
      display( frames[23], 4000);
  }
}

As you've probably guessed, I don't really have any idea what I'm doing. With my current skill set I feel a bit like a surgeon who needs to perform open heart surgery but only has a knife and fork to do it.

You are at the right place ;-) I think many of us started like you.

To your problem:

Hardware : Have you ever thought about taking adressable LEDs? You will only need one digitalPin for >100 LEDs? You can get them in Strips or as single LEDs! This will give you the possibillity to scale it up again.

it is as Grumpy_Mike posted, I don´t see a functionality for the Serial.read(). TO get the Values from the Sensors you need analogRead(PIN); To check the values and make decisions on the readings just use som IF statements. e.g. If (val > 50 && oldLedState == FALSE) {

}

  for (int k=0; k<c[5][4][2];k++)

Nope.
Your array “c” doesn’t have a location with that address, and you wouldn’t use it even if it did.

Edit:

int frames[][5] = 
{
  // Twenty LED s on:
  /*{ 0b1111,
   0b1111,
   0b1111,
   0b1111,
   0b1111
   }*/
};
 display( frames[23], 4000);

And how many elements does “frames” have?

I THINK my wiring is okay

You show nothing of the LDR connections, it is that we want to see a diagram of because that is the bit you are very mixed up about.

That is in addition you using arrays, as AWOL just pointed out.

Oh I see, well I don't have anything to take a photo with just now, but the LDR is wired up on a separate breadboard, wiring should be fine as I have been using it in the lightmeter sketch from the arduino website, which works perfectly.

No not a photo a schematic.

westminster: My original concept was to wire 100 LEDs to my Arduino and have them go off one by one when you go near them, but these LEDs were to be spread across a tree, so the idea would be that you would never be able to capture the light from the tree because it would go out before you got there. This idea was conceived when I knew VERY little about Arduino and the complexities this would involve!!

The LEDs part is anything but complex, if approached in the correct fashion. You need a MAX7219, these are available from eBay as little modules (either assembled or in kit form) to which you can connect a matrix of 64 LEDs - so you can use two and have up to 128 LEDs (and so on ...).

The matrix of 64 LEDs requires sixteen connections from the MAX7219 board - only slightly daunting!

And three control connections from the Arduino.