R/Evolution PICAXE-08 User manual

1
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 1
Supported by:
ALARM SYSTEMS
What is a microcontroller?
A microcontroller is often described as
a 'computer-on-a-chip'. It can be used
as an ‘electronic brain’ to control a
product, toy or machine.
The microcontroller is an integrated circuit
("chip") that contains memory (to store the program), a
processor (to process and carry out the program) and input/
output pins (to connect switches, sensors and output devices like motors).
Microcontrollers are purchased 'blank' and then programmed with a specific control
program. This program is written on a computer and then 'downloaded' into the
microcontroller chip. Once programmed the microcontroller is built into a product to
make the product more intelligent and easier to use.
Example use of a microcontroller.
Almost all modern buildings are fitted with some type of alarm. For
instance a fire detection system may have a number of smoke sensors
to detect the smoke from a fire.
However many alarm systems are also safety systems - for instance an
alarm system on an oil rig may monitor the temperature and pressure
of the crude oil as it is being extracted and automatically shut
the system down if a fault is detected. This ensures the safety of
both the workers and the environment around the oil rig.
All systems are made up of input and output devices. Often
these devices are connected to a microcontroller that interprets
the information from the sensors and switches the outputs on
and off at the correct time.
In the case of a fire alarm system the inputs may be smoke
sensors and the keypad on the front of the control panel. The
output devices are the display on the control panel as well as
the external siren and strobe light. The microcontroller is the
'brain' of the system.
Microcontrollers are powerful electronic components that have a
memory and can be programmed to switch things on and off in a
special sequence. The microcontroller in the fire alarm, for
instance, has been programmed to switcyh the siren on and off
when the smoke sensor has detected fire.
123
456
789
*0#
A
PICAXE
ALARM
B
C
D

2
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 2
Supported by:
BLOCK DIAGRAMS
The electronic system that makes up the alarm system be drawn as a ‘block diagram’.
The smoke sensor and keypad provide information to the microcontroller, and so these
are known as ‘inputs’. The microcontroller then ‘decides’ how to behave and may then
operate the outputs e.g. make the siren and strobe switch on or display a message on the
Liquid Crystal Display (LCD).
WHAT IS THE PICAXE SYSTEM?
The microcontrollers used in devices such as the alarm can be difficult to program, as
they generally use a complicated programming language called ‘assembler code’, which
can be quite difficult to learn.
The PICAXE system makes the microcontrollers much easier to program. The control
sequence can be drawn (and simulated) on the computer as a flowchart, or written in a
simpler programming language called BASIC. This makes it much easier to use the
microcontroller as the complicated ‘assembler code’ does not need to be learnt.
A sample BASIC program and flowchart are shown here. In this case both programs do
the same thing - flash a light (connected to output 0) on and off every second.
main:
high 0
wait 1
low 0
wait 1
goto main
start
high 0
low 0
wait 1
wait 1
LCD
strobe
microcontroller
INPUT PROCESS OUTPUT
smoke
siren
keypad
123
456
789
0#

3
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 3
Supported by:
piezo
output
microcontroller
INPUT PROCESS OUTPUT
digital
LED
analogue
BUILDING YOUR OWN ALARM
Design Brief
Design and make an alarm system. The alarm must be programmed to react to inputs
and sensors.
Design Specification Points
1) The design will use a PICAXE-08 microcontroller as it’s brain.
2) The design will include an LED indicator, a piezo sounder to generate noises and an
alarm output that could be a siren or motor..
3) The design will be also be able to react to analogue sensors such as light sensors.
.
Block Diagram
The block diagram for your alarm may look like this:
Designing Your Alarm
Your alarm may be for any purpose you choose. Some examples are given below.
1) A fire alarm. A light sensor is used to detect smoke. When smoke is detected a siren
sounds.
2) A burglar alarm. When a tripwire is activated a flashing stobe light is activated.
However the alarm is disabled during daylight by a light sensor.
3) A bank safety lock. When a ‘panic’ alarm switch is pushed an electronic solenoid
bolt locks a bank safe door.
4) A baby monitor for a bedroom. When movement or sounds are NOT detected, a
warning buzzer is activated.

