MH-Z16 CO2 sensor does not responding

Hi,

I try to use MH-Z16 CO2 (datasheet is here). It uses the UART protocol. I connect it to 5 socket (SUY) to my Mountaineer Ethernet board.
Get power (5 volts) from socket - pin 2. And connect TX to 4 pin and RX to 5 pin. Then I tried to send command to sensor and get response from it. Nothing happens. Write method works silently, but Read method freezes the program. If I use ReadTimeout property method Read returns zero:(. May be I’m doing something wrond again?


using System.IO.Ports;
using System.Threading;

namespace SensorsDebug
{
    public class Program
    {
        public static void Main()
        {
            var s = new SerialPort(Mountaineer.Netmf.Hardware.Socket5.SerialPortName, 9600, Parity.None, 8, StopBits.One);
            s.Open();

            var buf = new byte[] {0xff, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79};
            s.Write(buf, 0, 9);
            s.Flush();

            Thread.Sleep(100);

            var cnt = s.Read(buf, 0, 9);
        }
    }
}

my first thought is you should always try reversing TX and RX pins. Please check the comments on this product for a definition of UART Dyslexia. [url]https://www.sparkfun.com/products/449[/url]. It’s my biggest failure, and I now put jumpers on circuit boards in case I mess it up :slight_smile:

1 Like

@ Brett - :clap: You are right! I reordered RX and TX pins and… it works now!!! Hooray!
Thanks!

1 Like

gets the best of us - as well as me ;D .