LED circuit HELP for a Guerilla/Creative Marketing Campaign

Thread Starter

ZigZag

Joined Jul 22, 2010
264
I just remembered this: (I'm not sure how I forgot it because I use it every day).
The PIC (12F675) is similar but has analog capabilities and a few other tricks like an extra timer and the ability to use an external crystal for timing but still use the internal oscillator for code execution. The 508/509 always runs code at the external crystal frequency if a crystal is used.
None of these are really necessary - I just like making things complicated.

It turns a fairly bright LED on for 10 minutes when I turn my light off so I can find my way across my room. It then waits in low power mode for 8 hours and then flashes the LED in a doomed attempt to wake me up.
It is probably a good example of some of the things you are trying to do; it uses a high accuracy crystal to keep time and senses light. It also does software PWM dimming of the LEDs in the flashing mode. All in 225 program words (147 without the table for the sine wave flashing).
Rich (BB code):
    list    p=12F675
    radix    hex
    title "Timelapse"
        #include <p12f675.inc>
    __config _CP_OFF & _BODEN_OFF & _MCLRE_OFF & _PWRTE_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT


    cblock 0x20
    count
    count2
    delay16bitH    ;8 hours is 0x7080 seconds = 0x3840 2 second interrupts
    delay16bitL
    sinecount
    sinecurrent
    sinecopy
    ADRESHcopy
    W_TEMP
    STATUS_TEMP
    eetemp
    GPIOtemp
    mode            ;0 off 8 hours, 1 on until GP3 button, 
                    ;2 off until light off, 3 on 10 minutes
                    ;mode 3 at power on
    endc
    org 0x2100        ;initial values for timer H and L bytes (10 seconds)
    de 0x00,0x0a    
;    
;----------------------------------------------------------------------

    org    0x000
    goto init
    org 0x004    ;interrupt goes here
    MOVWF W_TEMP ; Copy W to TEMP register,
    SWAPF STATUS, W ; Swap status to be saved into W
    MOVWF STATUS_TEMP ; Save status to STATUS_TEMP register
    ;ISR : :
         ; Interrupt Service Routine

    ;test interrupt source
    btfss INTCON, GPIF        ;pin change, any activity change to mode 2
    goto TMRinterrupt
    movlw 0x02
    movwf mode
    bcf GPIO, 2                ;led off, wait for lights out
    goto endint
TMRinterrupt
    btfsc mode, 0
    goto mode1or3
    btfsc mode, 1
    goto mode2
    goto mode0
mode1or3
    btfss mode, 1
    goto mode1
;mode3 by elimination        ;light on for 10 minutes
    bsf GPIOtemp, 2                ;LED on
    movf GPIOtemp, W
    movwf GPIO
    movlw 0x01                ;count down for 10 minutes
    subwf delay16bitL, F
    btfss STATUS, C
    subwf delay16bitH, F
    subwf delay16bitH, W
    btfsc STATUS, C    
    goto endint    
    movlw 0x01
    subwf delay16bitL, W    ;w=1
    btfsc STATUS, C
    goto endint    
    bcf GPIO, 2                ;10 minutes up turn off LED
    clrf mode                ;mode 0, 8 hours off
    movlw 0x38                ;set delay = 8 hours = 0x3840
    movwf delay16bitH
    movlw 0x40                
    movwf delay16bitL
    goto endint
mode1
    goto endint                ;GPIO interrupt changes to mode 2
mode2                        ;wait with LED off until room light turned off
    bcf GPIOtemp, 2                ;LED off
    movf GPIOtemp, W
    movwf GPIO
    bsf ADCON0, 1            ;start conversion
    call delay1ms            ;way too long
    movlw 0x96                ;test brightness
    subwf ADRESH, W
    btfss STATUS, C
    goto endint
    incf mode, F
    movlw 01                ;10 minutes = 0x0258 sec = 0x012C x 2 sec ints
    movwf delay16bitH
    movlw 2C                
    movwf delay16bitL
    goto endint
mode0
;    incf mode, F
    bcf GPIOtemp, 2                ;LED off
    movf GPIOtemp, W
    movwf GPIO
    movlw 0x01                ;count down for 8 hours
    subwf delay16bitL, F
    btfss STATUS, C
    subwf delay16bitH, F
    subwf delay16bitH, W
    btfsc STATUS, C    
    goto endint    
    movlw 0x01
    subwf delay16bitL, W    ;w=1
    btfsc STATUS, C
    goto endint    
    incf mode, F            ; count finished, mode 1
    

    
endint
     ; should configure Bank as required
     ;
    SWAPF STATUS_TEMP,W     ; Swap nibbles in STATUS_TEMP register
    ; and place result into W
    MOVWF STATUS             ; Move W into STATUS register
    ; (sets bank to original state)
    SWAPF W_TEMP, F         ; Swap nibbles in W_TEMP and place result in W_TEMP
    SWAPF W_TEMP, W         ; Swap nibbles in W_TEMP and place result into W
;    CLRF TMR1L                 ; Clear Low byte, Ensures no rollover into TMR1H
;    movlw 0xC0                ;set up timer1
;    movwf TMR1H
;    clrf TMR1L
    clrf INTCON                ;clr interupts
    bsf INTCON,PEIE            ;timer1 interrupt on
    bsf INTCON, GPIE        ;gpio change interrupt on
    bcf PIR1, 0            ;clr tmr1 interrupt flag
    retfie
    
init    ;initialise stuff here
    movlw B'00000111'
    movwf CMCON                ;comparitors off    
    movlw B'00001111'
    movwf T1CON                ;enable timer1 external LP crystal 
    BSF STATUS, RP0 ; Bank 1
    movlw B'00010001'        
    movwf ANSEL                ;AN0 analog and Fosc/8 for 4MHz
    bsf PIE1, 0                ;timer1 int enabled
;    BSF STATUS, RP0 ; Bank 1    
    clrf   OPTION_REG      ; 
     movlw B'00001000'
    movwf IOC                ; interrupt on change pin GP3    
    bcf     STATUS, RP0    ; bank 0    
    movlw   B'01001000'     ; enable timer 1 interrupt and gpio change (not GIE yet)
    movwf   INTCON          ;  
    CLRF TMR1L                 ; Clear Low byte, Ensures no rollover into TMR1H
    clrf TMR1H
    movlw 0x02
    movwf mode
    CLRF GPIO                 ; Initialize GPIO by
                            ; clearing output
                            ; data latches
    BSF STATUS, RP0         ; Select Bank 1
    MOVLW B'00100001'         ; Value used to
                            ; initialize data
                            ; direction
    MOVWF TRISIO             ; Set GP<4-1> as output, GP0 input
    BCF STATUS, RP0         ;bank 0
    movlw B'00000001'
    movwf ADCON0            ;left justified, A/D on, AN0, ref VDD
    movlw D'75'
    movwf sinecount
    bsf INTCON, GIE            ;enable interrupts, then sleep

sleeploop
    sleep
    nop
    movlw 1
    subwf mode, W
    btfss STATUS, Z    
    goto sleeploop            ;if mode 1 goto main

main
;    bsf ADCON0, 1            ;start conversion
;    call delay1ms            ;way too long
    movf sinecurrent, W
    movwf sinecopy
    bsf GPIOtemp, 2                ;LED on
    movf GPIOtemp, W
    movwf GPIO
LEDon    
    decfsz sinecopy, F
    goto LEDon
    movf sinecurrent, W
    movwf sinecopy
    bcf GPIOtemp, 2                ;LED off
    movf GPIOtemp, W
    movwf GPIO
LEDoff    
    incfsz sinecopy, F
    goto LEDoff
    decf sinecount, W
    btfsc STATUS, Z
    movlw D'75'                    ;reset if one (wastes 1 space in lookup)
    movwf sinecount
    movf sinecount, W
    call sinetable
    movwf sinecurrent
    movlw 1
    subwf mode, W
    btfss STATUS, Z    
    goto sleeploop            ;if not mode 1 goto sleeploop
    goto main







sinetable
    addwf PCL, F
    nop                            ;never going to happen
    retlw D'128'
    retlw D'139'
    retlw D'149'
    retlw D'160'
    retlw D'170'
    retlw D'180'
    retlw D'189'
    retlw D'198'
    retlw D'207'
    retlw D'215'
    retlw D'222'
    retlw D'229'
    retlw D'235'
    retlw D'241'
    retlw D'245'
    retlw D'249'
    retlw D'252'
    retlw D'254'
    retlw D'255'
    retlw D'255'
    retlw D'254'
    retlw D'253'
    retlw D'250'
    retlw D'247'
    retlw D'243'
    retlw D'238'
    retlw D'232'
    retlw D'226'
    retlw D'219'
    retlw D'211'
    retlw D'203'
    retlw D'194'
    retlw D'184'
    retlw D'175'
    retlw D'165'
    retlw D'154'
    retlw D'144'
    retlw D'133'
    retlw D'123'
    retlw D'112'
    retlw D'102'
    retlw D'91'
    retlw D'81'
    retlw D'72'
    retlw D'62'
    retlw D'53'
    retlw D'45'
    retlw D'37'
    retlw D'30'
    retlw D'24'
    retlw D'18'
    retlw D'13'
    retlw D'9'
    retlw D'6'
    retlw D'3'
    retlw D'2'
    retlw D'1'
    retlw D'1'
    retlw D'2'
    retlw D'4'
    retlw D'7'
    retlw D'11'
    retlw D'15'
    retlw D'21'
    retlw D'27'
    retlw D'34'
    retlw D'41'
    retlw D'49'
    retlw D'58'
    retlw D'67'
    retlw D'76'
    retlw D'86'
    retlw D'96'
    retlw D'107'
    retlw D'117'
    retlw D'128'



delay1ms:    ;
    movlw 0xFF
    movwf count
loop1ms    
    nop
    decfsz count,F
    goto loop1ms
    return ;delay20ms


        


    end

Wow! Thank you big time! It is the first circuit that I've seen on this thread! w00t!

What does L324 do?

I've read through this, but I can not understand it: http://www.national.com/mpf/LM/LMV324.html#Overview

oh and what language is that code written in?
 

Markd77

Joined Sep 7, 2009
2,806
The LM324 is just an op amp to buffer and slightly amplify the voltage from the mid point of the voltage divider formed by the variable resistor and the light dependant resistor. The analog input pins don't work well with a high resistance voltage divider on its own.
The left side of the 324 is a non inverting amplifier with a gain of 2 and the right side provides half of the supply voltage to the non inverting amplifier.
If high gain (open loop) was used for the non inverting amplifier it could be used with a digital input pin.
http://en.wikipedia.org/wiki/Op_amp
 
Last edited:

Thread Starter

ZigZag

Joined Jul 22, 2010
264
I know you guys are going to laugh at me, but this is my first circuit ever!


  • 8 slow flashing LEDs

LED SPECS:
LED Size: 5mm
LED Color: water clear
Voltage: 3.2-3.6V
Current: 20mA
View Angle: ~ 25degree
Luminous Intensity: 5000-5500mcd

http://www.youtube.com/watch?v=epoVPB6wOuo

  • 4 CR2450 lithium coincell batteries
"CR2450/5029LC 610–620mAh Portable devices requiring high current (30 mA) and long shelf life (up to 10 years)" - http://en.wikipedia.org/wiki/List_of_battery_sizes#Lithium_coin.2Fbutton_cells



Here is how I calculated power requirements:


  • 8pm-3am=7hours/day for 14 days (98 hours)
To calculate required power I have multiplied amount of "on" hours by the LED draw/hour and then by the amount of LEDs: (98*20*8=15680mAh)

Then I assumed that the battery capacity will be 500mAh (not 610-620mAh as per wiki article) to account for any other draw that I may not be aware of (resistors, caps, timer circuits, etc...)

I have divided power required to power 8 LEDs for 7 hours per day for 14 days by the capacity of the coincell battery (15680/500=31.4)

While doing the calculations for this post I have noticed that my schematic only accounted for the power draw of one LED (not 8) and I teared up a bit when I saw that I will need whooping 32 CR2450 batteries for each circuit and decided not to rewrite it.




  • This circuit does not have the resistance values for the R1,R2,R3,R4
  • This circuit does not include any time-keeping facilities or triggers
  • This circuit does not include capacitors that were recommended
  • This circuit does not include a buck-boost controller
  • This circuit is probably incorrect,unrealistic, and with 32 batteries, it is also dysfunctional :(
^^^====All of the above is because I do not know how to implement much of anything. I have spent lots of time in the past few days trying to understand some core aspects of electricity and I've had pretty good success. If you see any wrong terminology that I may have used in the post - please let me know about it and yes, please nitpick as much as possible. I would prefer to use the correct terminology from the physics point of view while describing my circuits.
 

Attachments

Thread Starter

ZigZag

Joined Jul 22, 2010
264
At this point I desperately need good suggestions on power. I do not know if I calculated power correctly, but if I did, the 32 coincell battery requirement will be considered a relative sign of failiure for Project_One.
 
Last edited:

retched

Joined Dec 5, 2009
5,207
Yeah.. It makes no sense to use "cells" if you need more than 1 or 2.

A battery, by definition, is a group of cells.

So if you need more than 1 or 2 cells worth of current, then you should be using a battery.

A 16 ah battery is not going to be cheap in a small package.
 

Thread Starter

ZigZag

Joined Jul 22, 2010
264
Yeah.. It makes no sense to use "cells" if you need more than 1 or 2.

A battery, by definition, is a group of cells.

So if you need more than 1 or 2 cells worth of current, then you should be using a battery.

A 16 ah battery is not going to be cheap in a small package.

Alright, the only other options I can see would include cutting the time to 2 7-hour nights or stitching in a pv cell. Neither option is exciting to me.




If I would go the cheaper way and go with the 2-day run:


so we would be looking at... 14*20*8/500=4.8 so about five 3V cells @ 500 mAh

retched, what [battery] do you suggest that I replace the five 3v lithium coin cells with?



I just found out that I can score chipped pv cells pretty cheaply. Will I need a charge controller to recharge 3 AAA or AA cells that is something beside a simple voltage regulator? What specifications will I need to charge these 3 cells so they can run for at least 7 hours/night?
 
Last edited:

marshallf3

Joined Jul 26, 2010
2,358
http://www.goldmine-elec.com/ recently received some new scratch/dent PV cells and other places on the 'net abound with them if you look.

I also woudn't expect to drive them at full power, most LEDs put out pretty close to the same amount of perceivable light at greatly reduced driving currents.
 

Thread Starter

ZigZag

Joined Jul 22, 2010
264
Also, now that I can get the pv cells fairly cheaply, the only thing that is going to cause me headaches are the prices of rechargeable AAA or AA cells. I can get the CR2450s for about $0.25USD and I don't think I can get the AA or AAA anywhere close to that. The only upside with the solar cell design is that they will last "forever" not just 14 days. So at a fairly large expense (potentially as much as 2x the cost) I can make these signs stay on for as long as they would. I'm looking into the prices for them now. Oh also the battery holders or spot-welding the tabs cost.

Approximate price for 1 AAA cell (1000mAh) + batt holder ~$1.5 USD
Approximate price for 1 AA cell (2600mAh) + batt holder ~$1.5 USD

Welding the tabs may reduce $1.5 to $1 USD, but if I have to use 3 cells that is still $3. I guess this is not AS bad as 32 coin cells at whooping $17 USD!

I think rechargeable cells + battery holders + pv cell + additional magnets would come up to about $4-$4.50 for a sign that will stay on "forever".


Maybe going with a cell phone battery instead of AA or AAA would be better? They are slimmer....


Placement of a PV cell will be challenging. If I use 3 AA, what specs should the charging PV cell have? If I use 3 AAA, what specs should the charging PV cell have?


On the other hand, if I go with coin cell batteries & two 7-hour nights of operation I'll be looking at roughly $2.20 USD.


In other words, forever will cost me extra ~$2 on top of keeping the sign up for two days.



What do you guys think?
 
Last edited:

marshallf3

Joined Jul 26, 2010
2,358
Maybe going with a cell phone battery instead of AA or AAA would be better? They are slimmer.
Quite a few inexpensive replacement cordless phone batteries on eBay, matter of fact a lot of cheap NiCd cells too.
Remember, we're not talking cell phone batteries here but those for home cordless phones.

I recently bought a 3.6V 800 mA/hr replacement NiMH pack, encased, with leads, for something like $1.68 and free shipping.

Are you in or near a medium-large city? Home Depot has a "Recycle bin" that builders toss their failed electric drill batteries into. Usually the nearby cashier could care less if you grabbed a handful and since they came from a builder chances are you'l find a dozen or two of the exact same pack.

If you take these apart you'll usually find that only one or two of the cells has failed, the rest still being perfectly usable.
 

retched

Joined Dec 5, 2009
5,207
If you take these apart you'll usually find that only one or two of the cells has failed, the rest still being perfectly usable.
Thats a good idea.

Thats a real good idea.

Very true. The cordless tool batteries have a cap inside them that can also fail or be knocked loose.

Also, sometimes, the battery tabs come off. This has happened to me more than a few times.

My 18v dewalt hammer drill/driver has taken a fall off a ladder a few times. The bit is bent, and sometimes the battery needs some love to get working again.

Many contractors would chuck it in the recycle box before opening the battery up.

That could be a great source for your power.
 

Thread Starter

ZigZag

Joined Jul 22, 2010
264
Great stuff guys!

Actually, I got a bunch of HD within 15 miles of me...like 6 of them. I do not know how they would react to me emptying those out day after day or week after week. I need so make at least one thousand of Project_One and about the same of Project_Two circuits. I think it would take daily trips to the local HDs to be able to get enough of them after few months. I could talk to the managers at HD and see if they would let me empty their bins so they don't have to, but people at local HD aren't very friendly - usually overworked and bitter in my experience. Once there was a guy asking for a small, foot-sized scrap of wood (they had TONS of scrap wood!) and they tolled him no, and then they laughed at and made fun of him for 5 minutes or so. :( I'd really hate to get on their bad side. I will talk to a manager though and maybe at least one of the 6 DHs lets me dumpster dive.

Kicking the ball around with you guys gave me a killer idea for a no-effort (very little) idea of where to get a trickle flow of used battery packs: I have a manager friend at Interstate Batteries and they regularly replace dewalt and other battery packs at a fraction of a cost of a new one. I can just ask him to save me the batteries and maybe even see if I can get them from the 3 other interstate locations within driving distance from me. I can pick them up every week. Tremendous ideas guys! :cool:

Thanks!


P.S. Sounds like retched is going to hit up HD too ;)
 

marshallf3

Joined Jul 26, 2010
2,358
but people at local HD aren't very friendly
I asked a manager once, got some lecture about store liability. Ever since then if I need some I just grab them on the way out and go on my way. If the cashier looks stangely at me I just say I've asked and they've never had a problem with it.
 

Thread Starter

ZigZag

Joined Jul 22, 2010
264
I asked a manager once, got some lecture about store liability. Ever since then if I need some I just grab them on the way out and go on my way. If the cashier looks stangely at me I just say I've asked and they've never had a problem with it.

Alright, sounds like what I'm going to try in a few hours.
 

tom66

Joined May 9, 2009
2,595
I'm not sure if you're open to it, but what about coin cells? I've found several people on eBay selling packs of anywhere from 3 to 12 lithium coin cells for less £5 a pack. They're usually from reputable brands like Panasonic and Duracell.

EDIT: I just found someone selling 100(!) for £10.50. I'm not sure how long these will last, but you could afford to put in 2 or 3 per device with low cost.
 
Last edited:

Wendy

Joined Mar 24, 2008
23,421
The lifespan of those batteries is going to be short, very short. I did some experiments with my several Long Duration LED Experiments in my 555 projects. 2X "D" cells will have a decent lifespan if the design aims for it.
 

tom66

Joined May 9, 2009
2,595
It depends how many LEDs are to be used.

One coin cell will power an LED for about 3 to 4 days continuously until output drops to around 60%. Three coin cells, in parallel, will run an LED for up to 12 days (and so on.) If the LEDs are only to come on at certain times, battery life is increased. I haven't been following this post too much so I don't know all the requirements, it's just an idea.

These must be lithium coin cells - the alkaline ones simply don't have enough juice.
 

Thread Starter

ZigZag

Joined Jul 22, 2010
264
I'm not sure if you're open to it, but what about coin cells? I've found several people on eBay selling packs of anywhere from 3 to 12 lithium coin cells for less £5 a pack. They're usually from reputable brands like Panasonic and Duracell.

EDIT: I just found someone selling 100(!) for £10.50. I'm not sure how long these will last, but you could afford to put in 2 or 3 per device with low cost.
Coin cells (cr2450) are only about 600mAh. this makes them inadequate for long-duration application.
 
Top