Created
March 10, 2016 12:20
-
-
Save bassdread/33a2c8ec3c7dd1ff43af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <DHT.h> | |
#include <Wire.h> | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_BMP085.h> | |
#define DHTPIN 2 | |
#define DHTTYPE DHT22 | |
DHT dht(DHTPIN, DHTTYPE); | |
int LDR_Pin = A0; | |
int MOISTURE_1_Pin = A1; | |
int MOISTURE_2_Pin = A2; | |
int pump = 10; | |
Adafruit_BMP085 bmp = Adafruit_BMP085(10085); | |
String inputString = ""; | |
boolean stringComplete = false; // whether the string is complete | |
const int pin = A0; // Analog input pin | |
unsigned long duration; | |
float Res0=10.0; | |
int photocellReading0; | |
void setup(){ | |
Serial.begin(9600); | |
pinMode(pump, OUTPUT); | |
/* Initialise the sensor */ | |
if(!bmp.begin()) | |
{ | |
/* There was a problem detecting the BMP085 ... check your connections */ | |
Serial.print("Ooops, no BMP085 detected ... Check your wiring or I2C ADDR!"); | |
while(1); | |
} | |
dht.begin(); | |
} | |
void loop(){ | |
sensors_event_t event; | |
bmp.getEvent(&event); | |
if (event.pressure) { | |
int photocellReading0 = analogRead(LDR_Pin); | |
float Vout0=photocellReading0 * 0.0048828125; // calculate the voltage | |
int lux0 = 500 / (Res0*((5-Vout0)/Vout0)); | |
float temperature1 = dht.readTemperature(); | |
float temperature2; | |
bmp.getTemperature(&temperature2); | |
float temperature = (temperature2 + temperature1) / 2; | |
Serial.print("{\"light\":"); | |
Serial.print(lux0); | |
Serial.print(","); | |
/* Display atmospheric pressue in hPa */ | |
Serial.print("\"pressure\":"); | |
Serial.print(event.pressure); | |
Serial.print(","); | |
Serial.print("\"temperature\":"); | |
Serial.print(temperature); | |
float h = dht.readHumidity(); | |
Serial.print(", \"humidity\":"); | |
Serial.print(h); | |
/* | |
Serial.print(","); | |
int moisture_1 = analogRead(MOISTURE_1_Pin); | |
int moisture_2 = analogRead(MOISTURE_2_Pin); | |
Serial.print("\"waterlevel\":"); | |
Serial.print(moisture_1); | |
Serial.print(","); | |
Serial.print("\"moisture\":"); | |
Serial.print(moisture_2); | |
*/ | |
Serial.println("}"); | |
} | |
if (stringComplete) { | |
inputString.replace("\n",""); | |
if (inputString == "on") | |
{ | |
digitalWrite(pump, HIGH); | |
} | |
if (inputString == "off") | |
{ | |
digitalWrite(pump, LOW); | |
} | |
// clear the string: | |
inputString = ""; | |
stringComplete = false; | |
} | |
delay(3000); //just here to slow down the output for easier reading | |
} | |
void serialEvent() { | |
while (Serial.available()) { | |
// get the new byte: | |
char inChar = (char)Serial.read(); | |
// add it to the inputString: | |
inputString += inChar; | |
// if the incoming character is a newline, set a flag | |
// so the main loop can do something about it: | |
if (inChar == '\n') { | |
stringComplete = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment