95. Uplighter

Uplighter 4: Software

RemoteThe original purpose of this lamp was as a dawn simulator. So, at alarm time the light would very slowly fade in, like a sunrise. However, as the remote control has four buttons, I got a bit carried away assigning functions! Here’s the plan:

Button “A”
Press for full brightness (two white LEDs and the yellow on full); fade down to zero while held down
Button “B”
Press for candle effect (low-level flickering yellow LED)
Button “C”
Press to turn off all LEDs; fade up to full brightness while held down
Button “D”
If lamps are off then begin sunrise. If lamps are on then set to full brightness and begin sunset.

The receiver has five outputs, one for each button and a composite that goes High when any other output is high. By connecting each output to an Arduino digital input (i.e. any pin), it’s only necessary to set an interrupt on the fifth pin. If that pin goes high then the code jumps to the interrupt routine which sets a flag to say that a button is being pressed. Then, as soon as possible, it’s simply a matter of testing the main four pins to see which one of those is high – and thus to infer which button is being pressed. Similarly, it’s easy to test for button release because the fifth pin will go low, regardless of which button had been pressed.

The candle effect uses the code I wrote for the Bearing Witness project.

Regular checks
Not everything can be done using interrupts. There are three things that the software has to do on a regular basis:

  1. Look to see if the alarm is active.
    The external clock triggers a dawn simulation. The uplighter connects to the clock’s alarm output (having disconnected the actual piezo-electric sounder, so it doesn’t actually make a noise. The original alarm was a square wave, about 1KHz, starting out quiet and increasing in volume over about half a minute. It also went “beep, beep, beep” etc. Therefore, the output was of varying voltage and not consistently on, so the Arduino needs to check it several times a second to be sure it doesn’t get missed.
  2. Check the internal temperature.
    The thermistor attached to the LEDs connects to a hardware circuit that can shut off the LEDs independently of the Arduino if the heatsink gets too hot. This was in case the Arduino fails, leaving all the outputs high. However, the thermistor inside the lamp needs to be tested by the software. Every few seconds should be sufficient for this, if not every minute or two.
  3. Check the PSU voltage.
    Since the current through the LEDs is highly dependent on the voltage applied, it’s important that the power supply voltage doesn’t exceed 12 Volts by much since this would overdrive the LEDs. Therefore, this test shuts down the lamp if the input voltage is too high. This protects against an incorrect or faulty power supply.

In fact, this third one presented quite a problem. The current through the LEDs is highly dependent on the voltage applied. Typically, these COB LEDs need somewhere around 10 Volts to run at one Amp. Each has a series resistor to drop the difference between the LED’s required voltage and the power supply voltage. I calculated the value of each resistor so that they would run at 800mA from exactly 12 Volts when cold. This allows for the increase of current as they heat up, and for variations in the power supply voltage. However, it’s really only ok up to about 12.2 Volts. Above that they can start to exceed their 1 Amp maximum.

The problem is that both the cheap 12V 5A PSU I bought on eBay and the expensive one I bought from Maplins don’t produce exactly 12 Volts. They aren’t far out. Most of the time they’re around 12.1 Volts. The problem is that occasionally they jump up to over 12.5 Volts for a short time (less than a second). That actually equates to quite a high current that could damage the LEDs (most likely by shortening their life rather than destroying the). So, what to do? The voltage is only tested intermittently. How many times is 12.5V acceptable? What about 12.3?

The solution I went for was to dim the LEDs slightly when the voltage exceeds 12.1 Volts. I calculated the amount so that whatever the voltage, the 1 Amp won’t be exceeded when the LEDs are hot. It won’t be exact because the voltage is only tested intermittently (10 times a second), but the variation should even out to prevent a consistently high current. If the voltage exceeds 12.55 Volts then the lamp shuts down completely (or, if at powerup, doesn’t turn on). The table below is based on measured currents, for one LED; there are inaccuracies in the measurement, and it’s not necessarily accurate for anything else, nonetheless, taking into account all the readings I took, it seems that the PWM value needs to be reduced by about 6 for every 0.1 Volt increase.

Voltage Maximum PWM value
12.0 255
12.1 253
12.2 246
12.3 240
12.4 230
12.5 226

Main loop
So, the main loop is as follows:

  1. If sunrise / sunset, adjust brightness according to the time since effect began
  2. If candle, adjust brightness to maintain a flicker effect
  3. If button pressed, initialise new state
  4. If fade button held down, adjust brightness
  5. Do one of the three checks
    • if voltage above 12.1 Volts adjust brightness if above voltage-related maximum; if voltage above 12.55 Volts, turn off all LEDs and stop
    • if temperature exceeds maximum, turn of all LEDs and stop
    • if alarm input high, begin sunrise

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s