Components and supplies
1
Jumper wires (generic)
1
Relay Module (Generic)
1
USB-A to B Cable
1
oled display ssd1306 128x32 with i2c(blue)
1
Breadboard (generic)
1
Arduino Nano R3
1
soil moisture sensor fc-28
Tools and machines
1
Tape, Electrical
1
Hot glue gun (generic)
1
Soldering iron (generic)
1
Solder Wire, Lead Free
Apps and platforms
1
Arduino IDE
Project description
Code
Plant Watering System With Oled isplay script
c_cpp
1// needed libraries 2#include <Wire.h> 3#include <Adafruit_GFX.h> 4#include <Adafruit_SSD1306.h> 5 6#define SCREEN_WIDTH 128 // OLED display width, in pixels 7#define SCREEN_HEIGHT 32 // OLED display height, in pixels 8 9// declare an SSD1306 display object connected to I2C 10Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); 11 12const int dry = 500; //the value at which the plant is dry 13 14const int pumpPin = 10; //pump connected to pin 10 15const int soilSensor = A0; //the soil moisture sensor reads the value from the analog pin A0 16 17void setup() { 18 Serial.begin(9600); 19 20 // initialize OLED display with address 0x3C for 128x64 21 if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { 22 Serial.println(F("SSD1306 allocation failed")); 23 while (true); 24 } 25 26 delay(2000); // wait for initializing 27 oled.clearDisplay(); // clear display 28 29 oled.setTextSize(4); // text size 30 oled.setTextColor(WHITE); // text color 31 oled.setCursor(0, 0); // position to display 32 oled.println("Hello"); //inscription when switching on 33 oled.display(); //activating the screen 34 delay(3000); 35 36 //oled Loading script 37 oled.clearDisplay(); 38 oled.setCursor(0, 0); 39 oled.setTextSize(3); 40 oled.println("Loading"); 41 oled.setCursor(80, 12); 42 oled.setTextSize(3); 43 44 //loading animation(dots) 45 oled.println("."); 46 oled.display(); 47 delay(1000); 48 oled.setCursor(95, 12); 49 oled.setTextSize(3); 50 oled.println("."); 51 oled.display(); 52 delay(1000); 53 oled.setCursor(110, 12); 54 oled.setTextSize(3); 55 oled.println("."); 56 oled.display(); 57 58 //water intake by a pump 59 pinMode(pumpPin, OUTPUT); 60 pinMode(soilSensor, INPUT); 61 Serial.begin(9600); 62 digitalWrite(pumpPin, HIGH); 63 delay(500); 64} 65 66void loop() { 67 delay(1000); 68 oled.clearDisplay(); 69 70 oled.setTextSize(2); 71 oled.setTextColor(WHITE); 72 oled.setCursor(0, 0); 73 oled.println("Fern :) "); //the name of your plant that will be visible all the time 74 oled.display(); 75 76 // read current moisture 77 int moisture = analogRead(soilSensor); 78 Serial.println(moisture); 79 oled.setTextSize(1); 80 oled.println("value: " + String(moisture)); 81 oled.display(); 82 delay(5000); 83 84 if (moisture >= dry) { 85 // the soil is too dry, water! 86 Serial.println("Watering starts now..moisture is " + String(moisture)); 87 oled.println("watering required"); 88 oled.display(); 89 digitalWrite(pumpPin, LOW); 90 91 92 // keep watering for 5 sec 93 delay(2000); 94 95 // turn off water 96 digitalWrite(pumpPin, HIGH); 97 Serial.println("Done watering."); 98 oled.setTextSize(2); 99 oled.setCursor(0, 0); 100 oled.clearDisplay(); 101 oled.println("Done "); 102 oled.println("Watering"); 103 oled.display(); 104 } else { 105 Serial.println("Moisture is adequate. No watering needed " + String(moisture)); 106 oled.println("watering not required"); 107 oled.display(); 108 } 109} 110
Plant Watering System With Oled isplay script
c_cpp
1// needed libraries 2#include <Wire.h> 3#include <Adafruit_GFX.h> 4#include 5 <Adafruit_SSD1306.h> 6 7#define SCREEN_WIDTH 128 // OLED display width, in 8 pixels 9#define SCREEN_HEIGHT 32 // OLED display height, in pixels 10 11// declare 12 an SSD1306 display object connected to I2C 13Adafruit_SSD1306 oled(SCREEN_WIDTH, 14 SCREEN_HEIGHT, &Wire, -1); 15 16const int dry = 500; //the value at which the 17 plant is dry 18 19const int pumpPin = 10; //pump connected to pin 10 20const 21 int soilSensor = A0; //the soil moisture sensor reads the value from the analog 22 pin A0 23 24void setup() { 25 Serial.begin(9600); 26 27 // initialize OLED 28 display with address 0x3C for 128x64 29 if (!oled.begin(SSD1306_SWITCHCAPVCC, 30 0x3C)) { 31 Serial.println(F("SSD1306 allocation failed")); 32 while (true); 33 34 } 35 36 delay(2000); // wait for initializing 37 oled.clearDisplay(); 38 // clear display 39 40 oled.setTextSize(4); // text size 41 oled.setTextColor(WHITE); 42 // text color 43 oled.setCursor(0, 0); // position to display 44 45 oled.println("Hello"); //inscription when switching on 46 oled.display(); 47 //activating the screen 48 delay(3000); 49 50 //oled Loading script 51 52 oled.clearDisplay(); 53 oled.setCursor(0, 0); 54 oled.setTextSize(3); 55 56 oled.println("Loading"); 57 oled.setCursor(80, 12); 58 oled.setTextSize(3); 59 60 61 //loading animation(dots) 62 oled.println("."); 63 oled.display(); 64 65 delay(1000); 66 oled.setCursor(95, 12); 67 oled.setTextSize(3); 68 oled.println("."); 69 70 oled.display(); 71 delay(1000); 72 oled.setCursor(110, 12); 73 oled.setTextSize(3); 74 75 oled.println("."); 76 oled.display(); 77 78 //water intake by a 79 pump 80 pinMode(pumpPin, OUTPUT); 81 pinMode(soilSensor, INPUT); 82 Serial.begin(9600); 83 84 digitalWrite(pumpPin, HIGH); 85 delay(500); 86} 87 88void loop() { 89 delay(1000); 90 91 oled.clearDisplay(); 92 93 oled.setTextSize(2); 94 oled.setTextColor(WHITE); 95 96 oled.setCursor(0, 0); 97 oled.println("Fern :) "); //the name of your plant 98 that will be visible all the time 99 oled.display(); 100 101 // read current 102 moisture 103 int moisture = analogRead(soilSensor); 104 Serial.println(moisture); 105 106 oled.setTextSize(1); 107 oled.println("value: " + String(moisture)); 108 oled.display(); 109 110 delay(5000); 111 112 if (moisture >= dry) { 113 // the soil is too dry, 114 water! 115 Serial.println("Watering starts now..moisture is " + String(moisture)); 116 117 oled.println("watering required"); 118 oled.display(); 119 digitalWrite(pumpPin, 120 LOW); 121 122 123 // keep watering for 5 sec 124 delay(2000); 125 126 // 127 turn off water 128 digitalWrite(pumpPin, HIGH); 129 Serial.println("Done 130 watering."); 131 oled.setTextSize(2); 132 oled.setCursor(0, 0); 133 oled.clearDisplay(); 134 135 oled.println("Done "); 136 oled.println("Watering"); 137 oled.display(); 138 139 } else { 140 Serial.println("Moisture is adequate. No watering needed " + 141 String(moisture)); 142 oled.println("watering not required"); 143 oled.display(); 144 145 } 146} 147
Downloadable files
Plant Watering System With Oled Display
Plant Watering System With Oled Display

Comments
Only logged in users can leave comments