vilaswkhade
Published © GPL3+

Nose Lab: Edge AI smell classifier

Edge AI E-nose: train the neural net in your browser, export a standalone Arduino Uno sketch. No Python, no cloud, no PC after uplo

IntermediateFull instructions provided1,747
Nose Lab: Edge AI smell classifier

Things used in this project

Story

Read more

Schematics

Enose_circuit

Use 5 Volt/2 Amp DC supply for MQ series Sensor!

Code

Enose.ino

C/C++
// ENose Uno — On-Demand 6xMQ Reader
// MQ-2(A0) MQ-3(A1) MQ-4(A2) MQ-5(A3) MQ-7(A4) MQ-135(A5)
//
// Command protocol:
//   "Snn\n" -> burst of nn readings (SETTLE_MS between each)
//   "L\n"   -> live stream at 4 Hz
//   "X\n"   -> stop streaming
// Sends "READY\n" on boot. All output is 6-value CSV.

#define SETTLE_MS  150
#define STREAM_MS  250

bool streaming = false;
unsigned long lastStream = 0;
String cmdBuf = "";

void sendReading() {
  Serial.print(analogRead(A0)); Serial.print(",");
  Serial.print(analogRead(A1)); Serial.print(",");
  Serial.print(analogRead(A2)); Serial.print(",");
  Serial.print(analogRead(A3)); Serial.print(",");
  Serial.print(analogRead(A4)); Serial.print(",");
  Serial.println(analogRead(A5));
}

void setup() {
  Serial.begin(9600);
  Serial.println("READY");
}

void loop() {
  while (Serial.available() > 0) {
    char c = (char)Serial.read();
    if (c == '\n' || c == '\r') {
      cmdBuf.trim();
      if (cmdBuf.length() == 0) { cmdBuf = ""; continue; }
      if (cmdBuf == "L") { streaming = true; lastStream = 0; }
      else if (cmdBuf == "X") { streaming = false; }
      else if (cmdBuf.startsWith("S")) {
        streaming = false;
        int n = cmdBuf.substring(1).toInt();
        if (n < 1) n = 1; if (n > 99) n = 99;
        for (int i = 0; i < n; i++) {
          sendReading();
          if (i < n - 1) delay(SETTLE_MS);
        }
      }
      cmdBuf = "";
    } else { cmdBuf += c; }
  }
  if (streaming) {
    unsigned long now = millis();
    if (now - lastStream >= STREAM_MS) { lastStream = now; sendReading(); }
  }
}

Credits

vilaswkhade
3 projects • 16 followers

Comments