Maintenance: Project Hub will be unavailable on Monday 24 (9AM to 6PM CET) while we deploy critical improvements
Components and supplies
LED Strip, 10 "
Water level sensor
Resistor 100 ohm
DHT11 Temperature & Humidity Sensor (3 pins)
Arduino Nano R3
Photo resistor
Buzzer
Pump 12V
Gravity: Analog Soil Moisture Sensor For Arduino
Tools and machines
Plant pot
Project description
Code
Smart_plant
c_cpp
1//import librairies 2#define FASTLED_INTERNAL 3#include <FastLED.h> 4#include <DHT.h> 5 6//define pins 7#define PHOTO_PIN A7 //analog pin photoresistor 8#define WATER_PIN A0 //analog pin water sensor 9#define BUZZ_PIN 10 //digital pin buzzer 10#define DHTPIN 9 // Digital pin connected to the DHT sensor 11#define LED_PIN 11 //digital pin led 12#define NUM_LEDS 10 //number of led of the strip 13#define DHTTYPE DHT11 // model od dht 14#define MOISTURE_PIN A4 //analog soil moisture pin 15#define RELAY_PIN A5 // analog IN pin of relay 16 17 18DHT dht(DHTPIN, DHTTYPE); 19CRGB leds[NUM_LEDS]; 20 21int water_value; //value of the water sensor 22int photo_value; // store the value from photoresistor (0-1023) 23int moisture_value; //store the value from the soil moisture 24 25void setup() { 26 27 Serial.begin(9600); //sets data rate to 115200 bps 28 FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); 29 Serial.println("DHT test"); 30 dht.begin(); 31 FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); 32 pinMode(PHOTO_PIN,INPUT); 33 pinMode(WATER_PIN,INPUT); 34 pinMode(BUZZ_PIN,OUTPUT); 35 pinMode(RELAY_PIN, OUTPUT); 36 delay(1000); 37 38} 39 40void loop() { 41 //read the value of the moisture sensor 42 moisture_value= analogRead(MOISTURE_PIN); 43 moisture_value = map(moisture_value,0,1023,0,100); 44 Serial.print("Moisture : "); 45 Serial.print(moisture_value); 46 Serial.println("%"); 47 48 //If the soil is dry the relay is on 49 if (moisture_value >= 37){ 50 digitalWrite(RELAY_PIN, LOW); // turn on the pump 51 Serial.print("Pump On"); 52 Serial.print(RELAY_PIN); 53 } 54 else{ 55 digitalWrite(RELAY_PIN, HIGH); // turn off the pump 56 Serial.print("Pump Off"); 57 Serial.print(RELAY_PIN); 58 } 59 //read photoresistor value 60 int analog_value = analogRead(PHOTO_PIN); 61 int photo_value = map(analog_value, 0, 1023, 0, 100);// read value’s current range to value’s target range 62 while (photo_value > 50){ // while is daylight do the project otherwise nothing is activated 63 64 Serial.print("photoresistor = "); 65 Serial.print(photo_value); 66 Serial.print(" "); Serial.print("\ 67"); 68 69 //Read Water Value 70 water_value = analogRead(WATER_PIN); 71 72 if (water_value < 3050 && water_value > 0){ //the buzzer makes sound if the level of water is too low 73 //read buzz sensor 74 digitalWrite(BUZZ_PIN,HIGH); 75 delay(100); 76 digitalWrite(BUZZ_PIN,LOW); 77 delay(100); 78 79 Serial.print("Water box low"); 80 Serial.print(" | "); 81 } 82 else if (water_value == 0){ 83 Serial.print("Water box empty !!!!!"); 84 Serial.print(" | "); 85 } 86 else{ 87 Serial.print("Water box level OK"); 88 Serial.print("\ 89"); 90 Serial.print(" "); 91 } 92 //turn on the led strip 93 for (int i = 0; i < water_value; ++i) { 94 leds[i] = CRGB(255, 255, 0); 95 FastLED.show(); 96 //delay(500); 97 } 98//turn off the led strip 99 for (int i = water_value; i > 0; --i) { 100 leds[i] = CRGB(0, 0, 0); 101 FastLED.show(); 102 } 103//read temperature + humidity sensor 104 float h = dht.readHumidity(); 105 float t = dht.readTemperature();//as celsius 106 107 if(isnan(h) || isnan(t)){ 108 Serial.println("Failed to read DHT sensor"); 109 Serial.println(""); 110 return; 111 } 112 113 //Display message 114 Serial.print("Humidity :"); 115 Serial.print(h); 116 Serial.print("%"); 117 Serial.print(" | "); 118 Serial.print("Temperature :"); 119 Serial.print(t); 120 Serial.print("°C"); 121 Serial.print("\ 122"); 123 Serial.print("\ 124"); 125 Serial.print("Level Water = "); 126 Serial.print(water_value); 127 Serial.print("\ 128"); 129 Serial.print(" "); 130 delay(500); 131 } 132}
Smart_plant
c_cpp
1//import librairies 2#define FASTLED_INTERNAL 3#include <FastLED.h> 4#include <DHT.h> 5 6//define pins 7#define PHOTO_PIN A7 //analog pin photoresistor 8#define WATER_PIN A0 //analog pin water sensor 9#define BUZZ_PIN 10 //digital pin buzzer 10#define DHTPIN 9 // Digital pin connected to the DHT sensor 11#define LED_PIN 11 //digital pin led 12#define NUM_LEDS 10 //number of led of the strip 13#define DHTTYPE DHT11 // model od dht 14#define MOISTURE_PIN A4 //analog soil moisture pin 15#define RELAY_PIN A5 // analog IN pin of relay 16 17 18DHT dht(DHTPIN, DHTTYPE); 19CRGB leds[NUM_LEDS]; 20 21int water_value; //value of the water sensor 22int photo_value; // store the value from photoresistor (0-1023) 23int moisture_value; //store the value from the soil moisture 24 25void setup() { 26 27 Serial.begin(9600); //sets data rate to 115200 bps 28 FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); 29 Serial.println("DHT test"); 30 dht.begin(); 31 FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); 32 pinMode(PHOTO_PIN,INPUT); 33 pinMode(WATER_PIN,INPUT); 34 pinMode(BUZZ_PIN,OUTPUT); 35 pinMode(RELAY_PIN, OUTPUT); 36 delay(1000); 37 38} 39 40void loop() { 41 //read the value of the moisture sensor 42 moisture_value= analogRead(MOISTURE_PIN); 43 moisture_value = map(moisture_value,0,1023,0,100); 44 Serial.print("Moisture : "); 45 Serial.print(moisture_value); 46 Serial.println("%"); 47 48 //If the soil is dry the relay is on 49 if (moisture_value >= 37){ 50 digitalWrite(RELAY_PIN, LOW); // turn on the pump 51 Serial.print("Pump On"); 52 Serial.print(RELAY_PIN); 53 } 54 else{ 55 digitalWrite(RELAY_PIN, HIGH); // turn off the pump 56 Serial.print("Pump Off"); 57 Serial.print(RELAY_PIN); 58 } 59 //read photoresistor value 60 int analog_value = analogRead(PHOTO_PIN); 61 int photo_value = map(analog_value, 0, 1023, 0, 100);// read value’s current range to value’s target range 62 while (photo_value > 50){ // while is daylight do the project otherwise nothing is activated 63 64 Serial.print("photoresistor = "); 65 Serial.print(photo_value); 66 Serial.print(" "); Serial.print("\ 67"); 68 69 //Read Water Value 70 water_value = analogRead(WATER_PIN); 71 72 if (water_value < 3050 && water_value > 0){ //the buzzer makes sound if the level of water is too low 73 //read buzz sensor 74 digitalWrite(BUZZ_PIN,HIGH); 75 delay(100); 76 digitalWrite(BUZZ_PIN,LOW); 77 delay(100); 78 79 Serial.print("Water box low"); 80 Serial.print(" | "); 81 } 82 else if (water_value == 0){ 83 Serial.print("Water box empty !!!!!"); 84 Serial.print(" | "); 85 } 86 else{ 87 Serial.print("Water box level OK"); 88 Serial.print("\ 89"); 90 Serial.print(" "); 91 } 92 //turn on the led strip 93 for (int i = 0; i < water_value; ++i) { 94 leds[i] = CRGB(255, 255, 0); 95 FastLED.show(); 96 //delay(500); 97 } 98//turn off the led strip 99 for (int i = water_value; i > 0; --i) { 100 leds[i] = CRGB(0, 0, 0); 101 FastLED.show(); 102 } 103//read temperature + humidity sensor 104 float h = dht.readHumidity(); 105 float t = dht.readTemperature();//as celsius 106 107 if(isnan(h) || isnan(t)){ 108 Serial.println("Failed to read DHT sensor"); 109 Serial.println(""); 110 return; 111 } 112 113 //Display message 114 Serial.print("Humidity :"); 115 Serial.print(h); 116 Serial.print("%"); 117 Serial.print(" | "); 118 Serial.print("Temperature :"); 119 Serial.print(t); 120 Serial.print("°C"); 121 Serial.print("\ 122"); 123 Serial.print("\ 124"); 125 Serial.print("Level Water = "); 126 Serial.print(water_value); 127 Serial.print("\ 128"); 129 Serial.print(" "); 130 delay(500); 131 } 132}
Downloadable files
Schematics
Schematics
Comments
Only logged in users can leave comments