Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Akhil MalikChirag Sharma
Created April 30, 2017 © GPL3+

SWAN-PD

A all in one handy and portable device (Soil, Water, Air, Noise Pollution Detector) which is a IOT based portable environment analyzer.

IntermediateWork in progress74
SWAN-PD

Things used in this project

Story

Read more

Schematics

Schematic

Code

Arduino

Arduino
#include <LiquidCrystal.h>
#include <DHT.h>
#include <SoftwareSerial.h>

SoftwareSerial GSerial(2,3); // RX, TX    // GSM
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);

int measurePin = A3;
int ledPower = 11;
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
float voMeasured = 0; float calcVoltage = 0; float dustDensity = 0;


#define DHTPIN A5
#define DHTTYPE DHT22 
DHT dht(DHTPIN, DHTTYPE);

float temp,humidity;
int sound, moisture;
int turbidity;
float dust;
unsigned long previousMillis;
/*******************************************************************************************/
void sound_reading() 
{
  int i;
  long avg_val = 0;
  for(i=0;i<1000;i++)
  {
    avg_val += analogRead(A1);
  }
  avg_val/=1000;
  sound = map(avg_val,200,1023,0,100);
  GSerial.print("<N");GSerial.print(sound);GSerial.println(">");
}
/*******************************************************************************************/
void soil_reading() 
{
    moisture = analogRead(A4);
    moisture = map(moisture, 900, 200, 0, 100);
    GSerial.print("<S");GSerial.print(moisture);GSerial.println(">");
}
/*******************************************************************************************/
void read_turbidity()
{
  int i;
  int turb;
  long avg_val = 0;
  for(i=0;i<100;i++)
  {
    avg_val += analogRead(A2);
  }
  avg_val/=100;
  turbidity = map(avg_val, 885, 50, 0, 500);
  GSerial.print("<B");GSerial.print(turbidity);GSerial.println(">");
}
/*******************************************************************************************/
int read_temp()
{
   temp = dht.readTemperature();
   GSerial.print("<T");GSerial.print(temp);GSerial.println(">");
}
/*******************************************************************************************/
int read_humidity()
{
  humidity = dht.readHumidity();
  GSerial.print("<H");GSerial.print(humidity);GSerial.println(">");
}
/*******************************************************************************************/
void sensor_value_display()
{
  lcd.clear();
  lcd.setCursor(0, 0);lcd.print(moisture);
  lcd.setCursor(5, 0);lcd.print(temp,1);
  lcd.setCursor(11, 0);lcd.print(humidity);
  lcd.setCursor(0, 1);lcd.print(sound);
  lcd.setCursor(5, 1);lcd.print(turbidity);
  lcd.setCursor(11, 1);lcd.print(dust);
}
//*************************************************
void measure_dust_sensor(){
  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);
  voMeasured = analogRead(measurePin); // read the dust value
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
  dustDensity = 0.17 * calcVoltage - 0.1;
  dust = dustDensity;
  Serial.print("Dust : ");Serial.println(dust);
  delay(1000);
}
/*******************************************************************************************/
void setup() 
{
  Serial.begin(9600);
  GSerial.begin(9600);
  pinMode(ledPower, OUTPUT);
  lcd.begin(16, 2);
  lcd.print(" Swan PD System ");
  lcd.setCursor(0, 1);
  //lcd.print("     System     ");
  delay(2000);   
  lcd.clear(); 
  dht.begin(); 
  previousMillis = millis();
}
/*******************************************************************************************/
void loop()
{
  read_temp();delay(100);
  read_humidity();delay(100);
  soil_reading();delay(100);
  sound_reading();delay(100);
  read_turbidity();delay(100);
  measure_dust_sensor();delay(100);
  if(millis() - previousMillis > 1000)
  {
    sensor_value_display();  
  }
  if(millis() - previousMillis > 30000)
  {
    lcd.clear();lcd.print("Uploading...");
    GSerial.print("<U>");
    previousMillis = millis();
    delay(1000);lcd.clear();
  }
}
/*******************************************************************************************/

Credits

Akhil Malik

Akhil Malik

1 project • 0 followers
Chirag Sharma

Chirag Sharma

1 project • 0 followers

Comments