Controlling relay through data received from bluetooth

I want to use relay to power on a 12v fan and halogen lamp. My project details are as such my first bluno nano is connected to a thermistor and when temp hit a certain threshold it will send a ‘1’ to my other bluno nano via bluetooth, else it will it will send ‘0’ instead. When my other bluno nano receives ‘1’ it will switch on the fan and one halogen light (randomly from 3). However, I cannot get the relay to work. Even with input from my first bluno nano, both relay switches are constantly on all the time. Please help. I have tested my code with L.E.Ds without the relay and it works.

Code of my first bluno nano:
int ThermistorPin = A0;
int Vo;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

void setup()
{
Serial.begin(115200);
}

void loop()
{
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2logR2 + c3logR2logR2logR2));
Tc = T - 273.15;
Tf = (Tc * 9.0)/ 5.0 + 32.0;

if (Tc > 30)
{
Serial.print(‘1’);
}
else
{
Serial.write(‘0’);
}

delay(20000);
}

Code for my other bluno nano:
const byte a[3] = {2, 3, 4};
byte light;
int fan = 5;

void setup()
{
Serial.begin (115200);
pinMode (2, OUTPUT);
pinMode (3, OUTPUT);
pinMode (4, OUTPUT);
pinMode (fan, OUTPUT);
}

void loop()
{
if (Serial.available ())
{
if (Serial.read() == ‘1’)
{
light = a[random(0, 3)];
digitalWrite (light, HIGH);
digitalWrite (fan, HIGH);
delay(1000);
digitalWrite (2, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (fan, LOW);
delay(1000);
}

else
{
digitalWrite (2, LOW);
digitalWrite (3, LOW);
digitalWrite (4, LOW);
digitalWrite (fan, LOW);
delay(2000);
}
}
}

Bluetooth_Master_Temp1.ino (511 Bytes)

Bluetooth_Slave_Temp2.ino (699 Bytes)

I have tested my code with L.E.Ds without the relay and it works.

That points to hardware problems. Please post a system diagram and/or clear photos showing all interconnections including power supplies. Do you have a flyback diode on the relay? What powers the relay?

No flyback diode
I uses battery to power the relay, my pc usb to power arduino
I hope my picture is clear enough.
I did not connect digital pin 2 and 3 because I am testing out the circuit, so I test the FAN and one of the randomly selected LIGHTs

Red wires are connected as such:
arduino +5V to relay VCC
battery + to breadboard +
relay JD-VCC to breadboard +

Blue wires are connected as such:
arduino digital pins to relay IN pins

Green wires are connected as such:
breadboard + to relay COMS

Yellow wires are connected as such:
fan + to breadboard +
bulb to breadboard +

Photo size too big, i uploading individually

here’s another

last one, sry for the spam

lootr5858:
Photo size too big, i uploading individually
78d4a81cbbdd6dbcd85806cbe45f87535988c6d7.jpg
55a4e8585558343f5b0e42de79686e43e7534c68.jpg
25752f259040478cbea754fc21cdd1283fd1a9a8.jpg

Inline for convenience.

Can you get the relays to switch with those batteries, without connecting the Arduino?

wvmarle:
Can you get the relays to switch with those batteries, without connecting the Arduino?

Yes I can.

Anyways I figured out the problem. The relay takes the command in reverse, meaning when I write HIGH, it takes it as off, and LOW is on. I can live with that thanks guys

wvmarle:
Inline for convenience.

Thanks

Yes, some relays work like that. It doesn't matter at all which way they work, as long as you know which way it is.
I once encountered a two-relay board where one relay was active low, the other active high. Now that's confusing!