4
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 4
Supported by:
ELECTRONIC COMPONENTS
The main electronic components you may need for your alarm are shown here. The next
few pages describe each of these components in more detail, and also provide some
programming ideas that may be useful when you are later programming your alarm.
PICAXE-08 microcontroller
light emitting diode (LED)
piezo sounder
light dependent resistor (LDR)
transistor and diode
batteries
and you will also need
picaxe download socket resistors

5
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 5
Supported by:
MICROWAVE MW-1
1
2
3
4
5
6
7
8
9
10
FULLHIGH
MEDDEF
CLEARCOOK
TIMESET
SECTION 2 - ELECTRONIC COMPONENTS
MICROCONTROLLERS
What is a microcontroller?
A microcontroller is often described as a ‘computer-on-a-chip’. It is an
integrated circuit that contains memory, processing units, and input/
output circuitry in a single unit.
Microcontrollers are purchased ‘blank’ and then programmed with a specific
control program. Once programmed the microcontroller is built into a
product to make the product more intelligent and easier to use.
Where are microcontrollers used?
Applications that use microcontrollers include household
appliances, alarm systems, medical equipment, vehicle
subsystems, and electronic instrumentation. Some modern cars
contain over thirty microcontrollers - used in a range of
subsystems from engine management to remote locking!
As an example, a microwave oven may use a single microcontroller to process
information from the keypad, display user information on the seven segment
display, and control the output devices (turntable motor, light, bell and magnetron).
How are microcontrollers used?
Microcontrollers are used as the ‘brain’ in electronic circuits. These electronic circuits are
often drawn visually as a ‘block diagram’. For instance a simplified block diagram for the
microwave above could be drawn like this:
The program for the microcontroller is developed (and tested) on the computer and then
downloaded into the microcontroller. Once the program is in the microcontroller it
starts to ‘run’ and carries out the instructions.
light
motor
microcontroller
bell
magnetron
keypad
switch
pushes
door
switch
INPUT PROCESS OUTPUT

6
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 6
Supported by:
How are programs written?
Programs are drawn as flowcharts or typed as ‘BASIC’ listings. This is is explained in the
programming section (section 3) later in this booklet.
How is the program transferred to the microcontroller?
The PICAXE-08 microcontroller is programmed by connecting a cable from the serial
port at the back of the computer to a socket on the printed circuit board (PCB) beside
the microcontroller. This socket (which looks like a headphone socket as found on a
portable CD player) connects to two legs of the microcontroller and to 0V from the
battery. This allows the computer and the microcontroller to ‘talk’ to allow a new
program to be downloaded into the microcontroller’s memory.
The socket and interfacing circuit is included on every PCB designed to be used with the
PICAXE-08 microcontroller. This enables the PICAXE microcontroller to be re-
programmed without removing the chip from the PCB - simply connect the cable
whenever you want to download a new program!
The circuit diagrams of PICAXE circuits often do not include the components above to
make it easier to understand the input/output connections. However the two resistors
and the socket are always built onto every PICAXE project board!
Output 0
With the PICAXE-08 system leg 7 has two functions - when a program is being run the
leg is known as output 0 and can control outputs like LEDs and motors.
When a program is being downloaded the same leg acts as the ‘serial out’ pin, ‘talking’ to
the computer. Therefore if you also have an output such as an LED connected to the leg,
you will find that the LED will flicker on and off as the program download takes place.
Note:
Most modern computers have two serial ports, normally labelled COM1 and COM2. The
Programming Editor software used to create the programs must be configured for the
correct serial port – select View>Options>Serial Port to select the correct serial port for
your machine.
If you are using a new laptop computer it may only have the newer ‘USB’ type connector.
In this case you must buy a USB to serial adapter to use the PICAXE system. These are
available from most high street computer stores or online from www.tech-supplies.co.uk
(part USB010).
x
x
x
x
x
PICA E-08
7 - serial out
1 - serial in
8 - 0V
22k
10k
Above view
of socket

