abhishek n chatraniNikhil ChoudharyNitin Sharma
Published

Pollution control & Status

A smart pollution control device is set near the exhaust of the vehicle to alert the user when they are wasting fuel and causing pollution

AdvancedProtip24 hours9,380
Pollution control & Status

Things used in this project

Story

Read more

Schematics

Arduino 101 & MQ - 135 Sensor

Connect A0 in MQ 135 to Analog pin 0
Connect Vcc in MQ135 to 5V in Arduino 101\
Connect GND in MQ135 to GND in Arduino 101

CIRCUIT DIAGRAM

Arduino 101 and sensor conenction

APK

Code

code.ino

Arduino
#include <CurieBLE.h>


BLEPeripheral blePeripheral;              // BLE Peripheral Device (the board you're programming)
BLEService PollutionService("19b10001-e8f2-537e-4f6c-d104768a1214"); // BLE Pollution Service


BLEIntCharacteristic data("19b10000-e8f2-537e-4f6c-d104768a1214", BLERead | BLEWrite | BLENotify);  // remote clients will be able to get notifications if this characteristic changes
                              
int counter=0;
void setup() {
  Serial.begin(9600);    // initialize serial communication
  pinMode(13, OUTPUT);   // initialize the LED on pin 13 to indicate when a central is connected

  /* Set a local name for the BLE device
     This name will appear in advertising packets
     and can be used by remote devices to identify this BLE device
     The name can be changed but maybe be truncated based on space left in advertisement packet */
  blePeripheral.setLocalName("PollutionSketch");
  blePeripheral.setAdvertisedServiceUuid(PollutionService.uuid());  // add the service UUID
  blePeripheral.addAttribute(PollutionService);   // Add the BLE Heart Rate service
  blePeripheral.addAttribute(data); // add the Heart Rate Measurement characteristic

  /* Now activate the BLE device.  It will start continuously transmitting BLE
     advertising packets and will be visible to remote BLE central devices
     until it receives a new connection */
  blePeripheral.begin();
  Serial.println("Bluetooth device active, waiting for connections...");
}

void loop() 
{
  // listen for BLE peripherals to connect:
  BLECentral central = blePeripheral.central();

  // if a central is connected to peripheral:
  if (central) 
  {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());
    // turn on the LED to indicate the connection:
    digitalWrite(13, HIGH);

    // check the heart rate measurement every 200ms
    // as long as the central is still connected:
    while (central.connected()) 
    {
      int sendData;
      int pollution = analogRead(A0);
      if(pollution>=790)          //790 indicates high pollution
      {
        counter++;                //counter updates when value is greater than or equal to 790
      }                           //counter is updated till 4000 if pollution is above 790 for 4 seconds continuously
      else if(counter<790)        //if value is lesser than 790 counter is reset to 0
      {
        counter=0;
      }
      if(counter=>4000)           //counter is checked for value of 4000 indicating 4 seconds. 
      {                           
        sendData=4;               //indicates high pollution
        data.setValue(sendData);  // and update the pollution status
        counter=0;                //counter is reset to 0.
      }
      else
      {
         sendData=0;               //indicates moderate pollution
        data.setValue(sendData);  // and update the pollution status
      }
     }
  
    // when the central disconnects, turn off the LED:
    digitalWrite(13, LOW);
    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
    }
}

Credits

abhishek n chatrani

abhishek n chatrani

1 project • 14 followers
Entrepreneur | Mechanical Engineer | Innovator | Realist
Nikhil Choudhary

Nikhil Choudhary

0 projects • 1 follower
Nitin Sharma

Nitin Sharma

0 projects • 2 followers
An hobbyist and entrepreneur. Co-founded streak helmets.

Comments