Use a potentiometer to control speed of flickering light

jensmith25

Senior Member
Hi all,

I've had an enquiry as to the possibility of controlling the speed of flicker using a potentiometer for dolls house fireplaces / candles. They've seen an available unit (probably from China) and asked if I can do something similar.

What I'm using:

PCB: 18M2 project board / high power project board
10k analogue potentiometer on C.0
4.5v

I have created a welding effect simulation similar to this chap's http://www.picaxeforum.co.uk/showthread.php?27514-08M2-welder-flicker-simulation&highlight=welding+simulation
Code snippet:
Code:
#picaxe 08M2 ' specify processor

w0=0
w1=0
' ============= Begin Main Program =============
do
random w0
let w1 = b0*21
tune 3, 2,($27,$67,$67,$22,$22,$24,$64,$64,$20,$20,$25,$65 ,$65,$20,$20,$26,$66)
pause w1

etc etc
which uses the tune command and is very effective but in this case I need it to be more of a random flicker and without the additional LED and for the 18M2.

I've also seen this option which flashes an LED but this is a flash rather than a random flicker:
Code:
main:
  for b1 = 1 to 5
    call flash
  next
  call delay
  goto main

flash:
  high C.1
  low C.4
  readadc C.2, b0
  let w1 = 5 * b0
  pause w1
  low C.1
  high C.4
  readadc C.2, b0
  let w1 = 5 * b0
  pause w1
  return

delay:
  low C.1
  low C.4
  pause 2000
  return
Is it even possible to alter the speed of flicker using a potentiometer?

I've tried using a flickering LED but it needs a certain current to light and using the potentiometer seems to have no effect. It stops flickering when turned low.

Can you:

1) Use a potentiometer in combination with the tune command to alter the speed of the flicker?
or is there another way of doing it?

I considered whether I could use the tune command and just choose different tunes so a slow one to start, getting faster and use the
Code:
main: readadc 0,b1 ‘ read value on pin0 into variable b1
if b1<75 then light1 ‘ if b1 is less than 75 then light 1
if b1<175 then light2 ‘ if b1 is less than 175 then light 2
goto light3 ‘ if b1 is greater than 175 then light 3
idea to call the different tunes but I don't know how well this would work.

I'm still a newbie at Picaxe coding so please bear with me.

Thanks,

Jennifer,
 

premelec

Senior Member
probably could work using a combination of random and pause - pause values being determined by READADC from potentiometer. In my experience it's hard to get the right effect without a lot of trial and error till it 'looks good'. Having two LEDs - or more - works better. I haven't tried TUNE ever... but whatever works!

Note that changing PWMOUT DUTY can give you changes in intensity... and occasional PULSOUT crackle... BTW I have used some of the flicker LEDs - as you say frequency not variable by changing voltage - however two running in parallel won't stay synchronized for long and so give different effect... What's your proposed cost per unit budget? [How fancy are the doll houses.... add smoke too? ;-0 ] Some commercial flicker lights I got years ago just used a multi flipflop IC [4060?] with resistors to two LEDs i think.. rate on these could be varied by changing their timing capacitor...
 
Last edited:

jensmith25

Senior Member
Thanks premelec. It's a pretty specific brief, ie they want it to be like something they've already seen which can regulate brightness on one channel and speed on the other and it's for individual lights so I can't combine which is what I would normally do.

I've sorted the brightness one using pwm but just not sure how to handle the speed one on a flickering LED. Doing it with a flashing LED is no problem.
They specifically want the ability to control via a potentiometer so using anything else is out unfortunately.

Budget not specified. I said I would look into whether I could do it before going further but don't want to waste a lot of time on it.
 

premelec

Senior Member
Ok - have you seen the unit you want to emulate? it's a pretty broad field... you could regulate the speed of PWM variation if that's what you need - Use input value from pot - use that value to influence the variation in the PWM on the appropriate channel. This requires a pot determined variable in the code which influences the change of PWM values.
Of course I'm not sure that's just what you are trying to do... ;-0
 

