Interfacing MH-Z16 CO2 sensor with PBP?


Results 1 to 8 of 8

Threaded View

  1. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Interfacing MH-Z16 CO2 sensor with PBP?

    More than one issue with that piece of code. For one, you're running at 64MHz so it's probably going to wrap around X variable quite quickly giving you weird results. I'd try something like this:
    Code:
    Th VAR WORD
    Tl VAR WORD
    
    PWIN VAR PORTB.0
    
    
    Main:
        GOSUB Measure
        LCDOUT $FE, $01, "High: ",  DEC Th
        LCDOUT $FE, $C0, "Low: ",   DEC Tl
    GOTO Main
    
    Measure:
      Th = 0
      Tl = 0
    
      WHILE !PWIN : WEND	' Wait for rising edge
    
      WHILE PWIN			' Measure high pulse width
        Th = Th + 1
        PAUSEUS 999
      WEND
    
      WHILE !PWIN			' Measure low pulse width
        Tl = Tl + 1
        PAUSEUS 999
      WEND
    
    RETURN
    Once you have that working, displaying pulsewidth values matching what you see on the scope you can A) increase resolution (if needed) and/or B) calculate PPMs or percentage or whatever you want to display. Small steps...
    Last edited by HenrikOlsson; - 24th December 2024 at 06:21.

Similar Threads

  1. LM 35 Sensor interfacing with PIC16F877A
    By girish09 in forum Code Examples
    Replies: 1
    Last Post: - 7th November 2012, 14:23
  2. KINECT Sensor interfacing with PICs
    By MrRoboto in forum USB
    Replies: 2
    Last Post: - 29th August 2012, 17:43
  3. Temp & Humidity sensor interfacing question
    By tacbanon in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 20th February 2012, 23:12
  4. current sensor interfacing
    By hell_pk in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 29th January 2009, 04:55
  5. CO2 MG811 sensor connection
    By elektoro2009 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 8th May 2008, 00:49

Members who have read this thread : 11

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts