Interfacing MH-Z16 CO2 sensor with PBP?


+ Reply to Thread
Results 1 to 8 of 8

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

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

    Thanks!

    So since pulse duration is so long, instead of pulsin I can use something like
    WHILE PIN=1 A=A+1 and then count number of A's ?

    For the analog output, my particular sensor does not have it, I talked to manufacturer (I bought sensor directly from them), they said this is optional feature and had to be noted when ordering the sensor.

    Arduino library for the sensor is available, I'll try to connect to it later and check that way.

  2. #2
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

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

    I just tried this, but it always returns 0...

    puka:
    IF PWIN=1 THEN
    X=X+1
    ELSE
    LCDOUT $FE, $C0, DEC x, " "
    PAUSE 100
    x=0
    ENDIF
    GOTO PUKA

  3. #3
    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.

  4. #4
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

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

    Thanks a lot!
    Will check it tomorrow.

  5. #5
    Join Date
    Feb 2013
    Posts
    1,124


    Did you find this post helpful? Yes | No

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

    Just tried this code, it works fine, "High" displays readings consistent with actual CO2 concentrations, LOW displays some fixed numbers which only slightly change.

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