Shop OBEX P1 Docs P2 Docs Learn Events
Simple Q: How do I capture 0-5v input voltages? — Parallax Forums

Simple Q: How do I capture 0-5v input voltages?

BigMikeBigMike Posts: 34
edited 2009-05-18 08:54 in Accessories
Hello Parallax,

I am sure this is rather simple but after reading a ton of sensor pdf files on this site I have been unsuccessful at finding an example that applies to me.

The sensor programs I've seen use sensor devices that have a differing resistance (photocell) or some pulsein or pulseout or use serin serial stuff.

What I have is a very simple automotive pressure sensor with the following 3 terminals:

a- Ground
b- Output (positive 0-5 v)
c- +5 volts

All I want to do is read the output signal of this device with my stamp. The signal will vary from 0 - 5.0 volts lineally based on a pressure input port.

I am using my old BS2 HomeWork board.
So what I have is the ground connected to Vss and the +5 volts connected to Vdd.

I connected the sensor's output to P1 using a 330 ohm resistor.

All I need to know if what is the code used to read a positive input value ?

I already have a 4 line blue LCD screen that I am using to print the value out to, so the value needs to be stored as a variable.

Thank you very much in advance!!!!
BigMike

Comments

  • BigMikeBigMike Posts: 34
    edited 2009-05-01 02:39
    Forgot to specify that the output is just good ol' DC.


    Basically, a very, very, very simple question that will answer everything I need could be how do I connect a AA 1.2 volt Duracell battery for example?

    What code do I use to read how much positive voltage the battery currently has? Once I learn how to do this, I can use this pressure sensor [noparse]:)[/noparse]

    Thanks
    Mike
  • BigMikeBigMike Posts: 34
    edited 2009-05-01 02:42
    I am going to keep playing with RCTime and a capacitor for now...
  • FranklinFranklin Posts: 4,747
    edited 2009-05-01 03:36
    You could also use an adc. Parallax just happens to sell them.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2009-05-01 03:55
    Parallax sells several different ADCs (analog to digital converters). The webstore page for each has links to documentation and sample code. If you just need one channel, an ADC0831 will do very nicely. There are examples of its use in the StampWorks Manual and in the Basic Analog and Digital tutorial, both of which are available for free download from Parallax

    www.parallax.com/Store/Components/IntegratedCircuits/InterfacingChips/tabid/613/CategoryID/78/List/0/SortField/0/Level/a/ProductID/245/Default.aspx
  • BigMikeBigMike Posts: 34
    edited 2009-05-01 04:20
    Really! I already have one of those and I used it to measure temperature from a LM-34 temp sensor.

    So the automotive pressure sensor I have outputs an Analog voltage output and my BS2 requires a digital input?

    I will start working on this immediately, thanks for the tip!
  • BigMikeBigMike Posts: 34
    edited 2009-05-01 04:28
    ah Ha!

    I got it! I am using the following program for this:

    ' -----[noparse][[/noparse] Declarations ]----------------------------------------------------
    adcBits VAR Byte
    
    ' -----[noparse][[/noparse] Initialization ]--------------------------------------------------
    CS PIN 15
    CLK PIN 6
    DataOutput PIN 5
    
    DEBUG CLS 'Start display.
    
    ' -----[noparse][[/noparse] Main Routine ]----------------------------------------------------
    DO
    GOSUB ADC_Data
    GOSUB Display
    PAUSE 100
    LOOP
    
    ' -----[noparse][[/noparse] Subroutines ]-----------------------------------------------------
    ADC_Data:
    HIGH CS
    LOW CS
    LOW CLK
    PULSOUT CLK, 210
    SHIFTIN DataOutput,CLK,MSBPOST,[noparse][[/noparse]adcBits\8]
    RETURN
    
    Display:
    DEBUG HOME
    DEBUG "8-bit binary value: ", BIN8 adcBits
    DEBUG CR, CR, "Decimal Value: ", DEC4 adcBits
    RETURN
    



    I am playing with two pots hooked up to the circuit and I can only seem to get adcBits valves from 0 to 255. I change the variable to a Word and not a Byte but it still only goes up to 255. It is reaching 255 when the pressure sensor is at about 25% of it's maximum value.

    How can I increase this range?
  • BigMikeBigMike Posts: 34
    edited 2009-05-01 05:00
    Ok, I figured it out, it is simply fine tuning the potentiometers!
  • FranklinFranklin Posts: 4,747
    edited 2009-05-02 00:20
    Also you have to remember a Byte can only be a number from 0 to 255 so if you need a bigger number you need to use a Word.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • BigMikeBigMike Posts: 34
    edited 2009-05-02 05:41
    Thanks for the reply Franklin. Your advice has already been considered:

    "I change the variable to a Word and not a Byte but it still only goes up to 255"

    It is working great and today I got a lot of data logged and am about ready to transfer it to a motorcycle.

    Thanks for everyone's help!
    Mike
  • FranklinFranklin Posts: 4,747
    edited 2009-05-02 18:06
    If yoiu look at your shiftin command you are asking for 8 bits so it will only show 255 try \16 instead

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • vadivadi Posts: 2
    edited 2009-05-17 22:50
    i need 3v to 6v pir circuit diagram.example pir sensor on 3v motor work
  • vadivadi Posts: 2
    edited 2009-05-18 08:54
    i seen some pir sensor switch work 4.5v.that circuit diagram i need
Sign In or Register to comment.