Hi everyone,
some time ago I started to build myself a watering system for my plants, but there is one problem I am not able to solve.
The culprit are these cheap 5V mini pumps (Link to Aliexpress). Everytime a trigger the pump, the input values read from the moisture sensors are forced to zero or the whole arduino crashes. I do not have the problem when I am using the more expensive pumps (Link to better pump on Aliexpress).
At first I was using a TIP120 transistor to switch on the pumps, but than thought that the crashes might be caused by some backlash into the circuit. Because of this I switched to a relay board with optocouplers. I also added a potentiometer to check the anlog inputs, but this does not seem to be influenced by the pump for some reason.
Unfortunately the problem still happens and I am at my wits end.
I hope you can help me figure this out.
#include <Adafruit_GFX.h>
#include <Adafruit_SH1106.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
#define OLED_RESET -1
Adafruit_SH1106 display(OLED_RESET);
int water = 0;
int air = 488;
int humidityRaw[6] = {0, 0, 0, 0, 0, 0};
int humidityReal[6] = {0, 0, 0, 0, 0, 0};
void setup() {
Serial.begin(115200);
display.begin(SH1106_SWITCHCAPVCC, 0x3C);
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
pinMode(8,INPUT);
pinMode(9,INPUT);
pinMode(13,OUTPUT); //Set pin 13 as OUTPUT pin
pinMode(12,OUTPUT); //Set pin 13 as OUTPUT pin
}
void loop() {
humidityRaw[0] = analogRead(A0);
humidityReal[0] = map(humidityRaw[0], air, water, 0, 100);
delay(20);
humidityRaw[1] = analogRead(A1);
humidityReal[1] = map(humidityRaw[1], 0, 1022, 0, 100);
delay(20);
int push1 = digitalRead(2);
if (push1 == 1){
digitalWrite(13,HIGH);
}
else {
digitalWrite(13,LOW);
}
delay(200);
//clear display
display.clearDisplay();
// display temperature
display.setTextSize(1);
display.setCursor(0,0);
display.print("Humidity: ");
display.setTextSize(2);
display.setCursor(0,10);
display.print(humidityReal[0]);
display.print(" ");
display.setTextSize(1);
display.cp437(true);
display.write(167);
display.setTextSize(2);
display.print(" %");
// display humidity
display.setTextSize(1);
display.setCursor(0, 35);
display.print("Humidity: ");
display.setTextSize(2);
display.setCursor(0, 45);
display.print(humidityReal[1]);
display.print(" %");
display.display();
}