7
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 7
Supported by:
BATTERIES
What is a battery?
A battery is a self-contained source of electronic
energy. It is a portable power supply.
Batteries contain chemicals that store energy.
When connected into a circuit this chemical
energy is converted to electrical energy that can
then power the circuit.
Which battery size should I use?
Batteries come in all sorts of types and sizes. Most
battery packs are made up of a number of 'cells',
and each cell provides about 1.5V. Therefore 4 cells
will generate a 6V battery and 3 cells a 4.5V battery.
As a general rule, the larger the battery the longer it
will last (as it contains more chemicals and so will
be able to convert more energy). A higher voltage
battery does not last longer than a lower voltage
battery. Therefore a 6V battery pack made up of 4
AA cells will last much longer than a 9V PP3 battery, as it contains a larger total amount
of chemical energy as it is physically larger. Therefore items that require more power to
work (e.g. a CD walkman which contains a motor and laser to read the CD's) will always
use AA cells rather than PP3 batteries.
Microcontrollers generally require 3 to 6V to work, and so it is better to use a battery
pack made up of three or four AA size cells. Never use a 9V PP3 battery as the 9V supply
will damage the microcontroller.
Which battery type should I use?
Different batteries are made of different chemicals. Zinc-carbon batteries are the
cheapest, and are quite suitable for many microcontroller circuits. Alkaline batteries are
more expensive, but will last much longer when driving devices like motors that require
larger currents. Lithium batteries are much more expensive but have a long life, and so
are commonly used in computer circuits to provide a clock backup.
Rechargeable batteries can be recharged when they 'run-down'. They are generally made
up of nickel and cadmium (Ni-cad) or nickel metal hydroxide (NiMH) chemicals.
3V

8
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 8
Supported by:
Safety!
Never 'short circuit' any battery. Alkaline and rechargeable batteries can provide a very
large current, and can get so hot that they will actually melt the battery box if you short
circuit them! Always make sure you connect the battery around the correct way (red
positive (V+) and black negative (0V or ground)). The microcontroller chip will get hot
and be damaged if the battery is connected the wrong way around.
Using battery snaps.
Battery packs are often connected to electronic printed circuit boards by
battery snaps. Always ensure you get the red and black wires the correct
way around. It is also useful to thread the battery snap through holes on
the board before soldering it in place - this provides a much stronger
joint that is less likely to snap off.
Never accidentally connect a 9V PP3 battery to the battery snap - this will
damage the microcontroller, which only works between 3 and 6V.
Soldering to battery boxes.
Some small battery boxes require wires to be soldered to metal contacts on the battery
box. In this case you must be very careful not to overheat the metal contact. If the
contacts gets very hot they will melt the plastic and fall off. A good way of stopping this
happening is to ask a friend to hold the metal contact with a pair of small pliers. The
pliers will act as a ‘heat-sink’ and help stop the plastic melting.

9
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 9
Supported by:
0V
pin
330R
LIGHT EMITTING DIODE (LED)
What is an LED?
A Light Emitting Diode (LED) is an electronic component
that gives out light when current passes through it. An
LED is a special type of diode. A diode is a component
that only allows current to flow in one direction. Therefore when
using a diode, it must always be connected the correct way around.
The positive (anode) leg of an LED is longer than the negative
(cathode) leg (shown by the bar on the symbol). The negative leg
also has a flat edge on the plastic casing of the LED.
What are LEDs used for?
LEDs are mainly used as indicator lights. Red and green LEDs are commonly used on
electronic appliances like televisions to show if they are switched on or in 'standby'
mode. LEDs are available in many different colours, including red, yellow, green and
blue. Special 'ultrabright' LEDs are used in safety warning devices such as the 'flashing
lights' used on bicycles. Infra-red LEDs produce infra-red light that cannot be seen by the
human eye but can be used in devices such as video remote-controls.
Using LEDs.
LEDs only require a small amount of current to work,
which makes them much more efficient than bulbs (this
means, for instance, that if powered by batteries the LEDs
will light for a much longer time than a bulb would). If
too much current is passed through an LED it will be
damaged, and so LEDs are normally used together with a
'series' resistor that protects the LED from too much
current.
The value of the resistor required depends on the battery
voltage used. For a 4.5V battery pack a 330R resistor can
be used, and for a 3V battery pack a 120R resistor is
appropriate.
Connecting the LED to a microcontroller.
Because the LED only requires a small amount of current to operate, it can be directly
connected between the microcontroller output pin and 0V (with the series protection
resistor).

10
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 10
Supported by:
Testing the LED connection.
After connecting the LED it can be tested by a simple program like this:
main:
high 0
wait 1
low 0
wait 1
goto main
This program would switch the LED (connected to
output pin 0) on and off every second. If the LED does
not work check:
1) the LED is connected the correct way around
2) the correct resistor is used
3) the correct output pin number is being used in the
program
4) all the solder joints are good
This program flashes the LED connected to output pin 0 on and off 15 times using a
BASIC programming technique called a for...next loop (this technique cannot be used
with flowcharts). The number of times the code has been repeated is stored in the
memory of the PICAXE chip using a ‘variable’ called b1 (the PICAXE contains 14
variables labelled b0 to b13). A variable is a ‘number storage position’ inside the
microcontroller than the microcontroller can use to store numbers as the program is
carried out.
main: for b1 = 1 to 15 start a for...next loop
high 0 switch pin 0 high
pause 500 wait for 0.5 second
low 0 switch pin 0 low
pause 500 wait for 0.5 second
next b1 end of for...next loop
end end program
start
high 0
low 0
wait 1
wait 1

