Connect with us

Microcontroller LED project.

Discussion in 'Microcontrollers, Programming and IoT' started by Inverness, Oct 30, 2018.

  1. Inverness

    Inverness

    6
    0
    Oct 30, 2018
    Hello.

    I'm making a sewable electronics project. I originally intended to use a board based on ATTiny 85, but I've run out of practical ways to drive them considering the pin amount. It's to be fitted in a glove and powered by a power bank. I'm planning on using an Arduino pro micro instead

    [​IMG]

    I'm using lilypad LEDs which come with 100Ω SMD resistor and should have a 20 mA test condition current draw, though I'll say I didn't get them through a reputable source, that source reports 40 mA.

    The first four set of blue LEDs will follow a blinker pattern similar to some cars. It's a variation on a standard PWM fade. With the press of the button, they will stop blinking and be fully lit. Another press of the button will light up the 10 LED array. At 20 mA @ piece, that should be 200 mA max with 40 mA per pin going from the 20mA estimate.

    Code:
    #include <Button.h>
    const byte ledPins[4] = {6, 9, 10, 11};
    
    Button blinkLed(2);
    
    int n = 0;
    
    void setup() {
      blinkLed.begin();
    
      Serial.begin(9600);
     
      for(int i = 0; i <= 3; i++){
        pinMode(ledPins[i], OUTPUT);
        
      }
    
    }
    
    void loop() {
      if (blinkLed.pressed() && n == 0) { //if n indicates LED = off with n=0, start blinker program
       n++;
       Serial.println(n);
        while(n == 1){
        for(int i = 0; i <= 3; i++){
        for(int j = 0; j <= 255; j+=2){
        analogWrite(ledPins[i], j);
        delay(1);
        }
      }
        for(int i = 0; i <= 3; i++){
        for(int j = 255; j >= 0; j-=2){
        analogWrite(ledPins[i], j);
        delay(1);
        }
      }
          if (blinkLed.pressed() && n == 1){ //if n indicates LED = blinker start small flashlight
            n++;
            Serial.println(n);
               while(n == 2){
                digitalWrite(6, HIGH);
                digitalWrite(9, HIGH);
                digitalWrite(10, HIGH);
                digitalWrite(11, HIGH);
          
                if (blinkLed.pressed() && n == 2){ //if n indicates LED = small flashlight, turn off small flashlight and start big flashligh
                  n++;
                  Serial.println(n);
                  digitalWrite(6, LOW);
                  digitalWrite(9, LOW);
                  digitalWrite(10, LOW);
                  digitalWrite(11, LOW);
                  while(n == 3){
                    digitalWrite(3, HIGH);
                    digitalWrite(4, HIGH);
                    digitalWrite(5, HIGH);
                    digitalWrite(7, HIGH);
                    digitalWrite(8, HIGH);
                    
                    if (blinkLed.pressed() && n == 3){ //if n indicates LED = big flashlight, turn off
                    n = 0;
                    Serial.println(n);
                    digitalWrite(6, LOW);
                    digitalWrite(9, LOW);
                    digitalWrite(10, LOW);
                    digitalWrite(11, LOW);
                    break;
                  
    
    
                    }
                }
              }
            }
          }
        } 
      }
    }
    
    
    I would love to power this with my original ATtiny based board as that is made for wearables. This concept can be used, but due to pin restrictions, I would need some way of powering the large array. I made a concept where I use a slide switch to move current from the last pin on the 4 LED array to the entire 10 LED array. (Before I realised this isn't possible) But maybe I could use the pin as a signal to turn on a driver of some sort? Still, this adds complexity that may be quite hard to add in a wearable project.

    My questions:

    I can probably improve my code, though it works in this state. Any suggestions? I would, of course, delete anything serial related.

    How could I test the amperage usage from the LEDs and get a reliable result? I have a multimeter.

    Is it feasible to drive the LEDs like this? Are the max currents very strict, as in it will break down if I exceed them?

    Has anyone ever used an Arduino micro with conductive sewing thread?

    How could I power this using the original ATtiny85, making it as small as possible? (Even if I probably won't do this, I'm interested in learning)
     
  2. Bluejets

    Bluejets

    2,976
    578
    Oct 5, 2014
    To use the Attiny you will have to re-write the code to suit.
    As you already noted though, not enough pins for the above.
    If you want to drive larger than 20mA per pin, use a logic level mosfet on each pin and drive the load from the battery, still using the resistors on the leds of course.
    Or you may be able to use combinations of leds with the same mosfet and use one of the many small led driver modules kicking around for maybe $1 or so on Ebay.
    Use the amp range on your multimeter and turn leds hard on to get a maximum reading. If the leds are flashing they will use less but at least the worst case is covered with the former.
    2n7000 should be ok, depends on what loading you add.

    When writing code you need to improve by at least using comments and the format tool.
    Possible that the code could be a lot simpler also but this will come with practice.
    Finally, get away from using fritzing.
     
    Last edited: Oct 30, 2018
  3. Inverness

    Inverness

    6
    0
    Oct 30, 2018
    Thank you for your reply.

    I won't go into MOSFETs for this project because it's unfeasible to use them for a wearable project, but it's good to know, as I already have a project where this could be useful.

    There seems to be a difference in consensus regarding how much each pin on the Arduino pro micro can drive. I realize my plan of 40 mA per pin may not be "good" per the datasheet, but is it feasible?

    I'm not huge on commenting, but recognize that I should, so the ones that are there were added after I wrote the thing. In regards to fritzing, this is tinkercad's circuits. I used that a while ago, and I was hoping to use the schematics function, which I then found removed when I was done setting it all up... Feeling lazy I didn't bother trying to find out how I could make one. But I'm "proud" to say the whole thing was built and thought up without any such aids. Any preferences for software to make schematics?
     
  4. kellys_eye

    kellys_eye

    4,289
    1,143
    Jun 25, 2010
    It's not so much the individual port current capability as the packages overall power dissipation limit. You can't run ALL the ports at the maximum as you exceed the total power dissipation limit.

    It's also not wise to use the absolute maximum (theoretical anyway) values for reliability purposes. Keep it 20-25% under for safety sake.

    There are many buffer chips (inverting and non-inverting) that can be fitted to boost the port capability. The ULN2003 for example (find the datasheet).
     
  5. Bluejets

    Bluejets

    2,976
    578
    Oct 5, 2014
    You ask for assistance then argue the point.
    Additionally, mosfet size is hardly an issue when it is less than the size of one standard led.
     
    hevans1944 likes this.
  6. BobK

    BobK

    7,380
    1,559
    Jan 5, 2010
    Another option is WS2812B LEDs. These are RGB and controlled by a datastream. Power does not go through the micro at all, and you have complete control over the brightness and color of each LED. I just put 40 of these into a ballroom gown for my latest dance showcase (the lovely wife Morticia wore the gown, not me :))

    If you do this, please don't leave out the step (no pun intended) I did. I meant to put a coating of epoxy over the solder connections to keep them from breaking under stress. It worked perfectly during all of our practices, then, the day of the performance some of the wires broke and some of the lights on the front of the dress did not work. I took a shortcut and it came back to bite me with no time to fix it.

    Here is a link:

    https://www.amazon.com/100PCS-Built...58&sr=8-2&keywords=ws2812b+single+chip+boards

    These snap apart and the board is about 1 cm round. They need 3 wires between them and the micro and the data line is wired in series. Only 1 micro pin needed to run all of the LEDs.

    Bob
     
  7. Inverness

    Inverness

    6
    0
    Oct 30, 2018
    I never meant to argue. The size isn't what I was referring to when I said unfeasible, but sewing stuff that isn't made to be sewn isn't easy.
     
  8. Inverness

    Inverness

    6
    0
    Oct 30, 2018
    A chip like that would work. Just so I get this straight, I should be less worried about one single port, but at the very least keep it 20-25% under the total power dissipation limit? I'm going to find a different way to do my project.
     
  9. Inverness

    Inverness

    6
    0
    Oct 30, 2018
    I had a simple "on/off" single colour LED wearable project a while ago, and I absolutely get how finicky they are. It's not easy, and the conductive sewing thread I'm going to be using is so slippery. Coincidentally I got a bunch of these in the mail today:

    https://www.adafruit.com/product/1260

    I didn't even think of separating the power and data line. I'm going to cook something up as soon as I can.
     
  10. BobK

    BobK

    7,380
    1,559
    Jan 5, 2010
    Yep, those are the same thing except $2 a piece instead of $0.29 for the ones I linked.

    Bob
     
  11. Inverness

    Inverness

    6
    0
    Oct 30, 2018
    No way I got them for 2$ a piece :) Which is why I'm also wondering about some behaviour. Using the Neopixel library I use the code:
    strip.setPixelColor(n, red, green, blue);
    Where n is number of pixels in the chain.
    I get the colour to show, however whenever a value for red is present, that is the only colour that will shine. Green and blue will "try" to turn on, only flickering. I cannot remember if the same behaviour is present with blue and green alone, but I think so and unable to test at this moment. However, if there is a rolling colour animation, it seems to transition well from a colour to the next.
    Is there something I missed or is this intended behaviour?
     
  12. BobK

    BobK

    7,380
    1,559
    Jan 5, 2010
    Sounds like supply voltage is too low. Green and blue require higher voltage than red. Check the voltage with the lights on.

    These are supposed to work at 5V, but I have used them sucessfully with one Lithium cell, about 3.7V.

    Bob
     
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.