Ok, here goes! So I'm basically building a system to control my garden water tank system. Automatic overflow system via pump, watering plants and all that jazz... especially when I'm not around!
Got the code all working using the 'Non-contact' water sensor with a matrix display and decided I needed a timer circuit to set the times for the 'Watering' part of the system. The problem aired when I added the timer and programming to the sketch... nothing would work, at first I thought it was a clock or address confliction with the Matrix display. Basically the call for RTC.read function from library would err.
Took the whole thing apart to narrow down the issue, and it turns out to be the XKC Y25 sensor, every time I hook it to the board it stops the clock cycle and impairs the RTC. function. I'm hoping somebody with a better understanding of electronics can resolve the issue. I reckon it's some issue with it being a capacitance device.
The board I originally put everything together on was an Mega2560, everything worked sweet, without the timer element. Once that was added all halted. So just focussing using this code:
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
//#define HARDWARE_TYPE MD_MAX72XX::GENERIC_HW
// Display Size and CS Pin
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES); // CLK_PIN, CS_PIN, MAX_DEVICES);
int i = 0;
void setup() {
Serial.begin(9600);
pinMode(3, INPUT);
while (!Serial) ; // wait for serial
delay(200);
Serial.println("DS1307RTC Read Test");
Serial.println("-------------------");
myDisplay.begin();
myDisplay.setIntensity(5);
myDisplay.displayClear();
}
void loop() {
tmElements_t tm;
if (RTC.read(tm)) {
i = i + 1;
myDisplay.print(i);
Serial.print("Ok, Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
//delay(2000);
} else {
if (RTC.chipPresent()) {
Serial.println("The DS1307 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
} else {
Serial.println("DS1307 read error! Please check the circuitry.");
Serial.println();
}
delay(9000);
}
delay(1000);
}
void print2digits(int number) {
if (number >= 0 && number < 10) {
Serial.write('0');
}
Serial.print(number);
}
Circuit is as simple as it is, but now using a leonardo instead of the Mega. Just the power rail via an SDEC and a sep DESK PSU regulated output 5v with shared ground as it should be. Even if I connect the sensor... the clock will kinda halt, or rather the RTC.#### function call to library ceases to execute, and power consumption is negligible 10 ~ 30 mA at most!
So this is the image, the matrix is basically just showing the incrementing integer 'i' so I could see when the devices halted after trying numerous experiments to solve the issue.
IF I remove the XKC Y25 output from any of the digital inputs/pins with or without declaration I can connect VCC to sensor or vica-versa, but ground/VCC/output cannot be all connected.
From the image you will also see a relay board connected... but I only just added that to test other avenues to solve the problem.
Driving me bonkers, as this is the only hurdle holding me back before I can final assemble and deploy. All help welcome guys n gals.
Forgot to add, I got the sensor from Amazon and use it with logic 1 on output on detection of water:
EDIT: I should've also added I got the whole thing working on the Mega, timer and all, using straight logic '1' wire for sensor input whilst testing. When I replaced the straight logic with sensor outfit... No go!




