12.07.2015 Views

PICAXE Manual Section 1 - TechnoPujades - Free

PICAXE Manual Section 1 - TechnoPujades - Free

PICAXE Manual Section 1 - TechnoPujades - Free

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.picaxe.co.uk<strong>Section</strong> 1 65GETTING STARTEDTutorial 6 – Using Analogue SensorsAn analogue sensormeasures a continuoussignal such as light,temperature or position. Theanalogue sensor provides avarying voltage signal. Thisvoltage signal can berepresented by a number inthe range 0 and 255 (e.g.dark = 0, light = 255).Voltage5V0VCommon examples of analogue sensors are:Timelightdark• LDR (Light Dependent Resistor)• Thermistor• Variable Resistor (potentiometer)Using a Light Dependent Resistor (LDR)The LDR is an example of an analogue sensor. It isconnected to the <strong>PICAXE</strong> ADC input in a potential dividerarrangement (e.g. input 1). Note that not all inputs haveADC capabilities - see the pinout diagrams for moreinformation.The value of an analogue input can be easily copied into avariable by use of the ‘readadc’ command. The variablevalue (0 to 255) can then be tested. The following programswitches on one LED if the value is greater than 120 and adifferent LED if the value is less than 70. If the value isbetween 70 and 120 both LEDS are switched off.10kmain:‘ make a label called ‚mainreadadc 1,b0‘ read ADC1 intovariable b0if b0 > 120 then top‘ if b0 > 120 then do topif b0 < 70 then bot‘ if b0 < 70 then do botlow 0 ‘ else switch off 0low 4 ‘ and switch off 4goto main‘ jump back to the starttop:bot:‘ make a labelhigh 0 ‘ switch on 0low 4 ‘ switch off 4goto main‘ jump back to start‘ make a labelhigh 4 ‘ switch on 4low 0 ‘ switch off 0goto main‘ jump back to startrevolution(c) Revolution Education Ltd. Email: info@rev-ed.co.uk Web: www.rev-ed.co.ukVersion 6.9 07/2009All rights reserved.65

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!