4382billy
Published © GPL3+

Arduino Powered Emission Control System

NOx reduction from exhaust air using selective catalyst reduction method.

IntermediateWork in progress329
Arduino Powered Emission Control System

Things used in this project

Story

Read more

Code

EMCOSYS XXI KDU , EMISSION CONTROL SYSTEM

Arduino
#include <OneWire.h>
#include <DS18B20.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>

const byte ONEWIRE_PIN = 2;
byte sensorAddress1[8] = {0x28, 0xFF, 0x35, 0x26, 0x86, 0x16, 0x4, 0xF3};
byte sensorAddress2[8] = {0x28, 0xFF, 0x67, 0x20, 0x86, 0x16, 0x4, 0xEC};
int g1,g2,g3,t1,t2,conv,perc;
float p1,p2;
OneWire onewire(ONEWIRE_PIN);
DS18B20 sensors(&onewire);
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

int thValue = 200;

void setup() {
  sensors.begin();
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial2.begin(9600);
  pinMode(22, OUTPUT);
  pinMode(24, OUTPUT);
  bmp.begin();

}

void loop() {
  tempRead();
  readGas();
  displaySensorDetails();
  readProMini();
  printSerial();
  lcdDisplay();
}


void tempRead() {
  sensors.request(sensorAddress1);
  t1 = sensors.readTemperature(sensorAddress1);
  while (!sensors.available());
  sensors.request(sensorAddress2);
  t2 = sensors.readTemperature(sensorAddress2);
}

void readGas(){
  g1 = analogRead(A0);
  g2 = analogRead(A1) + 60;
  g3 = analogRead(A2) + 75;
  if(g1>g2){
    conv=1;
    perc=(g3-g1)*100/g3;
  }else{
    conv=2;
    perc=(g3-g2)*100/g3;
  }
  
  if (g3 > thValue)
  {
    digitalWrite(24, HIGH);
    delay(1000);
    digitalWrite(24, LOW);
    delay(1000);
    alarm();
  }
  else {
    digitalWrite(22, HIGH);
    digitalWrite(24, HIGH);
  }
}

void displaySensorDetails(){
  sensors_event_t event;
  bmp.getEvent(&event);
  if (event.pressure)
  {
    p1=event.pressure;
    p1=p1/1000;
  }
  else
  {
    Serial.println("Sensor error");
  }
  delay(1000);
}

void readProMini(){
  Serial1.flush();
  while(!Serial1.available()){
  }
  Serial1.read();
    String text =  Serial1.readStringUntil(13);
    
    if(text.startsWith("P")){
      text = text.substring(1);
      float x = text.toInt();
      if(x>900){
        p2=x/1000;
      }      
    }
}

void printSerial(){
  Serial.print(g1);
  Serial.print("  ");
  Serial.print(g2);
  Serial.print("  ");
  Serial.print(g3);
  Serial.print("  ");
  Serial.print(t1);
  Serial.print("  ");
  Serial.print(t2);
  Serial.print("  ");
  Serial.print(p1);
  Serial.print("  ");
  Serial.print(p2);
  Serial.println("  ");
}

void lcdDisplay(){
  printData("t0",t2);
  printDataFloat("t1",p1);
  printData("t2",t1);
  printDataFloat("t3",p2);
  printData("t4",conv);
  printData("t5",perc);
}

void printData(String id, int val){
  Serial2.print(id);
  Serial2.print(".txt=");
  Serial2.write(0x22);
  Serial2.print(val);
  if(id=="t5"){
    Serial2.print("%");
  }
  Serial2.write(0x22);
  Serial2.write(0xff);
  Serial2.write(0xff);
  Serial2.write(0xff);
  delay(100);
}

void printDataFloat(String id, float val){
  Serial2.print(id);
  Serial2.print(".txt=");
  Serial2.write(0x22);
  Serial2.print(val,2);
  Serial2.write(0x22);
  Serial2.write(0xff);
  Serial2.write(0xff);
  Serial2.write(0xff);
  delay(100);
}

void alarm(){
  tone(48,800);
  delay(500);
  tone(48,1500);
  delay(500);
  noTone(48);
}

Credits

4382billy

4382billy

0 projects • 0 followers

Comments