Panteltje's co_pic_udp a POE ethernet connected CO sensor.

This design is for <= 24V POE, do not use 48V with this LM2596 chip.

This project is released under the GPL license

Circuit diagram:

The PCBs and sensor in the box:

The closed box:

The displayed menu via the serial link at 115200 Bd, 1 start bit, 8 data bits, one stop bit, no parity, if you type 'h':

Panteltje (c) co_sensor_udp_MQ-7-0.1

AnnnENTER          set source IP address saved in EEPROM
BnnnENTER          set source IP address saved in EEPROM
CnnnENTER          set source IP address saved in EEPROM
EnnnENTER          set destination IP address saved in EEPROM
FnnnENTER          set destination IP address saved in EEPROM
GnnnENTER          set destination IP address saved in EEPROM
HnnnENTER          set destination IP address saved in EEPROM
LnnnnnENTER      set source port, saved in EEPROM
PnnnnnENTER      set destination port, saved in EEPROM
R                             select fast mode, 4 seconds heater 4 seconds measure
r                              select normal mode, 90 seconds heater, 60 seconds measure, default
S                              show data on serial out, saved in EEPROM
s                              do not show data on serial out, default, saved in EEPROM
V                             verbose
v                             verbose off, default
WnnnnnENTER    CO alarm beeper level, default 17, to disable local alarm beeper use 65535
XnnnENTER         PWM 1.5V level, default 29
h                             help (this)

Output to serial port in mode 'V' verbose:

source IP address
source port 1082
source MAC 01:02:03:04:05:0B
destination IP address
destination port 1082
destination MAC B8:27:EB:0A:2C:43
ADC max level 312 steps
CO alarm level 17 ppm
current PWM 28
PWM 5V level 255
PWM 1.5V level 28
sense resistor voltage 1.524 V
sensor resistance 10719 Ohm
CO level 0 ppm
CO data to serial port
slow mode

Data received at destination IP ( here) one entry about every 150 seconds:
netcat -u -l -p 1082

1 ppm 417 steps 6830 Ohm
0 ppm 405 steps 7174 Ohm
0 ppm 395 steps 7476 Ohm
0 ppm 295 steps 11608 Ohm
0 ppm 385 steps 7793 Ohm
0 ppm 391 steps 7597 Ohm
0 ppm 256 steps 14084 Ohm

Some remarks about the asm code.

This code is assembled with gpasm on Linux, it may not work in Microchip Mplab without changes.
In fact I never use simulators, test and debug via serial link, use scope.
MAC address is fixed and needs to be set in the #define in the asm source file and needs to be unique for your LAN.
Inspection of the MQ-7 datasheet found several conflicting data points, making it difficult to write a function to convert sensor resistance to CO level in ppm.
Both graphs in the datasheet DIFFER!

I noticed several people had a go at writing such a function for this type of sensor, I tried some of those, for example this one,
in my case it did not give anything that made sense..
So I decided to use the best graph from the datasheet, the one that starts at 10 ppm and ends at 1000 ppm, and use a lookup system based on calculated data and values I measured.


The conversion to ppm is now based on the Rsensor versus an Rsensor in 'clean' air of 8000 Ohm.
Then for 0-1 ppm resolution is 1 ppm, for 10 to 100 ppm resolution is 10 ppm (you'd be dead by then), and for 100 to 1000 ppm resolution is 100 ppm.
You can make 1000 ppm by blowing gas from a NON LIT cigarette lighter into the sensor, for lower ppm just breath into it.
OK, as this was my solution, and was simple to implement (only 30 compares in asm), I left better ones possible for others to do it at the receive side,
by also sending ADC steps and calculated sensor resistance via UDP, have fun.
Would it be better? I think not.
If not, then just parse the first ppm field.
The sensor is in series with a 4700 Ohm sense resistor powered from 5 V.
The ADC measures the voltage across the 4700 Ohm resistor, uses the same 5 V as reference, so the number of steps is just the ratio between 4700 and R sensor,
the supply voltage cancels.
This ratio is used to calculate Rsensor, and that Rsensor is also supplied for those who want to make their own function for at the Rx side.

In this version I left out the beeper in the box (it did not fit), maybe later.
The server side monitors for loss of data and too high ppm levels (alarm level set at server side) shows a red light, on screen message, and sounds a really loud beeper in case of alarm.
The sensor software is in a loop that does ARP request, heating , measuring, calculation, and data transmission about every 150 seconds.
When network changes happen then it will adapt itself that way.

Future versions

I would like to add temperature compensation, will add a LM35 temperature sensor on an ADC pin later and send temperature as well as do some correction in the asm.

This archive contains the asm, the Makefile, include files, as well as the MQ-7 sensor datasheet, for assembly gpasm (part of Linux gputis) is required,
however a hex file is included that could be programmed directly into the Microchip PIC 18F14K22,
untar it with
tar -zxvf co_pic_udp-0.1.tgz

The ethernet module is ebay item 170929813328, for POE you need to replace the connector by type HLJ-6115ANL ebay item 271891560407

return to main page