Bluetooth fan doesn't work

Hi everyone!! :smiley:

I'm making a project for high school, I have to turn on and off some stuff through an Android app that I designed.

4 led strips
1 servomotor
1 fan

I can already turn on and turn off the servomotor with Android, but the led strip and the fan that I'm using are of 12V both. I've got an external source of 12V, I've checked a lot of videos about how to turn them on and off via bluetooth , but it's been impossible :confused:

Some videos said that I needed to buy a transistor "TIP122" so I can control high currents, I bought the component, and I've tried a lot of schematic diagrams but nothing works... Here's the code by the way. Sorry about the language, I translated most of the stuff into English, so you can see where everything is.

#include <Servo.h>
Servo servo1;

void setup ()

{
servo1.attach(3); // DOOR
pinMode(2,OUTPUT); // LIGHTS
pinMode(5,OUTPUT); // FAN
Serial1.begin(9600);
}

void loop() {

while (Serial1.available())

{
char dato=Serial1.read();
switch(dato)
{
case '1':
servo1.write(0);
delay(500);
Serial1.println("CLOSE DOOR");
digitalWrite(5,HIGH);
Serial1.println("FAN ON");
digitalWrite(2,HIGH);
Serial1.print("LIGHTS ON"); // Sala
break;

{
case '2':
digitalWrite(4,HIGH);
Serial1.print("LIGHTS OFF"); // Cocina
break;

{
case '3':
digitalWrite(6,HIGH);
Serial1.print("LIGHTS OFF"); // Baño
break;

{
case '4':
digitalWrite(7,HIGH);
Serial1.print("LIGHTS OFF"); // Cuarto
break;

{
case '5':
digitalWrite(8,HIGH);
Serial1.print("LIGHTS OFF"); //Garage
break;

{
case '6':
digitalWrite(4,LOW);
Serial1.print("LIGHTS OFF"); // Cocina
break;

{
case '7':
digitalWrite(6,LOW);
Serial1.print("LIGHTS OFF"); // Baño
break;

{
case '8':
digitalWrite(7,LOW);
Serial1.print("LIGHTS OFF"); // Cuarto
break;

{
case '9':
digitalWrite(8,LOW);
Serial1.print("LIGHTS OFF"); //Garage
break;

{
case '0':
servo1.write(90); // Abrir la puerta
delay(500);
Serial1.println("OPEN DOOR");
break;

{
case 'a':
digitalWrite(2,LOW);
Serial1.print("Turn Off Lights"); // Sala

{
case 'b':
digitalWrite(5,LOW);
Serial.print("Turn Off Fan"); // Turn off Fan
break;

}
}
}
}
}
}
}
}
}
}
}
}
}
}

P.S: I'm using Arduino Leonardo by the way

As long as your bluetooth works for other things (AKA: the arduino gets the signal) you can control 12V LED strips - and yes you do need a transistor (I use IRF520s for exactly this purpose and it works, i'm just using 2.4Ghz transceivers instead of bluetooth) to turn on and off (even PWM) digital currents that exceed 5V.

Code-wise since it's for school I don't think anyone will write your code for you.

You have LOTS of extra brackets in your switch statement.
You are missing the break; at the end of case 'a' so 'a' will turn off both lights and fan.
You don't use names for your pins, making the code hard to read.
You have cases for a bunch of pins you don't initialize.
If your lights and fan aren't working you probably wired them wrong. How have you got them wired?

#include <Servo.h>
Servo servo1;

const int LIGHT_PIN = 2;
const int DOOR_PIN = 3;
const int FAN_PIN = 5;


void setup () {
  servo1.attach(DOOR_PIN); // DOOR
  pinMode(LIGHT_PIN, OUTPUT); // LIGHTS
  pinMode(FAN_PIN, OUTPUT); // FAN
  Serial1.begin(9600);
}

void loop() {

  while (Serial1.available()) {
    char dato = Serial1.read();
    switch (dato) {
      case '1':
        servo1.write(0);
        delay(500);
        Serial1.println("CLOSE DOOR");
        digitalWrite(FAN_PIN, HIGH);
        Serial1.println("FAN ON");
        digitalWrite(LIGHT_PIN, HIGH);
        Serial1.print("LIGHTS ON"); // Sala
        break;


      case '0':
        servo1.write(90); // Abrir la puerta
        delay(500);
        Serial1.println("OPEN DOOR");
        break;

      case 'a':
        digitalWrite(LIGHT_PIN, LOW);
        Serial1.print("Turn Off Lights"); // Sala

      case 'b':
        digitalWrite(FAN_PIN, LOW);
        Serial.print("Turn Off Fan"); // Turn off Fan
        break;
    }
  }
}

It's wired like this.

Check out this image from Connect the Dots


So, you should probably add a 1K resistor to pin 9. Also, make sure that the ground is common.

It didn't work :frowning:

You need the resistor between Pin 9 and the Base because the Base/Emitter junction(s) act as diodes to ground and will draw too much current if you let them.

The Emitter must be connected to both the 12V ground and the Arduino ground.

Why connect on the negative side of the lock?

The diode in both diagrams is in the wrong place.
It has to go across the load.
Cathode (ring) to +12volt and anode to collector/neg load.
The diode does nothing where it is now, and this could easilly send the transistor to silicon heaven.

A base resistor is needed. For a TIP120, driving a 3A load, you need ~10mA base current. Use ~330ohm.
1k is fine for ~1Amp loads.

Test your circuit/lock/LED/motor by first using the resistor between base and 5volt.
Leo..

Isaac96:
Why connect on the negative side of the lock?

You can turn on an NPN transistor/N-Channel MOSFET by putting a positive current/voltage into the Base/Gate when the Emitter/Source is connected to Ground. This works beautifully even when the Collector-Emitter/Drain-Source voltage is higher than 5V. This make a low-side switch (between load and Ground) cheap and easy.
To make a high-side switch (one which goes between the power source and the load) you would use a PNP transistor/P-Channel MOSFET. To turn that OFF you have to raise the Base/Gate voltage to equal the power source voltage. Since the Arduino output only goes up to 5V you can't use a simple high-side switch on anything running at more than 5V.
That is why a low-side switch is more common.

Ok, I see now. Thanks for the knowledge!
Back to the OP, if you connect a LED with an appropriate resistor, does it turn on?
Does the LED strip turn on when you attach the base of the transistor directly to ground or 5V?