Skip to content

Instantly share code, notes, and snippets.

@digi0ps
Created April 1, 2018 15:51
Show Gist options
  • Save digi0ps/106114074cd8cfb409def21a8978cda5 to your computer and use it in GitHub Desktop.
Save digi0ps/106114074cd8cfb409def21a8978cda5 to your computer and use it in GitHub Desktop.
Code for our garden automation project
#include <dht.h>
// For DHT11 sensor
dht DHT;
// PINS
#define DHT11_PIN A7
#define SMOISTURE_PIN A0
#define PDIODE_PIN A1
#define LED_PIN D5
#define MOTOR_PIN
// Thresholds
#define LIGHT_THRESHOLD 2
#define TEMP_THRESHOLD 28
#define MOISTURE_THRESHOLD 850
void setup() {
Serial.begin(9600);
// Configure these pins as output
pinMode(LED_PIN, OUTPUT);
pinMode(MOTOR_PIN, OUTPUT);
}
void loop() {
// read the input on analog pin 0:
int moistureValue = analogRead(A0);
int chk = DHT.read11(DHT11_PIN);
int tempValue = DHT.temprature;
int pdiodeValue = analogRead(PDIODE_PIN);
float light = pdiodeValue / 1024.0 * 5.0;
// Turn on LED if light under LIGHT_THRESHOLD
if( light < LIGHT_THRESHOLD )
digitalWrite(LED_PIN, HIGH);
else
digitalWrite(LEG_PIN, LOW);
// Turn on motors if temp value is greater than TEMP_THRESHOLD
// and moistureValue greater than MOISTURE_THRESHOLD
if( tempValue > TEMP_THRESHOLD || moistureValue > MOISTURE_THRESHOLD )
analogWrite(MOTOR_PIN, 64);
else
analogWrite(MOTOR_PIN, 0);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment