Does not work while USB is disconnected

1st post so please excuse any deviance from the usual format.

Very new to Arduino.

Project - Temperature sensor for activating external fan on PC.

Aim of project - To automatically start an external fan when a temperature is reached ... useful while gaming.

Components used - DHT11 Arduino Uno clone 5v Relay 12v 1A power supply 12v to 5v converter(for DHT11 & relay)

Now, i see quiet a few posts about this issue, however most of these were code issues. My code has only 2 lines - If temp is 42deg - change o/p to high If temp is 40deg - change o/p to low

The high/low drives the relay which switches a fan on/off.

Everything works fine when the USB is connected. So no problem with the code(i believe/hope).

When i remove the USB ... the whole things seems to go into a 2-3 sec cycle. It will remain on & then switch off every 2-3 seconds. So definitely a power issue. Or thats what it seemed like. The whole thing is powered by a 1A power supply. So dont see what is wrong. I thought the fan was drawing more power so i disconnected the fan, but still the same thing. The relay will remain on for 2-3 or sometimes 4 seconds & shut down for about 1-2 seconds & then repeat the cycle. The whole time the board remains ON.

How much power does a board consume? How much power does a relay consume for remaining active?

Are there some known issue regarding the boards? II have tred a few solutions like connecting a resistance between the TX & RX ... Connecting a diode between the RESET & 5v etc.

Any other suggestions?

Draw a circuit diagram showing all the connections and post it here.

A circuit diagram would be helpful and some stats on that relay.

Is the relay powered via the battery or via a transistor/diode from a 5v pin out of the arduino?

Further, some debugging LEDs would not go amiss. Have them flash a certain number of times when you get to a certain part in your sketch.

mikb55 - Per your suggestion, below is the circuit layout ... There maybe a few pins here & there ... but it works fine when connected to USB ... so its behaving as it is supposed to when tethered to USB.

Johnny010 - The relay module is just the usual off-the-shelf thing. A 5v Relay Module. Its powered by a 5v circuit/IC and is triggered with the signal from Pin 2(dont quiet remember) Also, Wouldn't know how to debug ... too new to this.

#include <DHT.h>

const int COMFORT_TEMPERATURE = 42;
const int COMFORT_TEMPERATURE2 = 40;
const int COMFORT_HUMIDITY = 70;

#define DHTPIN 3      // pin teplotního senzoru
#define DHTTYPE DHT11 // typ teplotního senzoru
#define RELAYPIN 2    // pin relé
#define RELAY2PIN 4

DHT dht(DHTPIN, DHTTYPE);

void setup()
{
Serial.begin(9600);
Serial.println("Hope this works");

pinMode(RELAYPIN, OUTPUT);  
pinMode(RELAY2PIN, OUTPUT);

dht.begin();
}

void loop()
{
int humidity = dht.readHumidity();
int temperature = dht.readTemperature();

if (temperature > COMFORT_TEMPERATURE)
{
digitalWrite(RELAYPIN, HIGH);  
}

else if (temperature <= COMFORT_TEMPERATURE2)
{
digitalWrite(RELAYPIN, LOW);                  
}

if(humidity < COMFORT_HUMIDITY)
{
digitalWrite(RELAY2PIN, HIGH);
}
else
{
digitalWrite(RELAY2PIN, LOW);
}

{
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
}

delay(500);
}

ummmmmm … how do i add the circuit ?

Reply:Attachments below the reply box.

Your motor should have at the very least a diode reverse connected across it to snub reverse emf transients. These could easily destroy your circuit.

Inductive components generally are best powered from a seperate supply

Also check the relay module has the same diode fitted (it should have)

With the usb connected the arduino will get its power from that, this indicates a power problem as you suggest