11
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 11
Supported by:
BUZZERS AND PIEZO-TRANSDUCERS
What is a piezo transducer?
A piezo transducer is a low-cost 'mini-speaker' that can used to
make sounds. The sound that the piezo makes can be changed
by altering the electronic signals provided by the
microcontroller.
Where are piezos used for?
Piezos are used in many different consumer goods to provide 'feedback' to the user. A
good example is a vending machine which will 'beep' whenever a keypad switch is
pressed to select a drink or snack. The 'beep' provides the user with feedback to tell them
their switch push has been successful. Uncased piezos are also often used in musical
birthday cards to play a tune when the card is opened.
What is the difference between a piezo and a buzzer?
A buzzer contains a small electronic circuit that generates the electronic signal needed to
make a noise. Therefore when a buzzer is connected to a battery it will
always make the same sound. A piezo does not contain this circuit, and so
therefore needs an external signal. This signal can be supplied by the
output pin of a microcontroller. A piezo also requires less current to
operate and so will last longer in battery powered circuits.
Using piezos.
A piezo is very simple to connect. Simply
connect the red wire to the microcontroller
output pin and the black wire to 0V
(ground).
Note that the cheapest piezos do not have a
plastic casing to them. In this case it is
necessary to mount the piezo on a piece of
board (with a sticky pad) to create a noise
that can be heard. The board acts as a
'sound-box' to amplify the sound made by
the piezo. Make sure the sticky pad is stuck
on the correct side of the piezo (the brass side
without the wires!).
Making More Noise.
Some times you might want to make a louder noise. In this case it is
possible to use a speaker instead of the piezo. When using a speaker
it is also necessary to use a capacitor (e.g. 10uF electrolytic capacitor)
to prevent damage to the microcontroller.
Remember that, like the piezo, a speaker only works correctly when
mounted in a 'sound-box'.
pin
0V
pin
0V
+
40R
10uF

