Need Help with LED Binary Counter

ARGG!!!! No joy. not illuminating the multiple bits in unison

So like the video in your original post?

exactly

And wiring one as shown below does not illuminate it?

led.png

JediMasterAubie:
James, I hooked it up to the 5v out and the ground (with the resistor & LED in the circuit) and it's not illuminating the LED at all.

Then you didn't wire something correctly. This VERY simple test should light the LED.

Two things to try:

  1. Go back to my 5V/Resistor/LED/GND circuit. If you can't make one LED directly powered light up, there is a significant problem. Either the LED is backwards or you some bad wires.

  2. Jack's simple sketch but, again, increase the delay from 1000 to 5000. Observe the difference.

Where did you buy the LEDs? Do you have a link?

Jack, I wired it up again for the GND to 5V just to double check and I may have accidentally slipped the wrong pin for the 5v the first time. The LED illuminates but it blinks.

Ha! You do have those LEDs with built-in blinker circuits! You need some plain ones!

Holy crap. I thought you were joking when you said with built in blinker circuits. I've been using LED's for years and I had no idea that such a thing existed, but taking a look back at the package, it sure does.

I like it when things turn out to be that simple.

Thanks for all the help guys!!!!!!!!!!!!

Baha! Oh yes they do exist. And man, will they mess with your mind!

Good evening, gents!

JediMasterAubie:
I've been using LED's for years and I had no idea that such a thing existed, but taking a look back at the package, it sure does.

Carefully examine the base of the LED and you'll see there is a small component inside, to help it blink. Once you've done that, throw them away! Otherwise, it'll bite you again. :wink:

@JediMasterAubie

If you want, I did a code for a binary counter. It count from 0 to 15, in binary. I did this code in July 2011. I did not learn about bitRead at the time of the code was written.

Just change this :

const int led[4] = {9,10,11,12}; // 9 to 12 are the digital pins
// That is an array. Pin 9 is box number 0. pin 12 is box 3. 
// An array is like an hotel  with room numbers. The box is the room number, and the inside of the room is the pin.

And replace with your pins. Don't worry about the transistors in the comment at this time. I did use a transistor to switch the Leds. But for now, just use a limiting resistor and a Led connect to a digital pin at this time.

/*

Version 1.0
Size : 1182 Bytes

This program will count 0 to 15 and display the result in binary.

TESTED and WORKING

The hardware is connected to a transistor to use as a switch.

Need : 4 Transistor : Common NPN ex: 2N3904
       4 1 K resistor : between the digital pin and the base of the transistor.
       4 LED : Any color
       4 330 ohms resistor : current limiting for the LED.
       
And try to power the LEDs circuit seperated. And don't forget to connect the gnd of the
circuit with the Arduino GND.

Created by Serge Desjardins  --->  Techone
           Toronto, ON   CANADA

Idea from "Bit Math Tutorial by CosineKitty" in Arduino Playground.
           
*/

const int led[4] = {9,10,11,12};

/* Set Output LEDs  --->  A B C D   MSD --- LSD
          Digital pin    12 11 10 9

   Common variables
*/

int pin;
int counting;


void setup()

/*
  Set the pin 12, 11 , 10 , 9  to OUTPUT
*/
{
   for (pin =0; pin < 4; pin++ )
   {
     pinMode (led[pin], OUTPUT);
   }   
}

void loop()

/*  
  Counting routine from 0 to 15 and wait for 1 second
*/
{
 for ( counting = 0; counting < 16; counting++)
 {
    LEDview();
    delay (1000); // The One second delay
 }
}

void LEDview()

/*
  The LED display subroutine. The trick is to brake down the 4 bit data
  ( 0 to 15 ---> 0000 to 1111, so I need HIGH or LOW ( 1 or 0 ) Humm ... boolean
 isolate the proper bit and shift the bit, so it equal in value 1 or 0, 
 so I use the AND operator & ( to isolate ) and the SHIFT RIGHT >> ( to move at 
the proper spot )

My idea came from "Bit Math Tutorial by CosineKitty" in the Arduino playground

From there, you can use a 7447 to count the data ( change 16 to 10 in the counter line ) or 
other use if need parallel data, the only limitation is the digital lines do not come out at the same 
time, but in this way, it is almost at the same time. Bear in mind the small delay after each digitalWrite 
instruction.

*/
{
  digitalWrite (led[3], boolean ((counting & 8)>>3));
  digitalWrite (led[2], boolean ((counting & 4)>>2));
  digitalWrite (led[1], boolean ((counting & 2)>>1));
  digitalWrite (led[0], boolean (counting & 1));
}

I think what we have discovered here may be sort of a high-tech version of those birthday candles that can't be blown out. Of course this could be a much more cruel trick to play on someone ]:slight_smile:

They also make LEDs that flicker like a candle flame. I have a few, pretty cool.

@Jack

I have one of those in my leds parts bin. I place one of them and I see it "blink" "blink".... I replace that led and things work fine.

And I always do a test code to see my hardware setup work. Even I do without Arduino before connecting to see if things work fine.

I'm sorry but I don't understand why for a binary counter nobody use a simple sketch like this one, following.
Doing so, you will have the 6 lower bits on B0...B5 and the higher two bits on D6...D7 (even if I haven't yet discover why)

String ProgramName = "1505-CounterOnPort"; // write here the filename
byte Counter; // definition of the sole variable

void setup() {
//--------------- RX-TX LED's ---------------------------
Serial.begin(9600); //This pipes to the serial monitor
Serial.begin(9600); //This is the UART, pipes to sensors attached to board
Serial.println(ProgramName);

// initialize the PORTs to use

DDRB = B11111111;
DDRD = B11111111;
}

void loop() {
// --------------- Counter ---------------------------------

Counter++;
delay(200);

// --------------- Outputs ---------------------------------

PORTD = Counter; // Lower order 6 bits
PORTB = Counter; // Higher order 2 bit
}