Help with Arduino PWM LED driver

Discussion in 'Embedded Systems and Microcontrollers' started by roof, Jan 9, 2016.

  1. roof

    Thread Starter New Member

    Jan 8, 2016
    Hi folks, it's my first thread in this forum.
    Version 1.
    I'm in a phase of my construction when it stop up. This circuit using Arduino Nano USB, 2 green LED, 2 red LED, all 3W, 700mA, red 2,5V, green 3,5V Vcc. It's a pilot strobe flasher for UVA/Drone using. When power on, green led 1 & 2 flash approx. 200mS, one by one. This repeat each 3 sec. 4 sec. after power on, red led 3 & 42 flash approx 200mS. 200mS ON, give a strong light effect, like strobe. By this delay, green led flash each 3 sec, while red flash each 4. sec.

    This url link is my first diagram:
    (see diagram uploaded) .

    Version 2:
    When thinking about each grams in weight count, and will decrease flight time, something has to be done. I skip the MOSFET array IC, I change step down converter (to adaptive correct voltage for LED's), to PWN 700mA constant drivers for LED. This drivers are quite best in use, when it comes to constant current flow, because of this 3W led change it's properties when heated, moisture etc. Driver provides a constant current drive @ 700mA. QUESTION are so, how to controlling PWM frequency to provide 2.5 volts and 3.5 volts to LED's?

    I need help both to Arduino wiring diagram (see Annex No. 2, one attempt with the approach of schematic wiring) and reprogram my Sketchup. Uploading my Sketchup as it is today, but must be changed to charts ver. 2.

    PWM LED driver:

    3W LED type:

    SKJEMAS LED DRIVER_600x624.jpg
    Please help me!
    Ver. 1.0
    Ver 1.0 Flash-light-Arduino-Buck-Per-18.10.15-1.png
    Ver 2.0
    Ver 2.0 Flash-light-ArduinoLED-DRIVER-28.12.15.png
    Arduino Sketchup for ver 1.0
    Code (Text):
    2. const int ledPin1 =  13;      // Set pin's in use :
    3. const int ledPin2 =  12;
    4. const int ledPin3 =  11;
    5. const int ledPin4 =  10;
    7. // Variables will change :
    8. int ledState1 = LOW;             //
    9. int ledState2 = LOW;
    10. int ledState3 = LOW;             // ledState used to set the LED LED STATUS :
    11. int ledState4 = LOW;
    12. long previousMillis = 0;        // will store last time LED was updated :
    13. long count = 0;
    15. long interval = 95;           // interval at which to blink (milliseconds) lower faster blinks :
    17. void setup() {
    18.   // set the digital pin as output :
    20.   pinMode(ledPin1, OUTPUT);
    21.   pinMode(ledPin2, OUTPUT);
    22.   pinMode(ledPin3, OUTPUT);
    23.   pinMode(ledPin4, OUTPUT);
    24. }
    25. void loop()
    26. {
    28.   do
    29.   {
    30.     unsigned long currentMillis = millis();
    32.     if (currentMillis - previousMillis > interval) {
    33.       // save the last time you blinked the LED
    34.       previousMillis = currentMillis;
    36.       // if the LED is off turn it on and vice-versa :
    37.       if (ledState1 == LOW ) {
    38.         ledState1 = HIGH;
    39.         ledState2 = LOW;
    40.       }
    41.       else {
    42.         ledState1 = LOW;
    43.         ledState2 = HIGH;
    44.         count++;
    45.         // set the LED with the ledState of the variable :
    46.       }
    47.       digitalWrite(ledPin1, ledState1);
    48.       digitalWrite(ledPin2, ledState2);
    49.     }
    50.   } while (count < 2); //sets how many blinke :
    51.   ledState2 = LOW;
    52.   digitalWrite(ledPin2, ledState2);
    53.   count = 0;
    54.   //=========================================================
    55.   delay(1000); // PAUSE and sets the time beteewen set green and read
    56.   //=========================================================
    57.   do
    58.   {
    59.     unsigned long currentMillis = millis();
    61.     if (currentMillis - previousMillis > interval) {
    62.       // save the last time you blinked the LED
    63.       previousMillis = currentMillis;
    65.       // if the LED is off turn it on and vice-versa:
    66.       if (ledState3 == LOW) {
    67.         ledState3 = HIGH;
    68.         ledState4 = LOW;
    69.       }
    70.       else {
    71.         ledState3 = LOW;
    72.         ledState4 = HIGH;
    73.         count++;
    74.         // set the LED with the ledState of the variable:
    75.       }
    76.       digitalWrite(ledPin3, ledState3);
    77.       digitalWrite(ledPin4, ledState4);
    78.     }
    79.   } while (count < 2);
    80.   ledState4 = LOW;
    81.   digitalWrite(ledPin4, ledState4);
    82.   count = 0;
    83.   //=========================================================
    84.   delay(1400);  //sets the time beteewn set green and read
    85.   //=========================================================
    86. }
  2. sailorjoe


    Jun 4, 2013
    Roof, first problem I see is that an important input to your LED driver circuits is missing. This is in Version 2.0. The units need I+ and I- connected. In your case, most likely, I- should be connected to ground. But it's hard to tell because you don't label the input and output pins with signal names, just pin numbers. That doesn't tell me very much.
    Now, the Arduino Nano outputs should be set up as PWM signals, so you can control the brightness, and these should be connected to the PWM inputs on the LED drivers. If you don't want to to control the brightness, just strobe the lights on/off, then fine just drive the PWM signal as an on/off pulse.
    I believe that is what your code is doing, so it should be OK.
    Your code seems OK to me after reading it just one time.
  3. dannyf

    Well-Known Member

    Sep 13, 2015
    Two comments:

    1. you provided lots of information, not much of it is helpful to people who want to help you;
    2. you may have to play with the led driver modules a little. looks like it takes a pwm input signal. If that's the case, you are golden.
  4. roof

    Thread Starter New Member

    Jan 8, 2016
    (Thanks to moderator, as move my thread :))
    Are you for sure this LED driver are missing an input in the trigger input? To me it make sense, this device could be driven by negative or positive input pulse. Not correct? Well, if I use a full voltage output from Arduino, this value is 5 or 0. 5 volts to the LED is too much, and just hang on a 3W resistor voltage dealer, not a good solution. The purpose of the constant current Controll disappears. I'm not for sure, if I insert a spanning parts resistance in series with the output from the Arduino, two this PWM module, do I Obtain output Vcc or some lower voltage level?
    "But it's hard to tell Because you do not label the input and output pins with signal names, just pin numbers. That does not tell me very much." If you take a look at the Arduino Nano device, it should give you information, see URL here, above pinout here:

    The code are not composed of PWM, only on / off, my schematic drawings showing how to insert variiable resistances which creates pulse mode cycle, but this addition is missing in sketchup. The code you see is NOT made by me, but by Arduino our friend, as opposed to me, is super good, I'm a newbie.

    To Danyf; What is it you miss, unlike you, I tell complementary what I know and do not let it be up to me to guess. Please, be more explanatory.
  5. shteii01

    AAC Fanatic!

    Feb 19, 2010
    So... we do the design, we do the programming and we get what for all that work?
  6. roof

    Thread Starter New Member

    Jan 8, 2016
    Do not think shteii01 have sense of orientation in order? As you will see, it lacks a Sketchup additional PWM, everything else is arranged. If you feel a waste of time and "money", throw then not waste time on frayed comments.
  7. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    Your sketch does not use PWM currently, as you stated. Not all pins on an Arduino capable of PWM also. Fortunately, your sketch is using the correct pins for PWM.

    Instead of using the command digitslWrite(), you need to use analogWrite(). This command takes duty cycle as its second parameter instead of state. Duty cycle is a value from 0 to 255, where 255 is 100% on.

    If you supply is 5VDC and you need 2.5V, use a 50% duty cycle. This is a value of 127 in analogWrite.

    The sketch will keep the signal outputting with the specified duty cycle, until you change it. This to shut it off, use a duty cycle of 0.

    Your existing sketch can be easily modified to use analogWrite() in the sketch structure. Just change the meaning of the ledStatex variables.
  8. roof

    Thread Starter New Member

    Jan 8, 2016
    Djsfantasi, LOVELY! Thats mean, not necessary to use vari pot. resistor? Just set in parameters, as fit to my needed out voltage. Vcc is 12.0V. So with value 1-255, should be easy to set parameters level for 2,5V and 3,5 V. Thanks a lot!
  9. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    I don't see a need for a pot.

    However, looking at your diagram, I noted the pins you are using. They don't all support PWM on the nano. Look at the pin out diagram. Pins 6,8,9,12-14 may be used for PWM. Your LEDs need to be connected to one of those pins.

    Also, remember the current limitations from an Arduino pin. It is a maximum of 40mA. I don't get what the boxes before the LEDs do, so I don't know their current draw.

    Note that just to be confusing, the nano pin numbering scheme is different than the digital pin labeling scheme. Use the nano pin numbers! Remembering that D09 is pin 12 is tough. Just use pin 12.
    Last edited: Jan 16, 2016
  10. shteii01

    AAC Fanatic!

    Feb 19, 2010
  11. roof

    Thread Starter New Member

    Jan 8, 2016
    I thought when I look at the diagram for Nano, I was using PWM pins output. 6,8,912, and 14 are PWM. So using 30 as +12V, and 20 as GND. Because of this circuit befor LED, this have a high input resistance, so because of this this PWM power constant DC-DC driver will not load Arduino its max load of 40mA. Simultaneously deliver this constant current of 700mA, 3W LED. A constant current driver is the best component for a 3W LED to use this to component. The LED's internal properties can easily change, and variable current will be required to ensure LED life condition, at worst, prevents this for burning off. This is the circuit's intended use.

    Maybe you also noticed in the schema, a circuit between the battery source and Arduino? With different causes, a Li-Po battery 1500mAh 11.1 volt source weighs 132 grams. Therefore I used two Li-Ion 18650 3.6V 3300mAh X2, in series = 106 grams including battery box. This provides approximately 7.6 volts, close to being too low drive voltage for my PWM, = min. 7.0V. This step up converter (Buck)) converts 7.6 volts to 12.0 volts (max 2A)
  12. sailorjoe


    Jun 4, 2013
    Roof, Let me try to be more clear on what I think is missing. You have an LED driver circuit, and it has 7 pins. On your schematic, you only have four pins numbered for the LED driver, but no way to tell which pin on the schematic matches the pin on the module. I can guess some of the pins because they're pretty obvious, like LED+ on Pin 3 and LED- on Pin 4. Pin 2 is probably I+ on the module. That leaves Pin 1, which is either PWM or I-. I can't tell which.

    In my opinion, I- should be connected to ground. Your Arduino logic signal should be tied to the PWM pin on the LED driver. If that's what you have, great, but then where is I- connected?
    djsfantasi likes this.
  13. roof

    Thread Starter New Member

    Jan 8, 2016
    Tak a lokk at this, my Chinese co operated company write in an answer, how it works(?):

    Now We have get solution to your question.

    Board lights on a serial link to the LED+ and LED-pins;
    Links to IN+ and IN-input voltage, working in the buck mode to ensure total pressure difference lower than the input voltage of the LED 2-3V to work.
    You can IN-and links to Arduino PWM pin GND and digital I/O, output of the PWM signal to control the LED brightness.
    PWM maximum signal frequency: 20HZ-20KHZ
    Rated proposal: 1KHZ

    Some sense?
  14. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    The voltage supply, pin 30, is input to a voltage regulator to provide the Arduinos 5V operating voltage. Your output pins will provide 5V maximum. To provide a higher PWM voltage, you'll have to supply a second voltage source, tie it ground to the Arduino ground, drive it through a transistor or MOSFET. The Arduino will not supply more than 5V.

    Also, note that pins 6,8,9,12,13,14 all can be used for PWM. As such, they are an output. In your second diagram, I see them as an input, from a pot.

    I think there is some confusion as to what PWM is and how your constant current "boxes" are used (where is the power for the LEDs?)

    Is this the case?
    Last edited: Jan 16, 2016
  15. roof

    Thread Starter New Member

    Jan 8, 2016
    Well, my Vcc are +12V. So pins 30 should be the right + in voltage, i think. I did not need any + 5 volt in my schematic diagram. See diagram Nano, pin 30 "SUPPLY VOLTAGE IN-7 - 12 V DC. Well, to adjust brightness as a dimmer, the pot vario resistance can be used to adjust the PWM duty cycle, but it's also a possible to set this as permanent value, due to your text: This command takes duty cycle as its second parameter instead of state. Duty cycle is a value from 0 to 255, where 255 is 100% on. I found @ Vcc 12 volts, the value for 2,5 volts are approx. 53.125,-3,5 volts=74,375. So, potmeters are not longer needed to use, when I set this permanent value, for a permanent PWM duty cycle.

    ... (where is the power for the LEDs?) This power are created using DC-DC constant current drivers, 1-4. This driver's are supplies with +12V, GND. As I told you before here.
  16. sailorjoe


    Jun 4, 2013
    Sorry, I don't understand the explanation. Let me ask it this way. Where is the ground line (I-) for the LED driver module shown on your schematic? Which PIN number is it? Also, which PIN number on the LED driver module on your schematic is the PWM signal?
  17. roof

    Thread Starter New Member

    Jan 8, 2016
    The explanation was some puzzled for me to catch, also. There is no ground line for the load side. Probably it like this, IN- to GND Arduino. the I/O from Arduino as PWM out pin to IN+. Correct? The pin no for LED in my schematic are not set up, but I make some change in a while.
  18. sailorjoe


    Jun 4, 2013
    OK, I'll wait.
  19. roof

    Thread Starter New Member

    Jan 8, 2016
  20. sailorjoe


    Jun 4, 2013
    Thanks, Roof. OK, your schematic still doesn't have I- connected to GND, and that's a problem. I don't know where the current is going, but probably through the PWM pin for each driver. Eventually, your nano is going to fry, or maybe the driver module will fry. So please connect I- to GND.
    Djsfantasi has already indicated how to use PWM in your Sketch to control on/off and brightness, if that's something you need to do. It can be useful to balance the red and green light pulses.