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.

  • you have to connect the relay to the controlled pin – jsotola Jun 22 '23 at 16:20
  • don't use the arduino as a power supply for the motor ... it could destroy the arduino – jsotola Jun 22 '23 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 :) – Revolucion for Monica Jun 22 '23 at 18:39
  • isn't it what I did? ... no, the wiring diagram shows otherwise – jsotola Jun 22 '23 at 19:33
  • Oh, you mean that the green and the light blue wires should be the same? So the relay would be connected to the control pin ? – Revolucion for Monica Jun 22 '23 at 21:03
  • "I will look for one when I will be sure my thing is working properly :) " Sounds like the chicken and egg thing. Expensive if the arduino fails. Note: "A Power Supply the Arduino is NOT!" A mistook could also take out your computer. – Gil Jun 22 '23 at 21:30
  • you mean that the green and the light blue wires should be the same? ... no ... your code shows the control pin to be pin 4 ... your wiring diagram show a connection at pin 2 – jsotola Jun 22 '23 at 22:43
  • yes, I think that's a mistake from the tutorial @jsotola as the video accompanying it says to connect the (S) pin of the relay to pin4 of the Arduino – Revolucion for Monica Jun 22 '23 at 23:31
  • 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 Jun 23 '23 at 00:45
  • hmm, I think I've posted the inaccurate material because it is the context of the question @jsotola My question is about the pump working continuously while the relays should stop it at some point – Revolucion for Monica Jun 23 '23 at 04:51
  • Do you hear the relais switch? Its PCB has an LED, does it reflect the expected state? Only if that is correct, you should think about adding the pump. – the busybee Jun 23 '23 at 06:29
  • Can you post your connection diagram? A hand-drawn document is better than the wrong diagram in the question. – Fahad Jun 25 '23 at 10:59

0 Answers0