Turn on a pump on and solenoid valve

I'm new with arduino projects, I've a project about a irrigation system, I have three moisture sensor and I need to turn on a pump on and control the irrigation area with three solenoid valves
I have the following code.

int soilMoistureValue = 0;
int soilMoistureValue2 = 0;
int soilMoistureValue3 = 0;
int sensor1 = 0;
int sensor2 = 0;
int sensor3 = 0;

void setup() {
  pinMode(3,OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  Serial.begin(9600);
}

void loop() {
soilMoistureValue = analogRead(A0);
Serial.println(sensor1);
sensor1 = map(soilMoistureValue, 490, 1023, 100, 0);

soilMoistureValue2 = analogRead(A1);
Serial.println(sensor2);
sensor2 = map(soilMoistureValue2, 490, 1023, 100, 0);

soilMoistureValue3 = analogRead(A2);
Serial.println(sensor3);
sensor3 = map(soilMoistureValue3, 490, 1023, 100, 0);


if(sensor1 < 40 || sensor2 < 40 || sensor3 < 40){
  Serial.println("Bomba encendida");
  digitalWrite(3,LOW);
  if (sensor1 < 40){
    Serial.println("Electrovalvula 1 encendida");
    digitalWrite(4, LOW);
  }else if (sensor2 < 40){
    Serial.println("Electrovalvula 2 encendida");
    digitalWrite(5, LOW);
  }else if (sensor3 < 40){
    Serial.println("Electrovalvula 3 encendida");
    digitalWrite(6, LOW);
  }
}

if (sensor1 > 80){
   Serial.println("Electrovalvula 1 apagada");
   digitalWrite(4,HIGH);
}else if (sensor2 > 80){
   Serial.println("Electrovalvula 2 apagada");
   digitalWrite(5,HIGH);
}else if (sensor3 > 80){
   Serial.println("Electrovalvula 3 apagada");
   digitalWrite(6,HIGH);
}else if(sensor1 > 80 || sensor2 > 80 || sensor3 > 80){
  Serial.println("Bomba apagada");
  digitalWrite(3,HIGH);
}
}

Is there a question?

Please post your code using code tags... these things in the editor window "</>".

Do you have a problem?

Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar.
code tags new

You need to NOT use +12 into the Arduinio. Use a +5 supply on the Vin pin and supply SEPARATE power to the pump and solenoid. The valve solenoid need anti kickback diodes. The Uno CANNOT power the pump/valves.

1 Like

Use 5V on the 5V pin. The Vin pin needs at least 7V for the onboard regulator to function properly.

Be careful when using the power plug or Vin. Powering through Vin or the power jack means that the Arduino and all peripherals that are on the 5V rail are powered by the onboard 5V regulator. The on board 5V regulator is not heat sinked so will supply limited current before it overheats and shuts down. The amount of current depends on the voltage input to Vin or the power jack. The higher the voltage the less current can by supplied. I would use a buck converter to drop the 12V to 5V and connect that to the 5V on the Arduino, bypassing the, weak, 5V regulator. Then the rated current of the DC DC converter is available on the 5V line.

Not suggesting using barrel connector/onboard reg. Hard +5 on +5 pin.

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