Vous êtes sur la page 1sur 12

#include "DHT.

h" //DHT Sesnor Library

#include <LiquidCrystal.h> // Library for Liquid Crystal Display

#include <Adafruit_BMP085.h>

#include <Wire.h>

//**************************Variables Required for


DHT11****************************************

#define DHTPIN 7 // what digital pin we're connected to

#define DHTTYPE DHT11 // DHT 11

// Connect - terminal of the sensor to GROUND of Arduino Board

// Connect s terminal to Arduino Digital Pin# 7(DHTPIN)

// Connect the centre terminal to the 5V terminal of Arduino Board (on the right)

// of the sensor to GROUND

//***********************************************************************************
***********

//****************************Interfacing LCD to
Arduino****************************************

//LCD 1 to breadboard negative power rail

//LCD 2 to breadboard positive power rail

//LCD 3 to potentiometer centre pin // this helps to change the LCD brightness

//LCD 4 to Arduino Digital Pin 12 // Arduino sends LCD data (LCD character
coordinates)

//LCD 5 to breadboard negative power rail

//LCD 6 to Arduino Digital Pin 13 // Arduino sends LCD data (LCD initiate command)

//LCD 11 to Arduino Digital Pin 5 // Arduino sends LCD data

//LCD 12 to Arduino Digital Pin 4 // Arduino sends LCD data

//LCD 13 to Arduino Digital Pin 3 // Arduino sends LCD data


//LCD 14 to Arduino Digital Pin 2 // Arduino sends LCD data

//LCD 15 to breadboard positive power rail

//LCD 16 to breadboard negative power rail

//***********************************************************************************
***********

long cm1, cm2;

String s1="WELCOME", s2="VVITIANS-7", s3="RURAL


BRIDGE",s4="FROM",s5="VVIT",s6="Initializing",s7="DONE!!";

String moislevel;

int ph_pin = A1;//Pin to which PH Sensor is Connected

//***********************************************************************************
**********

LiquidCrystal lcd(12, 13, 5, 4, 3, 2);

DHT dht(DHTPIN, DHTTYPE);

Adafruit_BMP085 bmp;

//***********************Variables for Ultra Sonic


Sensor*************************************

// * VCC connection of the sensor attached to +5V

// * GND connection of the sensor attached to ground

//UV Sensor-1 GROUND WATER LEVEL DETECTION

//UV Sensor-2 SURFACE WATER LEVEL DETECTION

// * TRIG1 connection of the sensor attached to digital pin 14

// * ECHO1 connection of the sensor attached to digital pin 15


// * TRIG1 connection of the sensor attached to digital pin 17

// * ECHO1 connection of the sensor attached to digital pin 18

int pressure;

const int trigPin1 = 14;

const int echoPin1 = 15;

const int trigPin2 = 17;

const int echoPin2 = 18;

//***********************************************************************************
*********

void setup()

Serial.begin(9600);

lcd.begin(16,2); //16 by 2 character display

lcd.clear();

lcd.setCursor(5,0);

lcd.print(s1);

delay(1500);

lcd.clear();

lcd.setCursor(4,0);

lcd.print(s2);

lcd.setCursor(4,1);

lcd.print(s3);

delay(1500);

lcd.clear();

lcd.setCursor(6,0);
lcd.print(s4);

lcd.setCursor(6,1);

lcd.print(s5);

delay(1500);

lcd.clear();

lcd.setCursor(3,0);

lcd.print(s6);

delay(2500);

lcd.clear();

lcd.setCursor(6,0);

lcd.print(s7);

dht.begin();

Serial.println("Temperature Sensor Initialized...");

if (!bmp.begin())

Serial.println("Pressure Sensor Not Initialized.");///if there is an error in


communication

// while (1) {}

Serial.println("Pressure Sensor Initialized...");

void loop()

delay(2000);
//******************************Code For DHT Sensor
****************************************

//delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!

// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)

float h = dht.readHumidity();

// Read temperature as Celsius (the default)

float t = dht.readTemperature();

// Read temperature as Fahrenheit (isFahrenheit = true)

float f = dht.readTemperature(true);

Serial.print("Humidity: ");

Serial.print(h);

Serial.print(" %\t");

Serial.print("Temperature: ");

Serial.print(t);

Serial.println(" *C ");

// Serial.print(f);

// Serial.println(" *F\t");

// Check if any reads failed and exit early (to try again).

if (isnan(h) || isnan(t) || isnan(f)) {

Serial.println("Failed to read from DHT sensor!");

return;
}

// delay(2000);

//*****************************End of DHT Sensor


Code***************************************

//***************************Code For Pressure Sensor


**************************************

pressure = bmp.readPressure();