sghioto

Senior Member
jensmith25 try this code:

Code:
main: random w0 
                 pwmout B.3,249,w0
                 readadc C.0,b2 
                 pause b2
                 goto main
Steve G.
 

jensmith25

Senior Member
Ok - have you seen the unit you want to emulate? it's a pretty broad field... you could regulate the speed of PWM variation if that's what you need - Use input value from pot - use that value to influence the variation in the PWM on the appropriate channel. This requires a pot determined variable in the code which influences the change of PWM values.
Of course I'm not sure that's just what you are trying to do... ;-0
Yes, but a tiny photo that's no use to anyone. It looked like it had two separate chips tbh with voltage regulation to each to allow 12v supply, two small potentiometers (the small blue ones) and not much else. It looked quite small.
 
Last edited:

mortifyu

New Member
From a totally different angle, providing you with TRUE randomness, you could always have microphone connected to an ADC input taking regular samples to provide you with a different PWM level to operate your LED.

You can still use a potentiometer to adjust the MIN/MAX LED intensity.

Just a suggestion.


Regards,
Morty.
 

inglewoodpete

Senior Member
...and yet another angle

Hi Jen, A few years ago I built a garden scene with a gardener 'watering' their growing vegetables with a garden hose. The water 'spray' was several optical fibres set in the hose's nozzle with a high brightness white LED set in the nozzle.

The software that I used to drive the LED would perform a very similar function to the appearance of a flickering candle. The LED used for the candle could be controlled with one or two PICAXE outputs, each driving the LED with different currents.

You may be able to adapt the code below to suit your purpose. The routine is called regularly from the programme's main loop to produce the flickering effect.
Code:
[color=Green]'Constants: Water spray[/color]
[color=Blue]Symbol   PeriodRange       [/color][color=DarkCyan]= [/color][color=Navy]8      [/color][color=Green]'Number of different 'on' times. Larger number gives wider range of times[/color]
[color=Blue]Symbol   MinimumPeriod     [/color][color=DarkCyan]= [/color][color=Navy]2[/color]
[color=Blue]Symbol   OffPeriod         [/color][color=DarkCyan]= [/color][color=Navy]5      [/color][color=Green]'Loops. Constant (Changed from 3 to 5 in Man v0.12)[/color]
[color=Blue]Symbol   WaterLED          [/color][color=DarkCyan]= [/color][color=Navy]5      [/color][color=Green]'Leg 26 White LED 'Hose watering'
'Variables: Water spray[/color]
[color=Blue]Symbol   [/color][color=Purple]WaterOnCount      [/color][color=DarkCyan]= [/color][color=Purple]b17    [/color][color=Green]'>w8  servo routines - watering only[/color]
[color=Blue]Symbol   [/color][color=Purple]WaterOffCount     [/color][color=DarkCyan]= [/color][color=Purple]b18    [/color][color=Green]'w9   servo routines - watering only[/color]
[color=Blue]Symbol   [/color][color=Purple]RandNum           [/color][color=DarkCyan]= [/color][color=Purple]w13    [/color][color=Green]'b26, b27 Must not to used for anything else
'
' *** Control Water - Control water in semi-random spurts ********
'
'  Water (LED) is turned 'on' for a random range of periods
'         and is turned 'off' for fixed period 'OffPeriod'
'  Entry: WaterOnCount, WaterOffCount, RandNum
'   Exit: WaterOnCount, WaterOffCount, RandNum  set to new values: must be preserved for next entry
'[/color]
[color=Black]ContolWater:[/color][color=Blue]If [/color][color=Purple]WaterOffCount [/color][color=DarkCyan]> [/color][color=Navy]0 [/color][color=Blue]Then     [/color][color=Green]'Water flash is currently off
               [/color][color=Blue]Dec [/color][color=Purple]WaterOffCount
               [/color][color=Blue]Random [/color][color=Purple]RandNum             [/color][color=Green]'Variable for random number must be preserved
               [/color][color=Blue]If [/color][color=Purple]WaterOffCount [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]Then  [/color][color=Green]'If water off, off period has ended
                  [PLAIN]'[RandNum // PeriodRange] limits random number to {PeriodRange} steps [/PLAIN]
                  [/color][color=Purple]WaterOnCount [/color][color=DarkCyan]= [/color][color=Purple]RandNum [/color][color=DarkCyan]// [/color][color=Blue]PeriodRange [/color][color=DarkCyan]+ [/color][color=Blue]MinimumPeriod
                  High WaterLED           [/color][color=Green]'Turn LED 'water' on
               [/color][color=Blue]EndIf
            Else                          [/color][color=Green]'Water flash is currently on
               [/color][color=Blue]If [/color][color=Purple]WaterOnCount [/color][color=DarkCyan]= [/color][color=Navy]0 [/color][color=Blue]Then   [/color][color=Green]'If 'on' period has expired,
                  [/color][color=Purple]WaterOffCount [/color][color=DarkCyan]= [/color][color=Blue]OffPeriod
                  Low WaterLED            [/color][color=Green]'Turn LED 'water' off
               [/color][color=Blue]Else
                  Dec [/color][color=Purple]WaterOnCount
                  [/color][color=Blue]High WaterLED           [/color][color=Green]'Ensure LED 'water' is on in initial entry (start water)
               [/color][color=Blue]EndIf
            EndIf
            Return[/color]
 

