Gas Sensor with arduino nano

Hi all,
Can I connect a gas sensor with Arduino nano sense and train in a edge impulse?
Thanks

Hello @sunim,

Yes you can. You would need to adapt the edge-impulse-data-forwarder script on your arduino to forward your samples to EI studio. More info here: https://docs.edgeimpulse.com/docs/cli-data-forwarder

Just print the values from your sensor in the serial console at a chosen frequency. How do you read the values from your gas sensor? Is it an analog device such as the MQ135? If so, I would do something like that:

#define FREQUENCY_HZ        50
#define INTERVAL_MS         (1000 / (FREQUENCY_HZ + 1))

static unsigned long last_interval_ms = 0;
const int gasPin = A0;

void setup() {
    Serial.begin(115200);
    Serial.println("Started");
}

void loop() {
    float gasValue;

    if (millis() > last_interval_ms + INTERVAL_MS) {
        last_interval_ms = millis();
        gasValue = analogRead(gasPin);
        //Add some conversion or calibration here if needed
        Serial.println(gasValue); 
    }
}

Then for the inference, you’ll need to store the gas sensor values in a features buffer. You can find some more info here: https://docs.edgeimpulse.com/docs/running-your-impulse-locally-1#input-to-the-run_classifier-function

Regards,

Louis

3 Likes