vrijdag 6 november 2009

Project: The light-o-meter

Ok, this is the final chapter in the project. We are going to build the actual meter. In the previous postings we've learned to program the PICAXE and use the LDR. Up next is to combine these into one circuit.

One nice feature of the PICAXE 18X is to be able to read analog components, by connecting them to an input pin. This will have to be either input0 (pin 17) or input1 (pin 18) as they have ADC support.

This is how the meter is going to work. The LDR will be used by the PICAXE to determine the amount of light. Based on the amount of light LEDs will be lit or unlit. The more light, the more LEDs will be lit.

For the following circuit we will require these items:
1 x 9V Battery
1 x LDR
1 x 10 kOhm resistor (brrown, black, orange)
1 x 4.7 kOhm resistor (I still use three)
8 x 1 kOhm resistor (brown, black, red)
8 x  C547B transistor
3 x green LED
3 x yellow LED
2 x red LED




Ok, here we go. Step by step:

1. Place the PICAXE on the board, like the last time.





2. Put the 8 LEDs on the board


 
3. For each LED, put a resistor between the LED and ground.
 

4. For each LED add a transistor to the board. Whatch carefully how to connect them.
 

5. Connect each transistor to the appropriate pin on the PICAXE. See the pin layout in the previous post for more details.

 
6. Connect an LDR to the + pole, and the 10kOhm resistor. The resistor should be connected to the - pole. Connect input 1 of the PICAXE to the LDR and resistor.

 
7. Review the result before you blow anything up ;)


8. upload the following code into the PICAXE:

main:
readadc 1, b0 'Read the amount of light 0=dark 255=very much

'Is it very bright? put led 7 on
if b0 > 230 then
    high  7
else
    low 7
end if

'Is it less very bright? put led 6 on
if b0 > 200 then
    high  6
else
    low 6
end if

'Is it bright? put led 5 on
if b0 > 180 then
    high  5
else
    low 5
end if

'Is it medium bright? put led 4 on
if b0 > 150 then
    high 4 
else
    low 4
end if

'Is it below medium? put led 3 on
if b0 > 120 then
    high  3
else
    low 3
end if

'Is it between dark and medium bright? put led 2 on
if b0 > 90 then
    high  2
else
    low 2
end if

'Is it less dark? put led 1 on
if b0 > 60 then
    high  1
else
    low 1
end if

'Is it quite dark? put led 0 on
if b0 > 30 then
    high  0
else
    low 0
end if

goto main


This is the result:


Geen opmerkingen:

Een reactie posten