jensmith25

Senior Member
Thanks very much everyone for your help. The code from Steve G works very well so assuming my customer is happy with the randomness I'll go with that.

The only downside is it needs a PWM pin and I'm using one already for the brightness control so it's limited as to how many lights you can run off it. The 18m2 only has 2 PWM outputs.
If it needs to run off more outputs then would need to look at inglewoodpete's suggestion.
 

premelec

Senior Member
The 14M2 and 20M2 have 4 PWMOUT pins - worth considering using... the down side 18 has different power pins than 08, 14, 20 power pins which are the same... thus easily used in one [20 pin] socket.
 

jensmith25

Senior Member
Thanks premelec, that's useful to know for the future.

The advantage of the 18m2 project board is the onboard voltage regulation (they want it to be 12v output) and the option for the high power board as there will be several lights running off it.
 

premelec

Senior Member
Ok - must be a BIG fire simulation if it needs higher power - LEDs are so bright! Maybe the previous units used incandescent lamps... Often times I patch in a 3 terminal regulator on a board [with bypass caps] - and you refer to 12v OUT so perhaps you need the darlingtons as well... good luck with it all
 

jensmith25

Senior Member
Premelec - Thanks. They want to use filament bulbs which are 50-80mA each and it's for all the lights in a dolls house. I thought it was just for 25 bulbs but now it sounds like it's 40 bulbs so if they're 80mA bulbs then it's too much even for the high power 18m2 project board.
 

premelec

Senior Member
That's an impressive doll house! You can use some low level MOSFETs to switch the lamps... also I have used common telephone type wire to feed this sort of thing - even using modular connectors for connection. it's good to remember that the initial - hence current - into a tungsten filament can be ten times higher that it's lit current.. so power supply must be able to take initial current surge if lots are turned on at once. i must admit I rather like the hot filament colors... if you haven't seen them also take a look at LED filament lamps that are being built to replace some incandescent lamps - they are strings of tiny LEDs ... more light efficient and no initial surge.. Interesting project...
 

jensmith25

Senior Member
premelec - thanks. I have tested the grain of wheat bulbs I have and the current doesn't spike on power up. It's consistent at around 80-83mA as specified. Thanks for the warning though as that could have killed the whole project!

Do you know if the Picaxe boards can be powered by an AC output transformer? Some dolls houses use AC transformers but I always use DC output.
 

hippy

Technical Support
Staff member
Do you know if the Picaxe boards can be powered by an AC output transformer?
PICAXE boards expect DC but an AC transformer can be used if rectified to DC at an appropriate voltage and suitable reservoir capacitors are used.
 
Top