Introduction: Light Sensing LED - PICAXE Version

A while ago I posted light sensing LED which used the arduino board now it is the same project but using a PICAXE microcontroller.This is the simplest circuit you might have ever seen it only uses a PICAXE microcontroller,a resistor and a LED.A LED not only lights up when power is applied but also produces a tiny voltage when exposed to light.Based on this principle we are going to make our "light sensing LED".A single LED is used to take a reading and light up when it is dark.This is a fun to do project which requires minimal parts.

This instructable will explain how to create your own light sensing LED,making some changes,programming the microcontroller,makingit on a breadboard and soldering the circuit.

A short video of it in action:

Step 1: How Can the LED Sense Light?

An LED can be used for light detection as well as emission.LED is a simple diode which has been adopted to emit light.Therefore if it is inserted into the circuit the same way as the photodiode it will serve the same function of sensing light

The LEDs will be sensitive to the light which has the wavelength equal to it or lesser than it.

When light falls on the LED a small voltage is produced this voltage produced can be fed to a microcontroller which can read it and follow the further instructions.

Step 2: Parts & Tools

Parts :
~ PICAXE 08M2 Microcontroller -
~ 330 Ohm Resistor -
~ Green or Red LED(I used a green LED) -
~ 10k Ohm Resistor -
~ 22k Ohm Resistor -
~ Audio Jack -

Tools :
~ Soldering Iron - Sparkfun .com
~ Solder Wire -
~ PICAXE Programmer -
~ ProtoBoard -
~ BreadBoard -
~ PICAXE Programming Editor -
~ Audio Cable 3.5mm - 
~ A to miniB USB Cable -

Note - Use only green or red LED and not any other color as the LED's of these two colors are the most sensitive to light.

The total cost would be around 5.55 $ assuming that you have all the tools.

Step 3: Programming

First you will need to program your PICAXE microcontroller for this you need a programmer I bought one from sparkfun for $14 it is the cheapest USB programmer for PICAXE that I found and you will need to download the PICAXE programming editor.Configure you programming editor to 08M2 mode and select the suitable COM prot.For programming your PICAXE you need to make the download circuit it consists of three wires.One wire sends data from the computer to the serial input of the PICAXE, one wire transmits data from the serial output of the PICAXE to the computer, and the third wire provides a common ground.I have added a schematic for the download circuit.You also need to externally supply 4.5v power supply to the PICAXE while programming (My programmer needs a external supply yours may not need one).I  made the circuit on a breadboard you can make it on a protoboard.I removed the power rails of my breadboard as they were not allowing the cable to go into the audio jack.

Here's the sensitive to dark code
main:readadc 2,b0
        if b0 < 10 then dark
        goto main
dark:high 2
     pause 1000
     goto main

Here's the sensitive to light code
main:readadc 2,b0
        if b0 > 10 then light
        goto main
light:high 2
       pause 1000
       goto main

If the programming finishes properly a pop up window will appear saying success and will display the size of the sketch.If something goes wrong please feel free to ask.

Step 4: Built the Circuit

This might be the simplest circuit you might have ever seen it consists of a PICAXE microcontroller,a LED and a resistor.A single LED is used to take a reading and light up when it is dark.You can test the circuit on a breadboard then you can solder it on a protoboard.The circuit is pretty straight forward connect the +ve terminal of the LED (with a longer lead) to pin2 of the PICAXE microcontroller and connect the -ve terminal of the LED (with a shorter lead) to gnd. Dont forget to add a resistor between the +ve terminal of the LED and pin2 of the microcontroller.Connect the +ve and -ve terminals of the microcontroller to +5v and -5v respectively.I used a wall adaptor to power it you can use 3xAA batteries.I used no resistor for the LED as it has a inbuilt resistor.Look at the last image for the schematic!.

Step 5: Testing & Changing Sensitivity

There are two codes that I have provided one is the sensitive to dark code and the other is sensitive to light code.If you are using sensitive to dark code the LED should light up when you are in dark and should switch off when you are in a well lit room.If you use the sesitive to light code then the LED should light up when you are in a well lit room and should switch off when you are in dark.To change this sensitivity what I did was I simply replaced ' < ' with ' > ' and it worked.

Step 6: Soldering

Now that you have built the circuit on a breadboard and tested it lets make the circuit permanent and solder it.If you have no experience of soldering consult this guide.You should always use the lead free solder as leaded could be harmful.Maintain safety while ,soldering use gloves and safety glasses use proper stand to keep you soldering iron as it is very hot and can harm you.You can use hard core wire to make the connections.You need a very small piece protoboard as this circuit is very small.Use 8 pin DIP socket to keep your PICAXE microcontroller safe.This might be the worst soldering you have ever seen but don't mind as I am not at all good at soldering.

