Hi,
unfortunately my old thread got closed. (Plant watering project - problem with two digitalWrite actions - #30 by Jogibaer)
I more or less solved the code issue and it works on my arduino UNO test setup. ![]()
Then I soldered everything together, but missed the part to test my setup with an external power supply. Please see the connection diagram and the attached code below.
First I didn't connect the GND of the Arduino with the GND of the external power supply, but I did.
- the Arduino is powered by the external power supply
- all relay modules are powered as well by the external power supply
- the (-) pole of the external power supply is also connected to the GND pin on the Arduino board
My problem or question is:
- The relay module No. 3 is closed (HIGH) all the time therefore it's LED is light up. Do you think the relay No. 3 is faulty?
- When external power is not on, and I connect the Arduino to USB Power only, some relay modules light up slightly or very bright. I checked all connections multiple times, checked for short circuits and so on, but I can't find the mistake or explain it.
- What do you think of my connection diagram, do you see any mistakes?
Edit: Picture updated
/***************************************************************
Project: Pflanzenrettung 5.0 a.k.a. "Plant Redeemer" (by Jogibaer)
***************************************************************/
#include <Adafruit_GFX.h> // Include core graphics library for the display
#include <Adafruit_SSD1306.h> // Include Adafruit_SSD1306 library to drive the display
Adafruit_SSD1306 display(128, 64); // Create display
#include <Fonts/FreeMono9pt7b.h> // Add a custom font
#include <Fonts/DejaVu_Sans_11.h>
int Watertank;
int WaterRelay = 9;
int Olive;
int OliveRelay = 10;
int Papyrus;
int PapyrusRelay = 11;
int Bonsai;
int BonsaiRelay = 12;
int OliveLimit = 500;
int PapyrusLimit = 500;
int BonsaiLimit = 500;
int WatertankLimit = 800;
#define soilSensor_Olive A0
#define soilSensor_Papyrus A1
#define soilSensor_Bonsai A2
#define soilSensor_Watertank A3
// 'Plant_Redeemer', 16x20px, Logo/Bild
const unsigned char PlantRedeemer [] PROGMEM = {
0x06, 0x00, 0x07, 0x80, 0x07, 0x80, 0x07, 0xc0, 0x07, 0xc0, 0x03, 0xc6, 0xfb, 0xdf, 0x7d, 0xbe,
0x3c, 0x3c, 0x1c, 0x30, 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80,
0x00, 0x80, 0x00, 0x00, 0x07, 0xf0, 0x0f, 0xf0
};
void setup()
{
Serial.begin(9600);
pinMode (9, OUTPUT); //Set pin 9 as output for the pump relay
pinMode (10, OUTPUT); //Set pin 10 as output for the relay
pinMode (11, OUTPUT); //Set pin 11 as output for the relay
pinMode (12, OUTPUT); //Set pin 12 as output for the relay
pinMode (A0, INPUT); //Set pin A0 as analog input for a capacitive soil moisture sensor #0 to Olive
pinMode (A1, INPUT); //Set pin A1 as analog input for a capacitive soil moisture sensor #1 to Papyrus
pinMode (A2, INPUT); //Set pin A2 as analog input for a capacitive soil moisture sensor #2 to Bonsai
pinMode (A3, INPUT); //Set pin A3 as analog input for a capacitive soil moisture sensor #3 to Watertank
//OLED**************************************************************************************************************
delay(100); // This delay is needed to let the display to initialize
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize display with the I2C address of 0x3C
display.clearDisplay(); // Clear the buffer
display.setTextColor(WHITE); // Set color of the text
display.setRotation(0); // Set orientation. Goes from 0, 1, 2 or 3
display.setTextWrap(false); // By default, long lines of text are set to automatically “wrap” back to the leftmost column.
// To override this behavior (so text will run off the right side of the display - useful for
// scrolling marquee effects), use setTextWrap(false). To restore it, replace "false" with "true".
display.dim(1); //Set brightness (0 is maximun and 1 is a little dim)
////OLED************************************************************************************************************
}
void loop()
{
Olive = analogRead(soilSensor_Olive);
Papyrus = analogRead(soilSensor_Papyrus);
Bonsai = analogRead(soilSensor_Bonsai);
Watertank = analogRead(soilSensor_Watertank);
Serial.print("Feuchtigkeitswert Olive:");
Serial.println(Olive);
delay(400);
Serial.print("Feuchtigkeitswert Papyrus:");
Serial.println(Papyrus);
delay(400);
Serial.print("Feuchtigkeitswert Bonsai:");
Serial.println(Bonsai);
delay(400);
Serial.print("Watertank Level:");
Serial.println(Watertank);
delay(400);
//OLED**************************************************************************************************************
display.clearDisplay();
display.drawBitmap(1, 1, PlantRedeemer, 16, 20, WHITE);
display.setFont(&DejaVu_Sans_11);
display.setTextSize(0);
display.setCursor(22, 13);
display.print("Plant Redeemer");
display.setTextSize(0);
display.setFont(&FreeMono9pt7b);
display.setCursor(0, 34);
display.print("Olive: ");
display.println(Olive);
display.setCursor(0, 48);
display.print("Papyrus:");
display.println(Papyrus);
display.setCursor(0, 62);
display.print("Bonsai: ");
display.println(Bonsai);
display.display();
////OLED**************************************************************************************************************
if ((Olive < OliveLimit) && (Watertank < WatertankLimit))
{
digitalWrite(OliveRelay, LOW); //meaning the soil is still wet, the relay stays open (NO)
digitalWrite(WaterRelay, LOW); //the water pump will not run
delay(200);
}
else if ((Olive > OliveLimit) && (Watertank < WatertankLimit))
{
digitalWrite(OliveRelay, HIGH); //meaning the plant needs water, therefore the pump needs to run if there is enough water in the tank.
digitalWrite(WaterRelay, HIGH); //the water pump will run
}
delay(200);
//**************************************************************************************************************
if ((Papyrus < PapyrusLimit) && (Watertank < WatertankLimit))
{
digitalWrite(PapyrusRelay, LOW); //the soil is still wet, the relay stays open (NO)
digitalWrite(WaterRelay, LOW); //the water pump will not run
delay(200);
}
else if ((Papyrus > PapyrusLimit) && (Watertank < WatertankLimit))
{
digitalWrite(PapyrusRelay, HIGH); //the plant needs water, therefore the pump needs to run if there is enough water in the tank.
digitalWrite(WaterRelay, HIGH); //the water pump will run
}
delay(200);
//**************************************************************************************************************
if ((Bonsai < BonsaiLimit) && (Watertank < WatertankLimit))
{
digitalWrite(BonsaiRelay, LOW); //the soil is still wet, the relay stays open (NO)
digitalWrite(WaterRelay, LOW); //the water pump will not run
delay(200);
}
else if ((Bonsai > BonsaiLimit) && (Watertank < WatertankLimit))
{
digitalWrite(BonsaiRelay, HIGH); //the plant needs water, therefore the pump needs to run if there is enough water in the tank.
digitalWrite(WaterRelay, HIGH); //the water pump will run
}
delay(200);
//**************************************************************************************************************
if (Watertank > WatertankLimit) //if the water level is too low
{
digitalWrite(WaterRelay, LOW);
digitalWrite(OliveRelay, LOW);
digitalWrite(PapyrusRelay, LOW);
digitalWrite(BonsaiRelay, LOW);
}
delay(2000);
//**************************************************************************************************************
}



