Hi All,
Its Xmas so I thought I would share this simple project with you.
It is a very simple Xmas lights controller, designed to be retrofitted into a cheap battery Xmas lights system from your favourite internet shop or local junk store.
The code should run on just about any pic/avr micro. No special peripheral hardware is need.
My h/w consists of a cheap battery Xmas light string that my wife acquired for $3 at a local junk store.
The electronic components are nothing more than an 8 pin PIC (12f617), a mosfet and a few resistors.
The additional components are just soldered together and stuffed into some free space in the battery box for the Xmas lights.
It just brittens up an otherwise dull Xmas light string. Previously the lights were just on or off. Now they illuminate to a random array of patterns.
;ChipSettings#chip 12F617,8#config OSC=INTOSCIO;Defines(Constants)#define Lights PortA.0#define PWM_Out1 PortA.0#define PWMFrequency 10;VariablesDimStateAsbyteDimVersionAsstring*4DimcyclecountAsbyteDimdutyAsByteDimEndcountAsbyteDimFlashontimeAswordDimFlashofftimeAswordDimFlickerAsByte'Xmas Lights'Single output drive (GP0) that controls LED Xmas light string'Use a MOSFET as the drive component for the LED string 'Runs on 12F617 or similar'Uses s/w PWM to keep things simple and portable.'Designed to be a retrofit for simple $3 battery Xmas lights that you find on ebayVersion="1E"'Uses PWM to control LEDs'Different light sequences and variable light levels to add interest.'1B - 5/1/19. More variety of light control added.'1D - 17/12/22. Added candle simulation option.'1E - 18/12/22. Improved randomised candle flicker routine.'************'Start up delay for PICkit2Wait200ms'Set up I/O pins.DirGPIO.0OutDirGPIO.1OutDirGPIO.2OutDirGPIO.3InDirGPIO.4OutDirGPIO.5Out'Set lights to offSetLightsOff'set up timer as seed for random number generator.InitTimer0Osc,PS0_1/2doForever'Get a random cycle length.Randomize(Timer0)cyclecount=Random/8'Change duty cycle to steadily increase brightnessForduty=10To250step10'slowly get brighterPWMout1,duty,cyclecountnextSetLightsOnWait200ms'change duty cycle to progressively dim.Forduty=250To10step-10'slowly dimPWMout1,duty,cyclecountnextSetLightsOffWait200ms'Now do some random flashingEndcount=Random/32Flashontime=(Random/16)*100Flashofftime=(Random/16)*100ForFlashcount=0ToEndcountSetLightsOnWaitFlashontimemsSetLightsOffWaitFlashofftimemsNext'now do some candle flicker simulationRepeat150Flicker=Randomduty=(Flicker&0b11100000)|128cyclecount=(Flicker&0b00111000)+7PWMOut1,duty,cyclecountendrepeatloop
Feel free to use and modify as you feel fit.
Have fun.
Peter.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ho Ho ho. Xmas is coming again.
I have updated my Xmas lights code from a few years back.
Essentially the same functionality but this time with fewer components.
The entire project is based around just a single PIC micro.
I used a PIC12F617, because they are small cheap and I had a few lying around.
The new design does away with the need for an external driver transistor/mosfet.
The code uses a slightly modified version of the standard GCB software PWM routines to enable the use of 5 outpit pins connected in parallel to provide sufficient drive for the LED string.
I just purchased a cheap LED fairy light string from the local $2 shop.
Here are the pin connections for the PIC chip
Pin1 - +ve (Vdd) power direct from the battery (in my case it was only 3V)
Pin2, Pin3, Pin5, Pin6 & Pin7 all connected together and provide the low side drive for the LED string
Pin4 - not connected
Pin8 - -ve (Vss) power via the existing switch in the battery box.
There was just enough spare space in my battery box to tuck away the single IC.
;ChipSettings#chip 12F617,8#config OSC=INTOSCIO;Defines(Constants)'#define PWMDelay 10 'waittimeinms;VariablesDimStateAsbyteDimVersionAsstring*4DimcyclecountAsbyteDimdutyAsByteDimEndcountAsbyteDimFlashontimeAswordDimFlashofftimeAswordDimFlickerAsByteDimhighTimeAsByteDimcountAswordDimcycleCountAsword'Xmas Lights'Single output drive, with all output pins tied together for additional current drive, that controls LED Xmas light string'Direct connect low level drive for lights'Runs on 12F617 or similar'Uses special s/w PWM routine to keep things simple and portable.'Designed to be a retrofit for simple $3 battery Xmas lights that you find on ebayVersion="2A"'Uses PWM to control LEDs'Different light sequences and variable light levels to add interest.'1B - 5/1/19. More variety of light control added.'1D - 17/12/22. Added candle simulation option.'1E - 18/12/22. Improved randomised candle flicker routine.'2A - 30/11/24. Reworked to drive 5 output pins simultaneously (GPIO 0 - 2, GPIO 4 - 5)'************'Start up delay for PICkit2Wait200ms'Set up I/O pins.'pic12f617 only has 6 pins available (8 pin device). GPIO3 (pin4) can only be set as an input.DirGPIO.0OutDirGPIO.1OutDirGPIO.2OutDirGPIO.3InDirGPIO.4OutDirGPIO.5Out'Initialise lights to off'Output pins set high as active lowGPIO=255'Special PWM routine to drive all pins on Port A. Active low outputs.SubMegaPWMOut(SoftPWMDuty,SoftPWMCycles)' Inputs: ' - duty: Duty cycle for all pins (0-255)' - cycles: Number of cycles to generate' Generate the specified number of PWM cycles'Software PWM'Duty is /255, Dur is msForPWMDur=1toSoftPWMCyclesForDOPWM=1to255ifSoftPWMDuty>DOPWMthen'set lights on (active low)GPIO=0' Set all bits of PORTA lowElse'set lights offGPIO=255endif#IFDEF PWM_DelayWaitPWM_Delay#ENDIFnextnextendsub'set up timer as seed for random number generator.InitTimer0Osc,PS0_1/2' now kick off the endless routinedoForever'Get a random cycle length.Randomize(Timer0)cyclecount=Random/8'Change duty cycle to steadily increase brightnessForduty=10To250step10'slowly get brighterMegaPWMoutduty,cyclecountnextGPIO=0Wait200ms'change duty cycle to progressively dim.Forduty=250To10step-10'slowly dimMegaPWMoutduty,cyclecountnextGPIO=0Wait200ms'Now do some random flashingEndcount=Random/32Flashontime=(Random/16)*100Flashofftime=(Random/16)*100ForFlashcount=0ToEndcountGPIO=0WaitFlashontimemsGPIO=255WaitFlashofftimemsNext'now do some candle flicker simulationRepeat150Flicker=Randomduty=(Flicker&0b11100000)|128cyclecount=(Flicker&0b00111000)+7MegaPWMOutduty,cyclecountendrepeatloop
Enjoy
Peter.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have attached an image that shows the little 8pin PIC stuffed inside the battery box.
I have also attached a short video to show the light effects. I think I managed to capture the candle flickering effect, but not sure how well it will come up in the video. Unfortunately, these cheap battery lights just have all the leds connected in series, so no real opportunity to to drive multiple outputs. The idea could easily be adapted to lights with multiple circuits.
Peter.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ho Ho ho. Xmas is coming again.
I have updated my Xmas lights code from a few years back.
Essentially the same functionality but this time with fewer components.
The entire project is based around just a single PIC micro.
I used a PIC12F617, because they are small cheap and I had a few lying around.
The new design does away with the need for an external driver transistor/mosfet.
The code uses a slightly modified version of the standard GCB software PWM routines to enable the use of 5 outpit pins connected in parallel to provide sufficient drive for the LED string.
I just purchased a cheap LED fairy light string from the local $2 shop.
Here are the pin connections for the PIC chip
Pin1 - +ve (Vdd) power direct from the battery (in my case it was only 3V)
Pin2, Pin3, Pin5, Pin6 & Pin7 all connected together and provide the low side drive for the LED string
Pin4 - not connected
Pin8 - -ve (Vss) power via the existing switch in the battery box.
There was just enough spare space in my battery box to tuck away the single IC.
;ChipSettings#chip 12F617,8#config OSC=INTOSCIO;Defines(Constants)'#define PWMDelay 10 'waittimeinms;VariablesDimStateAsbyteDimVersionAsstring*4DimcyclecountAsbyteDimdutyAsByteDimEndcountAsbyteDimFlashontimeAswordDimFlashofftimeAswordDimFlickerAsByteDimhighTimeAsByteDimcountAswordDimcycleCountAsword'Xmas Lights'Single output drive, with all output pins tied together for additional current drive, that controls LED Xmas light string'Direct connect low level drive for lights'Runs on 12F617 or similar'Uses special s/w PWM routine to keep things simple and portable.'Designed to be a retrofit for simple $3 battery Xmas lights that you find on ebayVersion="2A"'Uses PWM to control LEDs'Different light sequences and variable light levels to add interest.'1B - 5/1/19. More variety of light control added.'1D - 17/12/22. Added candle simulation option.'1E - 18/12/22. Improved randomised candle flicker routine.'2A - 30/11/24. Reworked to drive 5 output pins simultaneously (GPIO 0 - 2, GPIO 4 - 5)'************'Start up delay for PICkit2Wait200ms'Set up I/O pins.'pic12f617 only has 6 pins available (8 pin device). GPIO3 (pin4) can only be set as an input.DirGPIO.0OutDirGPIO.1OutDirGPIO.2OutDirGPIO.3InDirGPIO.4OutDirGPIO.5Out'Initialise lights to off'Output pins set high as active lowGPIO=255'Special PWM routine to drive all pins on Port A. Active low outputs.SubMegaPWMOut(SoftPWMDuty,SoftPWMCycles)' Inputs: ' - duty: Duty cycle for all pins (0-255)' - cycles: Number of cycles to generate' Generate the specified number of PWM cycles'Software PWM'Duty is /255, Dur is msForPWMDur=1toSoftPWMCyclesForDOPWM=1to255ifSoftPWMDuty>DOPWMthen'set lights on (active low)GPIO=0' Set all bits of PORTA lowElse'set lights offGPIO=255endif#IFDEF PWM_DelayWaitPWM_Delay#ENDIFnextnextendsub'set up timer as seed for random number generator.InitTimer0Osc,PS0_1/2' now kick off the endless routinedoForever'Get a random cycle length.Randomize(Timer0)cyclecount=Random/8'Change duty cycle to steadily increase brightnessForduty=10To250step10'slowly get brighterMegaPWMoutduty,cyclecountnextGPIO=0Wait200ms'change duty cycle to progressively dim.Forduty=250To10step-10'slowly dimMegaPWMoutduty,cyclecountnextGPIO=0Wait200ms'Now do some random flashingEndcount=Random/32Flashontime=(Random/16)*100Flashofftime=(Random/16)*100ForFlashcount=0ToEndcountGPIO=0WaitFlashontimemsGPIO=255WaitFlashofftimemsNext'now do some candle flicker simulationRepeat150Flicker=Randomduty=(Flicker&0b11100000)|128cyclecount=(Flicker&0b00111000)+7MegaPWMOutduty,cyclecountendrepeatloop
Ho Ho ho. Xmas is coming again.
I have updated my Xmas lights code from a few years back.
Essentially the same functionality but this time with fewer components.
The entire project is based around just a single PIC micro.
I used a PIC12F617, because they are small cheap and I had a few lying around.
The new design does away with the need for an external driver transistor/mosfet.
The code uses a slightly modified version of the standard GCB software PWM routines to enable the use of 5 outpit pins connected in parallel to provide sufficient drive for the LED string.
I just purchased a cheap LED fairy light string from the local $2 shop.
Here are the pin connections for the PIC chip
Pin1 - +ve (Vdd) power direct from the battery (in my case it was only 3V)
Pin2, Pin3, Pin5, Pin6 & Pin7 all connected together and provide the low side drive for the LED string
Pin4 - not connected
Pin8 - -ve (Vss) power via the existing switch in the battery box.
There was just enough spare space in my battery box to tuck away the single IC.
;ChipSettings#chip 12F617,8#config OSC=INTOSCIO;Defines(Constants)'#define PWMDelay 10 'waittimeinms;VariablesDimStateAsbyteDimVersionAsstring*4DimcyclecountAsbyteDimdutyAsByteDimEndcountAsbyteDimFlashontimeAswordDimFlashofftimeAswordDimFlickerAsByteDimhighTimeAsByteDimcountAswordDimcycleCountAsword'Xmas Lights'Single output drive, with all output pins tied together for additional current drive, that controls LED Xmas light string'Direct connect low level drive for lights'Runs on 12F617 or similar'Uses special s/w PWM routine to keep things simple and portable.'Designed to be a retrofit for simple $3 battery Xmas lights that you find on ebayVersion="2A"'Uses PWM to control LEDs'Different light sequences and variable light levels to add interest.'1B - 5/1/19. More variety of light control added.'1D - 17/12/22. Added candle simulation option.'1E - 18/12/22. Improved randomised candle flicker routine.'2A - 30/11/24. Reworked to drive 5 output pins simultaneously (GPIO 0 - 2, GPIO 4 - 5)'************'Start up delay for PICkit2Wait200ms'Set up I/O pins.'pic12f617 only has 6 pins available (8 pin device). GPIO3 (pin4) can only be set as an input.DirGPIO.0OutDirGPIO.1OutDirGPIO.2OutDirGPIO.3InDirGPIO.4OutDirGPIO.5Out'Initialise lights to off'Output pins set high as active lowGPIO=255'Special PWM routine to drive all pins on Port A. Active low outputs.SubMegaPWMOut(SoftPWMDuty,SoftPWMCycles)' Inputs: ' - duty: Duty cycle for all pins (0-255)' - cycles: Number of cycles to generate' Generate the specified number of PWM cycles'Software PWM'Duty is /255, Dur is msForPWMDur=1toSoftPWMCyclesForDOPWM=1to255ifSoftPWMDuty>DOPWMthen'set lights on (active low)GPIO=0' Set all bits of PORTA lowElse'set lights offGPIO=255endif#IFDEF PWM_DelayWaitPWM_Delay#ENDIFnextnextendsub'set up timer as seed for random number generator.InitTimer0Osc,PS0_1/2' now kick off the endless routinedoForever'Get a random cycle length.Randomize(Timer0)cyclecount=Random/8'Change duty cycle to steadily increase brightnessForduty=10To250step10'slowly get brighterMegaPWMoutduty,cyclecountnextGPIO=0Wait200ms'change duty cycle to progressively dim.Forduty=250To10step-10'slowly dimMegaPWMoutduty,cyclecountnextGPIO=0Wait200ms'Now do some random flashingEndcount=Random/32Flashontime=(Random/16)*100Flashofftime=(Random/16)*100ForFlashcount=0ToEndcountGPIO=0WaitFlashontimemsGPIO=255WaitFlashofftimemsNext'now do some candle flicker simulationRepeat150Flicker=Randomduty=(Flicker&0b11100000)|128cyclecount=(Flicker&0b00111000)+7MegaPWMOutduty,cyclecountendrepeatloop
Hi All,
Its Xmas so I thought I would share this simple project with you.
It is a very simple Xmas lights controller, designed to be retrofitted into a cheap battery Xmas lights system from your favourite internet shop or local junk store.
The code should run on just about any pic/avr micro. No special peripheral hardware is need.
My h/w consists of a cheap battery Xmas light string that my wife acquired for $3 at a local junk store.
The electronic components are nothing more than an 8 pin PIC (12f617), a mosfet and a few resistors.
The additional components are just soldered together and stuffed into some free space in the battery box for the Xmas lights.
It just brittens up an otherwise dull Xmas light string. Previously the lights were just on or off. Now they illuminate to a random array of patterns.
Feel free to use and modify as you feel fit.
Have fun.
Peter.
@pwstone How cool! Thank you for the great idea.
Ho Ho ho. Xmas is coming again.
I have updated my Xmas lights code from a few years back.
Essentially the same functionality but this time with fewer components.
The entire project is based around just a single PIC micro.
I used a PIC12F617, because they are small cheap and I had a few lying around.
The new design does away with the need for an external driver transistor/mosfet.
The code uses a slightly modified version of the standard GCB software PWM routines to enable the use of 5 outpit pins connected in parallel to provide sufficient drive for the LED string.
I just purchased a cheap LED fairy light string from the local $2 shop.
Here are the pin connections for the PIC chip
Pin1 - +ve (Vdd) power direct from the battery (in my case it was only 3V)
Pin2, Pin3, Pin5, Pin6 & Pin7 all connected together and provide the low side drive for the LED string
Pin4 - not connected
Pin8 - -ve (Vss) power via the existing switch in the battery box.
There was just enough spare space in my battery box to tuck away the single IC.
Enjoy
Peter.
Video!! Then we can we see the effect.
I have attached an image that shows the little 8pin PIC stuffed inside the battery box.
I have also attached a short video to show the light effects. I think I managed to capture the candle flickering effect, but not sure how well it will come up in the video. Unfortunately, these cheap battery lights just have all the leds connected in series, so no real opportunity to to drive multiple outputs. The idea could easily be adapted to lights with multiple circuits.
Peter.
Ho Ho ho. Xmas is coming again.
I have updated my Xmas lights code from a few years back.
Essentially the same functionality but this time with fewer components.
The entire project is based around just a single PIC micro.
I used a PIC12F617, because they are small cheap and I had a few lying around.
The new design does away with the need for an external driver transistor/mosfet.
The code uses a slightly modified version of the standard GCB software PWM routines to enable the use of 5 outpit pins connected in parallel to provide sufficient drive for the LED string.
I just purchased a cheap LED fairy light string from the local $2 shop.
Here are the pin connections for the PIC chip
Pin1 - +ve (Vdd) power direct from the battery (in my case it was only 3V)
Pin2, Pin3, Pin5, Pin6 & Pin7 all connected together and provide the low side drive for the LED string
Pin4 - not connected
Pin8 - -ve (Vss) power via the existing switch in the battery box.
There was just enough spare space in my battery box to tuck away the single IC.
Enjoy
Peter.
Ho Ho ho. Xmas is coming again.
I have updated my Xmas lights code from a few years back.
Essentially the same functionality but this time with fewer components.
The entire project is based around just a single PIC micro.
I used a PIC12F617, because they are small cheap and I had a few lying around.
The new design does away with the need for an external driver transistor/mosfet.
The code uses a slightly modified version of the standard GCB software PWM routines to enable the use of 5 outpit pins connected in parallel to provide sufficient drive for the LED string.
I just purchased a cheap LED fairy light string from the local $2 shop.
Here are the pin connections for the PIC chip
Pin1 - +ve (Vdd) power direct from the battery (in my case it was only 3V)
Pin2, Pin3, Pin5, Pin6 & Pin7 all connected together and provide the low side drive for the LED string
Pin4 - not connected
Pin8 - -ve (Vss) power via the existing switch in the battery box.
There was just enough spare space in my battery box to tuck away the single IC.
Enjoy
Peter.