pressure=pressure/100;

Serial.print("Pressure in hPa: ");

Serial.println(pressure);

//*****************************End of Pressure Sensor


Code**********************************

//***************************Code For PH Sensor


********************************************

int measure = analogRead(ph_pin);

Serial.print("Measure: ");

Serial.println(measure);

double voltage = 5 / 1024.0 * measure; //classic digital to voltage conversion

Serial.print("\tVoltage: ");

Serial.print(voltage, 3);

// PH_step = (voltage@PH7 - voltage@PH4) / (PH7 - PH4)

// PH_probe = PH7 - ((voltage@PH7 - voltage@probe) / PH_step)

float Po = 7 + ((2.5 - voltage) / 0.18);

Po = Po + 5;
Serial.print("\tPH: ");

Serial.println(Po, 3);

// delay(2000);

//**************************End of Code for PH


Sensor**************************************

//**************************Code For Soil Moisture


Sensor***********************************

int sensorValue = analogRead(A2);

if (sensorValue >= 820)

moislevel = "V - LOW";

Serial.print(moislevel);

Serial.println(sensorValue);

else if (sensorValue >= 615 && sensorValue < 820)

moislevel = "LOW";

Serial.print(moislevel);

Serial.println(sensorValue);

else if (sensorValue >= 410 && sensorValue < 615)

moislevel = "AVG";

Serial.print(moislevel);

Serial.println(sensorValue);
}

else if (sensorValue >= 250 && sensorValue < 410)

moislevel = "HIGH";

Serial.println(sensorValue);

else if (sensorValue >= 0 && sensorValue < 250)

moislevel = "V - HIGH";

Serial.println(sensorValue);

//**************************End of Code for Soil Moisture Sensor


***************************

//*************************Code for Ultra Sonic Sensor


*************************************

// establish variables for duration of the ping,

// and the distance result in inches and centimeters:

long duration1, inches1, duration2, inches2 ;

// The sensor is triggered by a HIGH pulse of 10 or more microseconds.

// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

pinMode(trigPin1, OUTPUT);

digitalWrite(trigPin1, LOW);

pinMode(trigPin2, OUTPUT);
digitalWrite(trigPin2, LOW);

delayMicroseconds(2);

digitalWrite(trigPin1, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin1, LOW);

digitalWrite(trigPin2, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin2, LOW);

// Read the signal from the sensor: a HIGH pulse whose

// duration is the time (in microseconds) from the sending

// of the ping to the reception of its echo off of an object.

pinMode(echoPin1, INPUT);

duration1 = pulseIn(echoPin1, HIGH);

pinMode(echoPin2, INPUT);

duration2 = pulseIn(echoPin2, HIGH);

// convert the time into a distance

inches1 = microsecondsToInches(duration1);

inches2 = microsecondsToInches(duration2);

cm1 = microsecondsToCentimeters(duration1);

cm2 = microsecondsToCentimeters(duration2);

Serial.print("G W L ::");

Serial.print(cm1);
Serial.print("cm, ");

Serial.print("S W L ::");

Serial.print(cm2);

Serial.println("cm");

//************************End Code for Ultrasonic Sensor


**********************************

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Humd= ");

lcd.print(h);

lcd.print(" %RH");

lcd.setCursor(0,1);

lcd.print("Temp = ");

lcd.print(t);

lcd.print(" ");

lcd.print(char(0xDF));

lcd.print("C");

delay(2500);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Pressure: ");

lcd.print(pressure);

lcd.setCursor(10,1);

lcd.print("hPa");

delay(2500);

lcd.clear();
lcd.setCursor(0,0);

lcd.print("Moist Level");

lcd.setCursor(5,1);

lcd.print(moislevel);

delay(2500);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("Soil pH: ");

lcd.print(Po);

delay(2500);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("G W L: ");

lcd.setCursor(8,1);

lcd.print(cm1);

lcd.print("cm");

delay(2500);

lcd.clear();

lcd.setCursor(0,0);

lcd.print("S W L: ");

lcd.setCursor(8,1);

Serial.println(cm2);

lcd.print("cm");

delay(2500);

}
long microsecondsToInches(long microseconds)

// According to Parallax's datasheet for the PING))), there are

// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per

// second). This gives the distance travelled by the ping, outbound

// and return, so we divide by 2 to get the distance of the obstacle.

// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf

return microseconds / 74 / 2;

long microsecondsToCentimeters(long microseconds)

// The speed of sound is 340 m/s or 29 microseconds per centimeter.

// The ping travels out and back, so to find the distance of the

// object we take half of the distance travelled.

return microseconds / 29 / 2;

Vous aimerez peut-être aussi