12
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 12
Supported by:
Testing the piezo connection.
After connecting the piezo it can be tested by a simple
program like this:
main:
sound 2,( 5,100)
sound 2,(78,100)
sound 2,(88,100)
sound 2,(119,100)
goto main
This program would make the piezo (connected to
output pin 2) make 4 different sounds (value 65, 78, 88
and 119). If the piezo does not work check:
1) the sound value is between 0 and 127
2) the correct output pin number is being used in the program
3) all the solder joints are good
With the sound command, the first number provides the pin number (on projects pin2
is often used). The next number is the tone, followed by the duration. The higher the
tone, the higher the pitch of the sound (note that some sounders cannot produce very
high tones and so number greater than 127 may not be heard).
When using multiple sounds you may also include them all on the same line e.g.
sound 2,( 5,100,78,100,88,100,119,100)
The following table shows some common notes with the appropriate sound value:
A(49), As(51), B(54), C(57), Cs(61), D(65), Ds(71), E(78), F(88), Fs(101), G(119)
The following BASIC program uses a for…next loop to produce 120 different sounds,
using variable b1 to store the sound value.
main:
for b1 = 1 to 120 start a for...next loop
sound 2,(b1,50) make a sound, freq value from b1
next b1 next loop
end
The number stored in variable b1 is increased by 1 in every loop (1-2-3 etc.) Therefore by
using the variable name b1 in the tone position, the note can be changed on each loop.
The following program does the same task but backwards (counting down instead of
up).
main:
for b1 = 120 to 1 step -1 start a for...next loop
sound 2,(b1,50) make a sound, freq value from b1
next b1 next loop
end
start
sound 2,(65,100)
sound 2,(78,100)
sound 2,(88,100)
sound 2,(119,100)

13
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 13
Supported by:
TRANSISTOR
What is a transistor?
A transistor is a component that controls current flow in a circuit.
A transistor acts as an ‘electronic switch’ so that a small current
can control a large current. This allows low-current devices, like a
microcontroller, to control large current devices (like motors).
Where are transistors used?
Transistors are used in radios and electronic toys and many
other devices such as this electronic stapler.
Using transistors.
A transistor has three legs. These are labelled base,
collector and emitter. The base connection is the leg
that is used to activate the ‘electronic switch’. When a
small current is passed through the base connection, it
allows a much larger current to flow down between the
collector and emitter. This larger current can be used to
switch on devices such as motors, lamps and buzzers.
A common transistor is the BC548B type. This has a
plastic can with a flat edge. The flat edge enables the base,
collector and emitter legs to be correctly identified.
Using motors.
Motors can generate ‘electrical noise’ as they turn.
This is because the magnets and electric coils inside
the motor generate electrical signals as the motor
rotates. These signals (the electronic noise) can
disrupt the operation of the microcontroller. Some
motors, like solar motors, produce very little noise
whilst others can create a lot of noise.
To prevent electrical noise affecting the micro-
controller circuit a 220nF capacitor should always
be soldered across the motor terminals before it is used.
In addition, a diode (e.g. 1N4001 diode) should be connected
alongside the motor. This prevents damage to the transistor as
the motor slows down after the transistor switches off (for a
short period of time (as it slows down and stops) the motor is
acting as a ‘dynamo’ and generating electric current!). When
connecting a diode make sure the ‘band’ is connected the
correct way around. It is also a good idea to connect a 100uF
electrolytic capacitor across the battery supply to help
‘suppress’ the the electrical noise.
0V
Pin
1k
Output
device
BC548B
V+
1N4001
emitter (E)
base (B)
collector (C)
B
C
E
m
+V
0V
m
+V
0V
small
current
into base
large
current
across
collector/
emitter

14
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 14
Supported by:
Testing the transistor using a buzzer
A buzzer could be connected as an output device as in this cicruit.
After connecting the buzzer it can be tested by a simple
program like this:
main:
high 4
wait 1
low 4
wait 1
goto main
This program would switch the buzzer (connected to
output pin 4) on and off every second. If the buzzer does
not sound check that:
1) the diode is connected the correct way around
2) the correct resistors are used
3) the transistor is connected the correct way around
4) the buzzer red wire is connected the correct way around
5) the correct output pin number is being used in the program
6) all the solder joints are good
Output Devices
Output devices that can be connected via a transistor include buzzers, motors, solenoids,
sirens and flashing strobe lights. However some devices may need a higher power
transistor - in this case the Darlington transistor BCX38B can be used instead of the
standard BC548B transistor.
0V
pin
1k
Buzzer
BC548B
V+
1N4001
(red)
start
high 4
wait 1
wait 1
low 4

