Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 23rd January 2005, 10:23 PM   (permalink)
Default simple alcohol sensor project,how do i read inputs(PICBASIC)

hi i am trying to use a pic to sense for alcohol content, i am going to be using a pot as the sensor as we cannot get hold of one. therefore i want to mimic the circuit. basically all i want it to do is light either and led stating "dont drive" or "ok to drive". So i was going to have two inputs there for if the voltage input to one pin is higher than the other(reference) i want the led to come one.

The problem is i am unsure how to read inputs into a pic, i have made the code below, i have not tested it yet but before i do i wanted to make sure i have not missed anything out.

P.S the delay is put in there for the heater in the sensor (not being used in this case)

Finally i have never wired up a PIC using the internal occilator. do i just need to add 5V and 0V anything else i need to add?

'************************************************* ***************
'* Name : groupproject.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 23/01/2005 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************

xtal=4 '4mhz

symbol LED = Portb.0 'Delay on led
symbol LED2 = Portb.1 'output led1
symbol LED3 = Portb.2 'output led2
SYMBOL PIN1 = PORTB.3 'inputs
SYMBOL PIN2 = PORTB.4 'inputs
INPUT PORTB.3 'defining input
INPUT PORTB.4 'defining input
Delayms 40000 'sensor warm up time 40secs
High LED 'sensor warm led on after 40secs

Start: 'start
Low LED2 'led off
Low LED3 'led off
IF PIN1 > PIN2 THEN High LED2 'if pin1 is less than pin2 make led come on
IF PIN2 > Pin1 THEN High LED3 'if pin2 is less than pin1 make led come on
Goto Start 'go back to start
lompa is offline  
Old 24th January 2005, 12:41 AM   (permalink)
Default

i think the above is wrong i have now changed it to this, P.S the value "50" is totally random at the moment.

************************************************** **************
'* Name : groupproject.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2005 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 23/01/2005 *
'* Version : 1.0 *
'* Notes : *
'* : *
'************************************************* ***************

xtal=4 '4mhz
DIM VAR1 as BYTE
symbol LED = Portb.0 'Delay on led
symbol LED2 = Portb.1 'output led1
symbol LED3 = Portb.2 'output led2
'SYMBOL PIN1 = PORTB.3 'inputs
'SYMBOL PIN2 = PORTB.4 'inputs
INPUT PORTB.3 'defining input
'INput PORTB.4 'defining input
Low LED2 'led off
Low LED3 'led off
Delayms 40000 'sensor warm up time 40secs
High LED 'sensor warm led on after 40secs

Start: 'start
VAR1 = POT PORTB.3 , 255
IF VAR1 > 50 THEN High LED2 'if pin1 is less than pin2 make led come on
IF VAR1 < 50 THEN High LED3 'if pin2 is less than pin1 make led come on
Goto Start 'go back to start



the problem with this method is there are only 255 steps over a wide resistance range there for sensing a very small change is not possible, is there a way round this?
lompa is offline  
Old 24th January 2005, 09:00 AM   (permalink)
Default

Quote:
Originally Posted by lompa
the problem with this method is there are only 255 steps over a wide resistance range there for sensing a very small change is not possible, is there a way round this?
255 steps is 8 bit resolution, which should be more than enough - bear in mind it's giving better than 0.5% resolution! - which is going to be more than the rest of your circuit.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is online now  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 04:20 PM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker