My Relay isnt working

const int dry = 356;
const int wet = 260;
//To make precent on screen lower lower thin number in incraments of 5
int Pump = 2;
int Pumpon = 50;

void setup() {
Serial.begin(9600);
pinMode(Pump, OUTPUT);

}

void loop() {

int sensorVal = analogRead(A0);


int PlantWaterLevels = map(sensorVal, wet, dry, 100, 0);

Serial.print("Water Levels In Your Plant-  ");
Serial.print(PlantWaterLevels);
Serial.println("%");
delay(50);


if (PlantWaterLevels < Pumpon){
  digitalWrite(Pump, HIGH);
  Serial.println("Pump On");
  delay(7000);
  digitalWrite(Pump, LOW);
  delay(10000);

}


if (PlantWaterLevels > Pumpon){
  digitalWrite(Pump, LOW);
  delay(150);
}

}

This is the code that is used for my relay the relay. The relay is connected to int Pump.

The relay I'm using is the HiLetgo 2pcs 5V One Channel Relay Module Relay Switch with OPTO Isolation High Low Level Trigger.

Welcome to the forum

Which Arduino board are you using and how is it powered ?

Also, how is the relay wired up?
This is the right type of relay to use with Arduino because it is optically isolated and only draws a couple of mA from the output pin. Often times people get confused about the wiring of the relay itself though.

Please provide schematic of the Arduino and relay. Check that the relay modual GND is connected to Arduino GND.

Hope this helps.

Hi, @silas431

Can you please tell us your electronics, programming, arduino, hardware experience?

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

What model Arduino are you using?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

I have deleted your other cross-post @silas431.

Cross-posting is against the Arduino forum rules. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Repeated cross-posting can result in a suspension from the forum.

In the future, please only create one topic for each distinct subject matter. This is basic forum etiquette, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

First suggestion is to eliminate the if statement ... for testing.

void loop() {

  digitalWrite(Pump, HIGH);
  Serial.println("Pump On");
  delay(7000);
  digitalWrite(Pump, LOW);
  delay(10000);
}

Hi,
OPs relay;

How have you got the jumper on the PCB set?

Tom... :smiley: :+1: :coffee: :australia: