2

I have a relay that should be switched off when the analog value is too high by the Arduino code:

int digitalPin = 4; // for the relay
int analogPin = A0; // for the soil moisture sensor
int digitalVal; // digital readings
int analogVal; // analog readings

void setup()
{
    pinMode(digitalPin, OUTPUT);
    digitalWrite(digitalPin, LOW);
    Serial.begin(9600);

}

void loop()
{
    analogVal = analogRead(analogPin); // read the value returned by the soil moisture sensor
    if (analogVal < 400) { // if the soil moisture sensor returns a value < 400
        digitalWrite(digitalPin, HIGH); // The water pump waters the plant
    } else {
        digitalWrite(digitalPin, LOW); // The water pump stops watering
    }
    Serial.println(analogVal);
    delay(100);
}

But, as you can see on the video, despite going above the 400 threshold, having the relay pin switching off, it continues to pump.

Here is my architecture:

enter image description here

I just changed the relay to an Elegoo 4:

enter image description here

I am following this tutorial.

12
  • you have to connect the relay to the controlled pin
    – jsotola
    Commented Jun 22, 2023 at 16:20
  • don't use the arduino as a power supply for the motor ... it could destroy the arduino
    – jsotola
    Commented Jun 22, 2023 at 16:21
  • Oh, right @jsotola but isn't it what I did? (I just uploaded a photo of my attempt to implement the sketch) Thanks for the tip for the power supply. I will look for one when I will be sure my thing is working properly :) Commented Jun 22, 2023 at 18:39
  • isn't it what I did? ... no, the wiring diagram shows otherwise
    – jsotola
    Commented Jun 22, 2023 at 19:33
  • 1
    why are you posting inaccurate material? ... there is no reason why anyone should have to watch a video to learn what you are doing ... questions should be self contained without need for external links
    – jsotola
    Commented Jun 23, 2023 at 0:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.