Step 7: All Done!

Hope this project inspires further experimentation. The PICAXE microcontrollers are extremly versatile and have a easy to learn programming language. This is just one of many simple projects which can be constructed using the PICAXE microcontrlles. Keep pondering!.Dont forget to follow mores comming up. .For any queries leave a comment below,PM me or contact me heres my E-mail ID


protoproff (author)2016-07-11

I love Picaxe and find the programming side easy and fun, amazing what you can build with these things, I always incorporate a 3pin icsp ( 3way header) into my circuits. With minimal components you can surely compact your circuit design I've switched over to smd and that's a whole new level of projecting. Hf

DanDav1956 (author)2015-11-22

Actually pin 5 or input C.2

AndyGadget (author)2012-03-29

Which of the programs gives you the short interval blink? The 'pause 1000' should give you a 1 second blink (at 4MHz) when triggered.  Another thing you could try is a 0.1uF capacitor across the supply, as close as possible to the chip's power pins.  (This is good design practice for any digital circuit.)

Dave Kruschke (author)AndyGadget2014-02-23

Normally, using the capacitor across the supply would be "good practice" but the loads here are non inductive (no coils or windings) and they are very wimpy - so any spikes must be pretty minimal. My similar project worked fine without any supply capacitor...

AndyGadget (author)2012-03-28

I think you've got the chip in upside-down in your title picture!
Speed should not be a problem. If you're running this without the programming resistors, make sure that the chip pin 2 is tied to 0V otherwise you can get strange things happening. 

Dave Kruschke (author)AndyGadget2014-02-23

I also found a need to "tie Leg 2 to 0V (using a 10k ohm resistor).

Dave Kruschke (author)2014-02-23


I had trouble duplicating your interesting project. I tried to derive a schematic by going back and forth between your images but kept finding, for me at least, contradictions. By making some changes to your schematic and code, I was finally able to get the assembled parts to work as a "dark detector." If you search for "PicAxe LED dark detector" in Instructables, you will see the details of what I did. You will notice that I didn't attempt any kind of fancy "Fritzing" but simply drew my schematic in pencil and then took a picture of it. More than a few people with electronics experience will relate better to a simple schematic rather than some kind of pictorial Fritzing that isn't clear enough to identify the parts...

Dave Kruschke

PicAxe dark detector 1.JPG
mpep (author)2013-06-20

"Sketch"???? I thought you were in the PICAXE world? :-)

Good wee instructable. Thanks.

chailiyh (author)2012-04-01

you can do it with a LM339 too.
but you will need much more res.

justbennett (author)2012-03-28

Thanks for posting this. This concept is included in some other instructables, I think, but I like that this one focuses on one concept. This could be incorporated into more complicated projects in interesting ways. I like the picaxe too (cheap AND easy), and I hope to see more projects on here soon. I'm working on a couple myself.

masterchippy (author)2012-03-28

I do not know if it will make any difference but the 08M2 can have its speed adjusted from 4MHz to 32MHz with

setfreq M32

AndyGadget (author)2012-03-27

There is only part of a program here.
What about the 'readadc' to get the b0 value and the code to tie those snippets together?

Bot1398 (author)AndyGadget2012-03-28

Sorry forgot to include that! btw how did you like the instructable?

AndyGadget (author)Bot13982012-03-28
That's better.
I'd have written the program as:

    readadc 2,b0
    if b0 < 10 then
        high 2
        pause 1000
    end if

but either way works.

How about putting in spaces after full stops in your text?  It would make it a lot easier to read.  Also, you mention the schematic in your text but I can't see it there.  It's a very simple circuit but that would make things a lot clearer.  All in all though, a good start.

There is another way of doing this which is more sensitive.  The LED junction is first 'charged' and then the state of an input pin checked after a time.  The discharge rate is related to the light level so can be used as a dark / light switch. 

P.S. It's not a good idea to display your e-mail address like that unless you want all sorts of spam turning up in your mailbox.

Bot1398 (author)AndyGadget2012-03-28

I have added the schematic and I not received any spam from anyone actually I have not received any email from anyone

About This Instructable




Bio: Preapering for my medical entrance exams
More by Bot1398:555 Crriter RepellentSolar Powered Clock HackDIY Astronomy Flashlight
Add instructable to: