Issue with Smart Irrigation System

Hi..I'm trying to make a Smart Irrigation System with a Arduino Mega, where a soil moisture sensor detects dryness(ik mine's a bit weird it gives about 1024 for a dry & about 300-400 for a wet.) every 10 seconds, and if it is above a certain threshold, it turns on a DC pump for 5 seconds. I've used a BC557 transistor since the digital pins can't power the pump. Here is the tinkercad circuit:


Here's the code:

const int soilDrynessPin = A0;    // Analog pin for soil dryness sensor
const int pumpControlPin = 8;      // Digital pin connected to the base of the BC557 transistor

void setup() {
  pinMode(soilDrynessPin, INPUT);
  pinMode(pumpControlPin, OUTPUT);
  Serial.begin(9600);

  // Turn off the pump initially
  digitalWrite(pumpControlPin, HIGH);
}

void loop() {
  // Read soil dryness level
  Serial.println("READING MOISTURE");
  int soilDryness = analogRead(soilDrynessPin);
  Serial.print("Dryness read: ");
  Serial.println(soilDryness);

  // Adjust the threshold value according to your soil dryness sensor
  int drynessThreshold = 700;

  // Check if soil dryness is below the threshold
  if (soilDryness > drynessThreshold) {
    
    // Turn on the pump
    digitalWrite(pumpControlPin, HIGH);
    Serial.println("Pump - HIGH & Waiting for 5 seconds");
    delay(1000);
    Serial.println("4 seconds");
    delay(1000);
    Serial.println("3 seconds");
    delay(1000);
    Serial.println("2 seconds");
    delay(1000);
    Serial.println("1 seconds");
    delay(1000); // Run the pump for 5 seconds (adjust as needed)
    // Turn off the pump
    digitalWrite(pumpControlPin, LOW);
    Serial.println("Pump - LOW");
  }

  // Wait for a period before checking soil dryness again
  Serial.println("Waiting for 10 seconds");
  delay(1000);
    Serial.println("9 seconds");
    delay(1000);
    Serial.println("8 seconds");
    delay(1000);
    Serial.println("7 seconds");
    delay(1000);
    Serial.println("6 seconds");
    delay(1000);
    Serial.println("5 seconds");
    delay(1000);  
    Serial.println("4 seconds");
    delay(1000);
    Serial.println("3 seconds");
    delay(1000);
    Serial.println("2 seconds");
    delay(1000);
    Serial.println("1 seconds");
    delay(1000);
  Serial.println("LOOP OVER");
}

It works properly on tinkercad but when I duplicate the exact same thing in my actual circuit it doesn't work and the pump randomly shuts off and on. I've tried changing the pump but the same thing happened. Is it because of some inductive current going the other way so I should put a diode or something? I don't know.. Someone please help.

The Arduino is not a power supply.

The Arduino cannot be used to power motors, pumps, servos, etc. Use a separate power supply, and connect all the grounds.

Servo example, power wiring works for pumps too.

1 Like

Hello dear why using BC557 transistor?

That the OP explained in the first post already:

Thanks but you can instead the BC557 transistor using relay with water pump 5v?

Yes - provided the relay has an appropriate driver itself.

Thanks but how can do?

There are tons of tutorials out there on how to connect a relay.

If you have further questions specific to your own project, please open your own thread as you're in the process of hijacking another thread now.

You do not have a resistor ( 220 to 330 Ohms) between transistor base and Arduino output pin, that will burn out the transistor, output pin or both. You cannot run a motor from the Arduino's 5V pin, that could damage the Arduino AND your computer. You need a separate power supply for the motor, what are the motor's voltage and current or Watt ratings?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.