15
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 15
Supported by:
DIGITAL SENSORS (SWITCHES)
What are switches?
A digital sensor is a simple ‘switch’ type sensor that can only be ‘on’ or ‘off’. If a graph is
drawn of the on-off signals as the switch is pushed it will look like this:
Switches are electronic components that detect movement. There are a large number of
different types of switches e.g:
push switches that detect a momentary 'push'
micro-switches with long levers that detect small movements
tilt-switches that detect jolting
reed-switches that detect a magnet being moved
What are switches used for?
Push switches are commonly used on device like keypads. Micro-switches are used in
burglar alarms to detect if the cover is removed from the alarm box. Reed switches are
used to detect doors and windows being opened and tilt switches are often used to detect
movement in devices such as toys, hair-dryers and tool-box alarms.
Switch Symbols.
The symbols for a slide switch
and a push switch are shown here.
0V
5V
Time
Voltage

16
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 16
Supported by:
Using switches
A switch is used with a resistor as shown in the diagram. The
value of the resistor is not that important, but a 10k resistor
is often used. When the switch is 'open' the 10k resistor
connects the microcontroller input pin down to 0V, which
gives an off (logic level 0) 0V signal to the microcontroller
input pin.
When the switch is activated, the input pin is connected to
the positive battery supply (V+). This provides an on (logic
level 1) signal to the microcontroller.
Testing the switch
After connecting the switch it can be tested by a simple program like this. This program
will switch an output on and off according to if the switch is pushed or not.
main: make a label called main
if input3 is on then flash jump if the input is on
goto main else loop back around
flash: make a label called flash
high 0 switch output 0 on
wait 2 wait 2 seconds
low 0 switch output 0 off
goto main jump back to start
In this program the first three lines make up
a continuous loop. If the input is off the
program just loops around time and time
again.
If the switch is then pushed the program
jumps to the label called ‘flash’. The
program then flashes output 0 on for two
seconds before returning to the main loop.
Note carefully the spelling in the if…then
line – input3 is all one word (without a
space). You can use the word pin3 or input3
to mean the same thing. Note also that only
the label is placed after the command then
– no other words apart from a label are
allowed at this point.
V+
0V
10k
Pin
start
high 0
low 0
pin3=1 Y
N
wait 2

17
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 17
Supported by:
LIGHT DEPENDENT RESISTOR (LDR)
What is an LDR?
A Light Dependent Resistor (LDR) is special type of resistor that reacts to changes in light
level. The resistance of the LDR changes as different amounts of light fall on the top
'window' of the device. This allows electronic circuits to measure changes in light level.
What are LDRs used for?
LDRs are used in automatic street lamps to switch them on at night and off during the
day. They are also used within many alarm and toys to measure light levels.
The LDR is a type of analogue sensor. An analogue sensor measures a continuous signal
such as light, temperature or position (rather than a digital on-off signal like a switch).
The analogue sensor provides a varying voltage signal. This voltage signal can be
represented by a number in the range 0 and 255 (e.g. very dark = 0, bright light = 255).
R(W)
Light intensity
(Lux)
dark light
LDR
0V
5V
Time
Voltage
dark
light

18
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 18
Supported by:
Using LDRs.
A LDR can be used in two ways. The simplest way to use an LDR is
as a simple on-off ("digital") switch - when the light level is above
a certain value (called the 'threshold value') the LDR will provide
an on signal, when the light level is below a certain value the LDR
will provide an off signal.
In this case the LDR is used in a potential divider with a standard
resistor. The value of the standard resistor sets the 'threshold value'.
For miniature LDRs a suitable value is 10k or 1k, for larger ORP12
type LDRs 10k is more appropriate. If desired the fixed resistor can
be replaced by a variable resistor so that the threshold value can be
'tuned' to different light values.
A more versatile way of using the LDR is to measure a number of different light values, so
that decisions can be made at varying light levels rather than just one fixed threshold
value. A varying value is known as an 'analogue' value, rather than a digital 'on-off' value.
To measure analogue values the microcontroller must contain an 'analogue to digital
converter (ADC)' and the programming software must support use of this ADC. Most
microcontrollers only contain ADC on certain input pins, and so the input pin
connection must be carefully selected. With the 8 pin microcontroller only pin1 can be
used.
The electronic circuit for using the ADC is a potential divider identical to the circuit
above. The analogue 'measurement' is carried out within the microcontroller itself.
10k

