Category Archives: projects

Timers and Flickering LEDs!

Recently back to work on a 12V RGB LED colour controller that I haven’t worked on in a while as a break from study (actually, read as avoidance of doing any study for a day). After finally finding the current version of the code (that was an ordeal and a half  – had the newer copy in a different folder). I had gotten basic colour selection, brightness control and a seven colour strobe sequence working. Now it was time to do the rest of the colours and get the ‘colour wheel’ / fade  working. Easy. Well, I did a complete re-write of the code, and changed to colour mapping from hard coded RGB to using HSI, which I will talk about in another post. In a nutshell, it let me separate the colour I wanted to set from the brightness or intensity, and as a result, I can easy just set the colour, and change the brightness – and it will re-calculate the new colour codes automatically.

Also made the colour wheel exceptionally easy. So, moving from the small 9 led test strip to the full length 3m ceiling mounted strip and the moment of truth. Switched it on, and chose white. Grea…. aw… what the flicker? It’s pulsing… and quite noticably. So, is there a glitch in the code, or fluctuation of the power supply meaning I really do need to put some filter caps on it. Try some of the other colours… they’re all fine… just white, but some combinations show the flicker also.

Back to google, and a general search for ‘rgb led arduino flicker’ and ‘rgb led arduino pwm flicker’. I suspected the issue was related to the particular pwm duty cycle, so that’s why I looked for PWM related results as well. I saw a few posts which suggested the original posters problems were power related, but then I saw two posts by a chap who has done some great articles on Arduino stuff in the past. And he was having the same problem. He said he though some of his trouble was power supply related, but when he tested the output of the PWM control signals for the LEDs, he noticed that they weren’t what they should have been… and one channel was going in and out of phase… and visibly so! Great… so I wasn’t my imagination. And in his follow-up post, he had the solution… just one line of code in the setup function, and the PWM signal to the three pins in use would be in perfect sync! Eureka! The miraculous line of code is as follows:

bitSet(TCCR1B, WGM12);

Do I hear you ask “What does it do?” Excellent question. In a nutshell, it changes the Timer 1 setting from Phase Correct PWM to Fast PWM, which is what Timer 0 is set to. Although Phase Correct PWM may be the better quality / higher accuracy PWM mode, due to the fact that we are both using RGB leds that are connected to pins controlled by Timer 0 (5 & 6) & Timer 1 (9 & 10), they need to be set to the same mode. Otherwise, the difference in operation will result in a visible flicker. For a much clearer and detailed explanation, please check out Jean-Claude’s postings which I linked above.

After adding just this one line of code, I can happily report that the colour controller is now running without a single flicker. Now I just have to fine tune the colours and add the final touches!

Cosm Local Environment (Weather) Logger


  • 30-12-2012 – Posts to every 15 minutes (as opposed to every 30 minutes)
  • 30-12-2013 – Multiply atmospheric pressure value by 10 to report hPa rather than kPa (breaks historical data)
  • 30-12-2012 – Changed analog LDR sensor for digital lux light sensor (breaks historical data)
  • 27-12-2012 – Now running from a 5v mains powerpack rather than a 12v SLA battery with maintenance charger. 


  • LCD to display data locally
  • SD card to log data locally for analysis
  • Post to twitter when downtime occurs (with explanation codes – ie. loss of network connection)

Brains of the unit (microcontroller) = Atmel ATmega328

Programmed with Arduino 1.5 (C++) 

Connection to the outside world = WIZ820io
  • Plug-in Network Module having W5200 & Mag Jack
  • Usable without H/W design for W5200, Transformer and RJ-45
Temperature & Humidity = DHT22 temperature-humidity sensor
  • Good for 0-100% humidity readings with 2-5% accuracy
  • Good for -40 to 80°C temperature readings ±0.5°C accuracy 

Atmospehric Pressure = BMP085 Barometric Pressure/Temperature/Altitude Sensor
  • Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level)
  • Up to 0.03hPa / 0.25m resolution

Light = TSL2561 digital luminosity / lux / light sensor

  • Approximates Human eye Response
  • Precisely Measures Illuminance in Diverse Lighting Conditions
  • Dynamic range (Lux): 0.1 to 40,000 Lux

Unusual projects

I have recently been having fun with a solar-energy power monitoring system, some friends live in a remote area without access to grid power. They are currently using two banks of old Telcom v2 SLA cells, with pair of solar panels on the roof for charging. There is a 600w inverter providing 240v power for the house, and a solar management unit to ensure peak charge from the solar panels. There is a 240v petrol generator providing backup power and also charging the batteries via a intelligent SLA 25A charger. To make life easier, there is also a automatic change-over switcher which will run the house off the generator whilst it is running, and automatically drop back to the batteries / inverter when it stops.

To monitor the state of the batteries and system, we have installed a Arduino clone board (Freetronics EtherMega) with a RTC, MicroSD card and custom op-amp and shunt sense board. This allows for the battery voltage, load and charge status to be tracked via a 20×4 LCD screen, as well as over the network via a custom website. Plus with data capture, the state of the batteries can be analysed on a excel graph. 

This is where I came. As a result of about three weeks of off-and-on work on the system, I have taken it from a system which simply displayed the voltage, load and charge current of the batteries to a system which is network capable, with a custom website which allows access to this information plus more. There is now a real-time clock onboard as well, so the system knows the current date and time. There is also a MicroSD card which is being used to capture data for later analysis. The website allows the user to grab the data in CSV format, and easily graph it using Microsoft Excel, thus easily visualise the data over time and assess the condition of the batteries.

The website also allows for calibration of the unit, formatting of the MicroSD card, saving of calibration data and resetting to default settings. Next up is to refine and make the code more bullet-proof, and also add the ability to set the time! Then, time to work out how to track the capacity of the batteries in a reliable manner.

Lego NXT project update

Well, yes, it is a new year, and with it it brings a lot of changes. As Dr Rosie Thrupp’s contract at CQUniversity finished in October 2011, the Lego NXT research project has come to an end. However, this is not the end of Lego NXT in the Bundaberg district, as I am endeavouring to obtain access to a venue, prizes and support to continue running the challenges, and where possible, the holiday school workshops.

Should the competition go ahead, the theme of 2012’s challenges are most likely to be based on the ‘International Year of Sustainable Energy for All’, and as a result, be related to renewable energy.