My DC fan is not stopping

Hello guys I am new to Arduino and I am facing one huge problem for me..you see I am using Arduino Uno r3 with soil sensor,water pump,dht11,12v DC fan..the water pump works fine..but the problem is the fan...in the serial monitor it is showing the fan is off but the fan is still spinning..and also even without uploading the code the fan spin on its own..Can you help me :hugs:

Probably. But not without a complete schematic and < /CODE>.

1 Like
This is my code 

#include <dht.h>
dht DHT;
#define DHT11_PIN A5


int sensor_pin = A0;  // Soil Sensor input at Analog PIN A0
int output_value;
int relayPin = 8;
int RELAY_FAN_PIN = 7;

const int TEMP_THRESHOLD = 25;


void setup() {
  Serial.begin(9600);
  pinMode(sensor_pin, INPUT);
  pinMode(relayPin, OUTPUT);

  pinMode(RELAY_FAN_PIN, OUTPUT);
  delay(500);
  Serial.println("Reading From the Sensor ...");
  delay(2000);
}

void loop() {
  DHT.read11(DHT11_PIN);
  Serial.print("Temp: ");
  Serial.print(DHT.temperature);
  Serial.println("C");
  Serial.print("Humidity: ");
  Serial.print(DHT.humidity);
  Serial.println("%");
  delay(5000);

  if (DHT.temperature > TEMP_THRESHOLD) {
    Serial.println("The fan is turned on");
    digitalWrite(RELAY_FAN_PIN, HIGH);
  } else {
    Serial.println("The fan is turned off");
    digitalWrite(RELAY_FAN_PIN, LOW);
  }


  //this for soil sensor and pump
  output_value = analogRead(sensor_pin);
  output_value = map(output_value, 550, 10, 0, 100);
  Serial.print("Moisture : ");
  Serial.print(output_value);
  Serial.println("%");
  if (output_value < 20) {
    digitalWrite(relayPin, LOW);
  } else {
    digitalWrite(relayPin, HIGH);
  }
  delay(1000);
}

Also need a schematic please.

1 Like

Please also post a link to the product page for the pump, the motor driver and power supply you are using to control and power it.

Without this information, it is impossible to give much useful advice.


I don't know how to do that schematic but I am assuming it is about the connection.

1.Waterpump link-Submersible Mini Water Pump buy online at Low Price in India - ElectronicsComp.com

2-Relay used -1 Channel 5V Relay Module without Optocoupler buy online at Low Price in India - ElectronicsComp.com

3-type C cable charger connected to laptop USB port to power the fan/waterpump

4.the fan is a 12v DC fan 0.14 A ( i take it from an SMPS)

What happens if you unplug pin 7? Also, does the relay have a normally closed contact that you're wired to?

When I take out 7 the fan keep spinning..even if i disconnect the Arduino it still spin it's as if it is directly connected to power.
Is it due to the fact that it is an SMPS fan?

Yes the relay has NC but I only connected to NO and COM for both the relays

COM & N.O.
(N.O. - Normally Open, "open circuit")

Yes

You guys always have this deal where you wump a bunch of stuff together without covering the basics.
Work out a sketch to turn the fan/relay on for 5 seconds and off for 5 seconds - to troubleshoot with.

Hi, @jack28y
Welcome to the forum.

Do you have a DMM, Digital MultiMeter?

A sketch that JUST has fan/relay code in it.

Did you test your relay connection and control before you wrote the code in post#4?

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

Well i did a simple connection but the fan wont stop spinning,,the weirder part is even when i disconnect the Arduino the fan keep on spinning

Replace the relay! Cheap relays can have the tiny contacts weld themselves together.

1 Like

Hi,
Can you please post some images of your project?
So we can see your component layout.

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

It's working now,the reason was that I used an old relay and there is a really2 small copper wire than is stucked beneath the No and Com ports touching the two..I clean it and now its working fine...
Thank you guys for being really kind and quick to listen to a stranger :innocent::innocent::+1::+1::+1::+1::+1::+1:

Hello is it normal for soil sensor not to show 100 percent even if i dip the sensor fully in water...or is my sensor broke..or is it in the program

If you dry the sensor afterwards, what is the reading ?

-33 or any negative number

Many inexpensive moisture sensors are Go/No Go type.

They are only useful for dry or wet conditions, nothing in between.