Skip to main content

Read chlorine

What this example shows​

The library's bridgeBoard example starts the board at its default address, 0x30, and prints the gas concentration in ppm every 2.5 s. It is the same example as the Quick Start.

The example creates the sensor with SENSOR_CO, the carbon monoxide preset. The library calculates ppm from the preset's sensitivity and gain settings; the preset for this board's chlorine cell is SENSOR_CL2.

The example code​

The example's comments say the address is set with jumpers on the back of the board and that LMPEN is hardwired to GND. On this board the ADDRESS switch on the top side sets the address (0x30 by default). A 10 kΩ resistor holds LMPEN low and it is wired to the ATtiny404, so you leave it unconnected (see Hardware Details).

Select Board
bridgeBoard.ino
/**
**************************************************
*
* @file bridgeBoard.ino
* @brief See how to init a sensor on the new ATtiny404 bridge board revision,
*
* To successfully run the sketch:
* - Set the desired address using the jumpers on the back of the board
* (address = 0x30 + jumper offset, giving a range of 0x30-0x37)
* - Run the sketch and open serial monitor at 115200 baud!
*
* Note: on this board revision, LMPEN is hardwired to GND, so there's
* no configPin argument to pass - the constructor's third argument
* is ignored whenever the address falls in the bridge range (0x30-0x37).
*
*
* @authors @ soldered.com
***************************************************/

// Include the required library
#include "Electrochemical-Gas-Sensor-SOLDERED.h"

// Any additional boards on the same bus just need a different jumper setting
// (0x30-0x37), same as twoSensors.ino does for legacy boards with 0x49/0x4A/0x4B.
ElectrochemicalGasSensor sensor(SENSOR_CO, 0x30);

void setup()
{
Serial.begin(115200); // For debugging

// Init the breakout
if (!sensor.begin())
{
// Can't init? Notify the user and go to infinite loop
Serial.println("ERROR: Can't init the sensor! Check connections and jumper address!");
while (true)
delay(100);
}

Serial.println("Sensor initialized successfully!");
}

void loop()
{
// Make the reading
double reading = sensor.getPPM();

// If PPB is more relevant for your sensor, you can use:
// double reading = sensor.getPPB();

// Print the reading with 5 digits of precision
Serial.print("Sensor reading: ");
Serial.print(reading, 5);
Serial.println(" PPM");

// Wait a bit before reading again
delay(2500);
}

Expected result:

Serial MonitorAutoscrollShow timestampNewline115200 baud
Message (Enter to send message to the board)
Sensor initialized successfully!

Then a line every 2.5 s: Sensor reading: , the concentration in ppm with five decimals, and PPM. If the board does not answer, the sketch prints ERROR: Can't init the sensor! Check connections and jumper address! and stops.

Functions used​

ElectrochemicalGasSensor(sensorType _t, uint8_t _adcAddr = DEFAULT_ADC_ADDR, int _configPin = -1)returns ElectrochemicalGasSensor

Creates the sensor object. It stores the settings only; nothing is sent to the board until begin().

ReturnsThe sensor object.

Parameters

TypeNameDescription
sensorType_tThe cell preset. The example passes SENSOR_CO; this board's SGX-4CL2 cell has the preset SENSOR_CL2.
uint8_t_adcAddrThe I2C address, DEFAULT_ADC_ADDR (0x49) when left out. For an address from 0x30 to 0x37, the range of this board's ADDRESS switch, begin() talks to the board's ATtiny404; the example passes 0x30, the board's default. For any other address begin() looks for an ADS1115 at that address and the LMP91000 directly on the bus.
int_configPinA GPIO that begin() drives low while it configures the LMP91000 directly. -1 (none) when left out. Unused for addresses 0x30 to 0x37.
bool begin()returns bool

Starts Wire, checks that the board answers, sends it the preset's ADC gain and data rate, and configures the LMP91000 with the preset's gain, load, reference, zero and bias settings. Call it once in setup() before reading. Each exchange with the board waits up to 500 ms for an answer.

Returnstrue when the board answered and both configuration steps succeeded, false otherwise.

double getPPM()returns double

Takes one reading and converts it to ppm: it subtracts the internal zero voltage (the 2.5 V reference times the preset's internal zero percentage), adds the zero calibration, divides by the amplifier gain and by the preset's sensitivity in nA per ppm. A result below zero is returned as 0.

ReturnsThe gas concentration in ppm.

double getPPB()returns double

Same reading as getPPM(), times 1000. The example shows it in a comment as the alternative to getPPM().

ReturnsThe gas concentration in ppb.

The example also uses Serial and delay(), which come with the Arduino core, not with this library.

Putting it together​

begin() does all the setup, so loop() only calls getPPM() and prints the result. To read in ppb instead, swap the getPPM() line for the getPPB() line in the comment below it.