Close
0%
0%

Blinking 6W of LEDs

Blinking (2x3W) LEDs with an ATTiny45 and a 240mAh battery

Similar projects worth following
With new rules and regulations coming along for flying rc planes, uni and multicopters(drones or not) in Norway one of the requirements is that you should always maintain visual contact with your drone. A friend of mine wanted some extra blinky lights on his DJI Phantom 3 Pro for extending his visual flightrange.
After testing with some 0.5W white LEDs the results were not entirely satisfying so some 3W LEDs were acquired.

Everyone have blinked some LEDs with something, right?

I'll just rabble down some of my workflow here.

First I did the software, in one evening, with a sixpack.

Then I do the circuit in Fritzing protoboardview, its got most of the components readily available and doing it in protoview
gives a very good overview. Then i sort the basic layout out in the schematic view. By this time i can also start protoing RL.

After that I redo the entire circuit in Designspark schematic view adding the proper components etc. After debugging the RL proto and the schematic its time to move to PCB layout and routing. Designspark has a 3D view of the PCB so its really easy to see if you screwed up before you start building the PCB.

Then i solder the whole shebang together and start testing the software and building a 3D printable case for it.

With this project I really only hit one minor bump in the road. While charging it was reading the battery voltage as 4.3 volt resulting in no charging since battery is to only be charged to 4.2volts. The cause of this turned out to be that since it is using the same pin to charge the battery and measure the voltage the measurements was done too soon after charging. Adding a 2ms delay between charging and measuring solved everything.

DWG Drawing - 176.55 kB - 01/20/2016 at 22:19

Download

pcb - 34.00 kB - 01/20/2016 at 22:19

Download

plain - 7.51 kB - 01/20/2016 at 22:19

Download

sch - 35.00 kB - 01/20/2016 at 22:18

Download

fzz - 16.89 kB - 01/20/2016 at 22:18

Download

View all 7 files

  • 1 × Attiny45 Microprocessors, Microcontrollers, DSPs / ARM, RISC-Based Microcontrollers
  • 1 × Capacitor 100µF
  • 1 × Pot.meter 10Kohm
  • 1 × Resistor 56Kohm
  • 2 × LED 3W