19
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 19
Supported by:
Testing the LDR (digital)
After connecting the LDR it can be tested as a
digital switch by a simple program like this:
main:
if input1 is on then dohigh
low 0
goto main
dohigh:
high 0
goto main
This program will switch output 0 on and off according to the light level.
Testing the LDR (analogue)
After connecting the LDR it can be tested
as an analogue sensor by a program like
this:
main:
readadc 1,b1
if b1 > 100 then do4
if b1 > 50 then do0
low 0
low 4
goto main
do4:
high 4
low 0
goto main
do0:
high 0
low 4
goto main
The ‘readadc’ command is used to read the analogue value (a number between 0 and
255) into variable b1. Once the number is in variable b1 it can be tested to see if it is
greater than 100 or greater than 50. If it is greater than 100 output 4 is switched on, if it is
between 50 and 100 output 0 is switched on, and if it is less than 50 both outputs are
switched off.
start
high 0low 0
pin1=1 Y
N
start
readadc 1,b1
b1> 100 Y
N
b1> 50 Y
N
high 0 high 4low 0
low 4 low 4 low 0

20
PICAXE-08 ALARM PROJECT
revolution © copyright 2002 - AXE102 Alarm Student Project Notes Version 1 1
Revolution Education Ltd Email: info@rev-ed co uk Web: www rev-ed co uk 20
Supported by:
SECTION 3
PROGRAMMING - DRAWING FLOWCHARTS
Flowcharts are a useful tool that allow programs to be drawn graphically to make them
easier to understand. The Programming Editor software includes a flowchart editor that
allows flowcharts to be drawn on screen. These flowcharts can then be converted to
BASIC listings for download into the PICAXE. The flowcharts can also be printed or
exported as graphics files for inclusion within project portfolios.
Detailed instructions for drawing/downloading a flowchart:
1. Connect the PICAXE cable to the computer serial port. Note which port it is
connected to (normally labelled COM1 or COM2).
2. Start the Programming Editor software.
3. Select View>Options to select the Options screen (this may automatically appear).
4. Click on the ‘Mode’ tab and select PICAXE-08
5. Click on the ‘Serial Port’ tab and select the serial port that the PICAXE cable is
connected to. Click ‘OK’
6. Start a new flowchart by clicking the File>New Flowchart menu.
7. Draw the flowchart by dragging the correct symbols onto the screen, and then using
the mouse to draw arrows between the symbols.
8. Once the flowchart is complete it can be converted into a BASIC program by
selecting Flowchart>Convert Flowchart to BASIC. The BASIC program can then be
downloaded into the PICAXE by clicking the PICAXE>Run menu.
9. To print or save the flowchart, use the File menu options. To export the flowchart as
a graphic file, use the File>Export menu. To publish the image in a Word document
select file type EMF. To publish the flowchart on an internet web page use the GIF
file type.
This manual suits for next models
1
Table of contents
Popular Microcontroller manuals by other brands

ST
ST STM32L496 Series Application note

Freescale Semiconductor
Freescale Semiconductor MPC5634M manual

Littlebits
Littlebits BUBBLE BOT manual

GigaDevice Semiconductor
GigaDevice Semiconductor GD32F403 Series user manual

I2SE
I2SE Powerline Bundle for Internet of Things quick start guide

ST
ST STM32 Nucleo user manual

Fujitsu
Fujitsu MB88121 SERIES Application note

Texas Instruments
Texas Instruments Hercules RM48 user guide

Texas Instruments
Texas Instruments MSP-EXPCC430RF Series user guide

BECKWITH ELECTRIC
BECKWITH ELECTRIC M-2601 Instruction book

Texas Instruments
Texas Instruments Stellaris LM3S9B96 user manual

Renesas
Renesas V853 user manual