FIDUST - Find the Fine Dust

measure the fine dust rate using the dust sensor, we can check the dust rate lively and FIDUST automatically open and close the window.

121
FIDUST - Find the Fine Dust

Things used in this project

Story

Read more

Schematics

Schematics of Fidust

Code

Arduino Code

Arduino
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3, POSITIVE); 


int window = 9;
//open : HIGH
//close : LOW 

int redPin = 7;
int greenPin = 6;
int bluePin = 5;

void setup() 
{
  lcd.begin(16,2);
  lcd.setBacklight(HIGH);
  pinMode(8,INPUT);
  Serial.begin(115200);
  Serial2.begin(115200);
  pinMode(5,OUTPUT);//b
  pinMode(6,OUTPUT);//g
  pinMode(7,OUTPUT);//r
  pinMode(9,OUTPUT);//window
}

unsigned long pulse = 0;
float ugm3 = 0;

void loop() 
{
  Serial2.println("Fine Dust rate : ");
  Serial2.print(ugm3,1);
  Serial2.println(" [ug/m3]");
  
  pulse=pulseIn(8,LOW,20000);
  ugm3=pulse2ugm3(pulse);
  
  lcd.setCursor(0,0);
  lcd.print("Fine Dust rate :");
  lcd.setCursor(0,1);
  lcd.print(ugm3,1);
  lcd.print(" [ug/m3]");
  
  if(ugm3>=0&&ugm3<=15){//clean
    displayColor("green", 0, 255, 0, 0);
    digitalWrite(window,HIGH);
    delay(1000);
  }
  else if(ugm3>15&&ugm3<=50){//average
    displayColor("orange", 255, 120, 0, 0);
    digitalWrite(window,HIGH);
    delay(1000);
  }
  else if(ugm3>50){//bad
    displayColor("red", 255, 0, 0, 0);
    digitalWrite(window,LOW);
    delay(1000);
  }
  delay(2000);
}

float pulse2ugm3(unsigned long pulse)
{
  float value=(pulse-1400)/14.0;
  if(value>300)
  {
    value=0;
  }
  return value;
}

void displayColor(String color, int r, int g, int b, unsigned long mills){
  Serial.println(color);
  setColor(r,g,b);
  delay(mills);
}

void setColor(int red, int green, int blue){
  analogWrite(redPin,red);
  analogWrite(greenPin,green);
  analogWrite(bluePin, blue);
}

Wiznet Code

C/C++
#include "mbed.h"
#include "SPI.h"
#include "MQTTEthernet.h"
#include "MQTTClient.h"

#define ECHO_SERVER_PORT   7
 
Serial pc(USBTX, USBRX);   //Enabling the Serial transmission between WIZ750SR and PC.
Serial serial(D1,D0);      // Enabling Serial transmission betwenn Wiz750SR and W7500. 
char c[100]="";
 
int main(void) {
    printf("Wait a second...\r\n");
    char* topic = "Vending machine";
    MQTTEthernet ipstack = MQTTEthernet();
    
    MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack);
    
    char* hostname = "172.16.73.4";   //Give the IP Address of the MQTT Broker.
    int port = 1883;                  // Port number of the MQTT broker.  
    
 
    int rc = ipstack.connect(hostname, port);
    if (rc != 0)
    printf("rc from TCP connect is %d\n", rc);
    printf("Topic: %s\r\n",topic);
    
    MQTTPacket_connectData data = MQTTPacket_connectData_initializer;       
    data.MQTTVersion = 3;
    data.clientID.cstring = "parents";

    if ((rc = client.connect(data)) == 0)
    printf("rc from MQTT connect is %d\n", rc);
 
   while (true) {
    if (serial.readable()) // if anything available/ readable in Serial port 
    {
        int i;
        c[i]=0;
        for(i=0;i<=4;i++){
        char c1 =serial.getc();
        c[i] = c1;
    
    }
     MQTT::Message message;
     char buf[100];
     sprintf(buf, "%s", c);
     message.qos = MQTT::QOS0;
         message.retained = false;
         message.dup = false;

         message.payload = (void*)c;
         message.payloadlen = strlen(c);

         rc = client.publish("Dust", message);
         client.yield(60);
             }
}
}

Credits

Yongtae Cheon

Yongtae Cheon

1 project • 0 followers
Changmin Kang

Changmin Kang

0 projects • 0 followers
Jaewoong Choi

Jaewoong Choi

0 projects • 0 followers
Seungtaek Woo

Seungtaek Woo

0 projects • 0 followers

Comments