View all 12 components

  • The code

    Non-ICE10/01/2015 at 18:43 0 comments

    /*
    Dronestrober with BMS and charger

    when running on 4.4 volt or less it will strobe leds
    when run on more it will charge the battery to (approx.) 4.2 volt, let it drop to 4.0 before recharge
    will cut off operation at cell voltage about 3 volts

    dji phantom pro 3 lower leg 9x7mm



    flashing status readout

    battery mode:
    Vcc x.x volts
    2 sec delay
    battery pin read, nonsense
    2 sec delay
    flashing operation starts.


    USB power mode:
    Vcc x.x volts, ususally 5 blinks then 3 sec delay (5 volts)
    at least 2 sec delay
    battery x.x volts, 1 sec delay is the decimal separator
    2 sec delay
    charging mode starts:
    flash every second: CHARGING
    flash every 5 seconds: CHARGING DONE

    */




    //sleep stuff
    #include <avr/sleep.h>
    #include <avr/wdt.h>
    //#include <avr/power.h>
    #ifndef cbi
    #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
    #endif
    #ifndef sbi
    #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
    #endif



    //for sleep mode watchdog timer
    volatile boolean f_wdt = 1;


    const int batpin = 3; // D3 and A3 for charging ans sensing battery voltage.
    const int ledpin = 4; // LED pin -> mosfet -> LED
    const int potpin = 1; // analogue input 1 (pin 2) for strobe setting, read only first 60 secs. or something.

    //battery data
    const int batmax = 4080; //max battery charge voltage mV
    const int batrecharge = 3950; //restart charge coltage mV
    const int batmin = 3100; //min battery charge voltage mV
    const int chargethreshold = 4400; //charge vs operation threshold

    int voltage; //battery measured
    int sensorValue; //temp readvalue
    int debug; //debug



    //variables will change:
    int runmode=1;
    int wdduration=5;
    int blinks;

    int ond=20; //on delay for LED
    int itv; //interval 1 for LED sleepdelay
    int sitv; //interval 2 for LED sleepdelay

    void setup() {
    //internal voltage reference
    //analogReference( INTERNAL2V56_NO_CAP );
    //indicate on state
    digitalWrite(ledpin,HIGH);
    delay(10);
    digitalWrite(ledpin,LOW);
    //sleep before sensing input voltage.
    setup_watchdog(8); // approximately 4 seconds sleep before starting operation.
    system_sleep();

    delay(10);
    //show Vcc
    int bdebug=readVcc()/1000;
    int adebug=(readVcc()/100)-(bdebug*10);
    while (bdebug>0) {
    digitalWrite(ledpin, HIGH);
    delay(1);
    digitalWrite(ledpin, LOW);
    delay(400);
    bdebug--;
    }
    delay(1000);
    while (adebug>0) {
    digitalWrite(ledpin, HIGH);
    delay(1);
    digitalWrite(ledpin, LOW);
    delay(400);
    adebug--;
    }

    delay(2000);

    //read input voltage
    if (readVcc() > chargethreshold) {
    runmode=1; //runmode for charging.
    }
    else {
    runmode=2; //runmode for strobing
    }



    pinMode(batpin, INPUT);
    pinMode(ledpin, OUTPUT);
    pinMode(potpin, INPUT);

    }



    void loop(){

    if (f_wdt==1) { // wait for timed out watchdog / flag is set when a watchdog timeout occurs
    f_wdt=0; // reset flag
    }



    //check runmode
    //pinMode(batpin,INPUT);
    sensorValue = analogRead(batpin);
    voltage = (1000 * (sensorValue * (5.0 / 1023)));

    if (debug!= true) {
    int bdebug=voltage/1000;
    int adebug=(voltage/100)-(bdebug*10);
    while (bdebug>0) {
    digitalWrite(ledpin, HIGH);
    delay(1);
    digitalWrite(ledpin, LOW);
    delay(400);
    bdebug--;
    }
    delay(1000);
    while (adebug>0) {
    digitalWrite(ledpin, HIGH);
    delay(1);
    digitalWrite(ledpin, LOW);
    delay(400);
    adebug--;
    }

    delay(2000);
    debug=true;
    }


    if (runmode==1) { //charging

    if (voltage <= batmax) { // charge
    pinMode(batpin,OUTPUT);
    digitalWrite(batpin,HIGH);
    delay(1000);
    digitalWrite(ledpin,HIGH);
    delayMicroseconds(50);
    digitalWrite(ledpin,LOW);
    digitalWrite(batpin,LOW);
    pinMode(batpin,INPUT);
    delay(2);
    } else {
    runmode=3;
    }
    }

    if (runmode==2) { //flashing
    if (readVcc() > batmin) { // strobe

    if (blinks<250) { //stop measuring pot if over 250 blinks to lock blinkrate
    //read pot for sleeptimers
    blinks++;
    int pot = analogRead(potpin); //pot read value
    if (pot < 100) {itv=2;; sitv=0;}
    if (pot >= 100 && pot <=199) {itv=2;sitv=1;}
    if (pot >= 200 && pot <=299) {itv=2;sitv=2;}
    if (pot >= 300 && pot <=399) {itv=2;sitv=3;}
    if (pot >= 400 && pot <=499) {itv=3;sitv=1;}
    if (pot >= 500 && pot <=599) {itv=3;sitv=2;}
    if (pot >= 600 && pot <=699) {itv=3;sitv=3;}
    if (pot >= 700 && pot <=799) {itv=4;sitv=1;}...

    Read more »

View project log

Enjoy this project?

Share

Discussions

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates