Picaxe Simple Nightlight


nightlight picture
(click image for better view)

Over the last few years,  I've watched the steady and terrific progression of maker-friendly hardware such as the Arduino.  But it was really the simplicity of the Picaxe that lured me in to spend yet a few more hours thinking of neat devices I might build with their latest wonders.  I'm amazed that even the simplest Picaxe chips can be made into almost anything you might imagine.  And while there's no limit to the complexity and capability of a design you might build using the Raspberry Pi, the Picaxe is at the other end of the spectrum.  Yet this modest chip is now at a point where, quite literally: the simplest single chip version available can be programmed into a 1000+ point datalogger, a clock, or a even thermometer, with no additional components, running off of nanowatts scavanged from "dead" AA batteries, at a cost of less than $3 per build

Although it's been many years since I made my first "hello world" blinking light, even within this trivial design, innovation keeps occurring.  So here is it:  a power-optimized programmable self-calibrating pulse-width-modulation driven light-sensing electro-optical circuit, also known as the simplest single LED nightlight.

The Picaxe allows you to take many shortcuts in your design.  Since the i/o pins will only sink or source 20mA, LEDs don't need current limiting resistors.  Darkness is sensed by the same LED that is lighting up; which is the only external component needed for the circuit.  Brown-out detection is disabled during brief 288ms naps, thereby reducing current consumption down to 10uA or less, and allowing the device to run on 1.8v or less.  During development, I was fooled into thinking the device was malfunctioning when it didn't reset after disconnecting the batteries; so be sure to short the power leads on the device (after disconnecting the batteries) or give it 10+ seconds without power to let spare capacitance dissipate.  

The design contains 2 resistors and a programming header.  While these aren't necessary, they only add a few cents to the design, and the temptation to program and reprogram a nightlight ad-nauseum was just too great for me to resist. (this self-realization should probably bother me more than it does!)

For me, this simplest of projects demonstrates how eventually, all designs become software.  And all software is a work-in-progress, since there's always something else that can be optimized if I have a few more minutes.  This minimalist nightlight design consists of only a Picaxe, an LED, and a battery, yet it really can be reprogrammed into the datalogger, clock, and thermometer that I mentioned.  Add a single length of wire, and you can use the "touch" command to detect user input; a perfect complement for the single-bit output that the LED provides.

Electronic design doesn't get much more minimalist than a Turing machine connected to single bit input and output lines.  Yet as processing power increases, this design can accomplish anything. 


The following schematic/layout drawing was generated from this file using PEBBLE (Picaxe Electronic Bread Board Layout Emulator - V3.1).

nightlight schematic(click to enlarge)

Parts count:

  • 1 Picaxe-08M microcontroller
  • 1 LED
  • 2 resistors (10K, and 22K; for in-circuit programming)
  • 1 3-pin programming header
  • misc wire, DIP socket, a battery holder, veroboard

My schematic is above, and here is the code.  My style/documentation is pretty rigorous, but I strongly advocate good coding practice regardless of the machine; all software only becomes more obfuscated over time.

Some noteworthy aspects of the program:

  • Separate variable, constant, and pinout sections permit quick modification
  • A built-in code identifier:  Hook up the serial cable and connect power, and it self-identifies it's code-base.  This is a lifesaver for quickly identifying hardware pinouts and software version for the numerous unlabled protoboards which are lying around.
  • The first 10 minutes of power (approx) send light readings via the serial cable, so you can easily check whether your LED functions well as a light-sensor.
  • Triggers when current light is < 25% of the range from min light to max light for that day.
  • Resets min/max light readings approx every 24 hours; this is an adaptable trigger-threshold, so the light recalibrates if you move it between dark-light environments.
  • Pulse-width modulated fade-in and fade-out effect, operates intermittently to maximize battery life.
  • Microcontroller enters low-power mode when LED is off.
  • Brown-out fuse disabling during naps, further reduces power usage and allows operation at low voltages.


This code is explicitly released under the GPL. And this page is licensed under a Creative Commons Attribution 2.5 License.  

Write me if you find this project interesting. Link to this page if you find it relevant..

Warning, may cause loss of time. This project is provided without any warranty and probably isn't suitable for anything.

Read or write a comment on the hardware projects

Back to Picaxe Projects