Arduino Powered Emission Control System
NOx reduction from exhaust air using selective catalyst reduction method.
Components and supplies
1
Arduino Mega 2560
1
Arduino Pro Mini 328 - 5V/16MHz
1
Pressure/Altitude/Temperature Sensor
Project description
Code
EMCOSYS XXI KDU , EMISSION CONTROL SYSTEM
arduino
1#include <OneWire.h> 2#include <DS18B20.h> 3#include <Wire.h> 4#include <Adafruit_Sensor.h> 5#include <Adafruit_BMP085_U.h> 6 7const byte ONEWIRE_PIN = 2; 8byte sensorAddress1[8] = {0x28, 0xFF, 0x35, 0x26, 0x86, 0x16, 0x4, 0xF3}; 9byte sensorAddress2[8] = {0x28, 0xFF, 0x67, 0x20, 0x86, 0x16, 0x4, 0xEC}; 10int g1,g2,g3,t1,t2,conv,perc; 11float p1,p2; 12OneWire onewire(ONEWIRE_PIN); 13DS18B20 sensors(&onewire); 14Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); 15 16int thValue = 200; 17 18void setup() { 19 sensors.begin(); 20 Serial.begin(9600); 21 Serial1.begin(9600); 22 Serial2.begin(9600); 23 pinMode(22, OUTPUT); 24 pinMode(24, OUTPUT); 25 bmp.begin(); 26 27} 28 29void loop() { 30 tempRead(); 31 readGas(); 32 displaySensorDetails(); 33 readProMini(); 34 printSerial(); 35 lcdDisplay(); 36} 37 38 39void tempRead() { 40 sensors.request(sensorAddress1); 41 t1 = sensors.readTemperature(sensorAddress1); 42 while (!sensors.available()); 43 sensors.request(sensorAddress2); 44 t2 = sensors.readTemperature(sensorAddress2); 45} 46 47void readGas(){ 48 g1 = analogRead(A0); 49 g2 = analogRead(A1) + 60; 50 g3 = analogRead(A2) + 75; 51 if(g1>g2){ 52 conv=1; 53 perc=(g3-g1)*100/g3; 54 }else{ 55 conv=2; 56 perc=(g3-g2)*100/g3; 57 } 58 59 if (g3 > thValue) 60 { 61 digitalWrite(24, HIGH); 62 delay(1000); 63 digitalWrite(24, LOW); 64 delay(1000); 65 alarm(); 66 } 67 else { 68 digitalWrite(22, HIGH); 69 digitalWrite(24, HIGH); 70 } 71} 72 73void displaySensorDetails(){ 74 sensors_event_t event; 75 bmp.getEvent(&event); 76 if (event.pressure) 77 { 78 p1=event.pressure; 79 p1=p1/1000; 80 } 81 else 82 { 83 Serial.println("Sensor error"); 84 } 85 delay(1000); 86} 87 88void readProMini(){ 89 Serial1.flush(); 90 while(!Serial1.available()){ 91 } 92 Serial1.read(); 93 String text = Serial1.readStringUntil(13); 94 95 if(text.startsWith("P")){ 96 text = text.substring(1); 97 float x = text.toInt(); 98 if(x>900){ 99 p2=x/1000; 100 } 101 } 102} 103 104void printSerial(){ 105 Serial.print(g1); 106 Serial.print(" "); 107 Serial.print(g2); 108 Serial.print(" "); 109 Serial.print(g3); 110 Serial.print(" "); 111 Serial.print(t1); 112 Serial.print(" "); 113 Serial.print(t2); 114 Serial.print(" "); 115 Serial.print(p1); 116 Serial.print(" "); 117 Serial.print(p2); 118 Serial.println(" "); 119} 120 121void lcdDisplay(){ 122 printData("t0",t2); 123 printDataFloat("t1",p1); 124 printData("t2",t1); 125 printDataFloat("t3",p2); 126 printData("t4",conv); 127 printData("t5",perc); 128} 129 130void printData(String id, int val){ 131 Serial2.print(id); 132 Serial2.print(".txt="); 133 Serial2.write(0x22); 134 Serial2.print(val); 135 if(id=="t5"){ 136 Serial2.print("%"); 137 } 138 Serial2.write(0x22); 139 Serial2.write(0xff); 140 Serial2.write(0xff); 141 Serial2.write(0xff); 142 delay(100); 143} 144 145void printDataFloat(String id, float val){ 146 Serial2.print(id); 147 Serial2.print(".txt="); 148 Serial2.write(0x22); 149 Serial2.print(val,2); 150 Serial2.write(0x22); 151 Serial2.write(0xff); 152 Serial2.write(0xff); 153 Serial2.write(0xff); 154 delay(100); 155} 156 157void alarm(){ 158 tone(48,800); 159 delay(500); 160 tone(48,1500); 161 delay(500); 162 noTone(48); 163} 164
Comments
Only logged in users can leave comments