Rtc ds3231

Does anyone want to help me in making my project in the form of: watering the plants using two sensors, a soil moisture sensor and a DS3231 RTC sensor. Where does this tool work by reading two conditions including: when the time shows 08.00 and the soil moisture sensor reads with humidity <= 50 then watering will be done. but when the soil moisture sensor reads soil moisture> = 50 then watering is not done, even though the time schedule is read correctly. for the day of sailing, it is not done because there is no watering schedule, and in the afternoon the watering is carried out according to the way of working in the morning.

#thank you
#Please help

First of all I am sorry to say NO ONE HERE WILL WRITE THE CODE FOR YOU.
But we can give ideas or suggest on how to move with the project.

First thing is to find a code for DS3231. Try to turn on and off a LED on specified time(this same thing can be done using Blynk’s RTC widget). If this works well next search for a soil moisture sensor code, make it work.

Now merge both code together add BLYNK to the code. Make sure the loop part is empty, because you will later need to be running only Blynk.run and timer.run in the loop. Rest all the functions will be called by a timer.

Once you have this basic code you can post it here if it doesnt work. So we can help you out.

–’’–’’–’’–
Madhu

There are very few scenarios where a hardware RTC is needed when using Blynk.
The Blynk RTC widget will update the Time library with the correct time on a regular basis when there is an internet connection.
If there is no internet connection then the ESP8266’s internal clock gives good accuracy over quite a long period of time.
The only situation where actual time synchronisation can’t be achieved is when the ESP8266 restarts and there is no internet signal to synchronise the time with the Blynk server.

There are a number of excellent plant watering examples on the forum. I’d suggest that you check them out.

Pete.

#include <SPI.h>  // not used here, but needed to prevent a RTClib compile error
#include "RTClib.h"
#include <LiquidCrystal_I2C.h> // Library for LCD
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
 
RTC_DS1307 RTC;     // Setup an instance of DS1307 naming it RTC

const int pumpStart1 = 14;
const int pumpStart2 = 12;
const int pumpStart3 = 13;
bool on=HIGH;
bool off=LOW; 

const int sensorPin = A0;
int sensorState = 0;
int lastState = 0;

void setup () 
{
  Serial.begin(9600); // Set serial port speed
  lcd.init();
  lcd.backlight();

  pinMode(pumpStart1,OUTPUT);
  pinMode(pumpStart2,OUTPUT);
  pinMode(pumpStart3,OUTPUT);
  
  RTC.begin();  // Init RTC
  //RTC.adjust(DateTime(__DATE__, __TIME__));  // Time and date is expanded to date and time on your computer at compiletime
  //RTC.adjust(DateTime(2021, 1, 15, 14, 45, 0)); 
  Serial.print('Time and date set');
  lcd.setCursor(0, 0);
  lcd.print("Real Time Clock");
  delay(3000);
  lcd.clear();
}
 
void loop () {
  sensorState=analogRead(sensorPin);
  lastState= map(sensorState,0,750,100,0);
  Serial.print("ADC: ");
  Serial.println(sensorState);
  Serial.print("Soil: ");
  Serial.println(lastState);
 
 DateTime now = RTC.now();
   if (now.hour() == 16 && now.minute() >= 53 && now.minute() < 5 && lastState <= 50)
  {
    digitalWrite(pumpStart1,on);
  }
  else 
  {
    digitalWrite(pumpStart1,off); 
  }
  
  lcd.setCursor(6, 0);
  lcd.print(now.year(), DEC);
  lcd.print(":");
  lcd.print(now.month(), DEC);
  lcd.print(":");
  lcd.print(now.day(), DEC);
 
  lcd.setCursor(6, 1);
  lcd.print(now.hour(), DEC);
  lcd.print(":");
  lcd.print(now.minute(), DEC);
  lcd.print(":");
  lcd.print(now.second(), DEC); 
  delay(1000);
  lcd.clear();
}

I have tried to make this program why pumpstart1 does not turn on when both the time schedule conditions and soil moisture are in accordance with the programming.

please give me some help, to solve this problem.

There are so many things wrong with this sketch that it’s difficult to know where to begin!

I’d recommend that you do some additional research and find someone who has written a better piece of code to use as your starting point.
If you’re planning to use Blynk then I’d suggest that you start with the Blynk RTC examples in Sketch Builder, then add the hardware RTC Sync in there later.
If you aren’t planning to use Blynk then I think you’ve come to the wrong forum :grinning:

Pete.

Did you try what Mr. @PeteKnight said ? A quick search in the forum gave me -

you can study the code and try to add the required bits n pieces to it like RTC etc…

You must take this seriously.