Can't activate relay using Digital pin out and 2n2222 transistor

Hello,

I'm trying activate 5V relay using Arduino which is sending signal when TMP36 sensor is reaching certain temperature. Since it can't be activated through digital output directly i'm using a circuit as shown below (except I have 4001 diode)

image

I've connected everything, first tested with LED where the relay should be, it lights up as intended. When I put relay, nothing happens.
I've measure how much current the relay draws, it was around 20mA.
Then I tried to measure current when I give voltage directly from 5V output of arduino - 60mA.
As I understand the 2n2222 when activated connects relay leg to the ground while 5V is connected directly to other relay leg. So it should work the same as connecting directly to 5V and GND. 2N222 has rated current as 800mA maximum, so that shouldn't be a problem as well.
I'm new to Arduino and don't know what i'm doing wrong. Does anyone have any insights?

Hi @taskitas
If you have a multimeter, set the arduino pin to HIGH, and measure the voltage between the 2 pins of relay coil.
And say how much you measured.

I've measured it directly, it says 4,95V. Also tried to measure when the relay is there - 1,85V, so as I understand it is voltage drop?

Hi, here I've measure it directly on the relay. It's 1,85V.
image

Hi @taskitas
If you have 1.85 between the pins of the relay coil, you have 2 possibilities:

  1. The source is not providing enough current and the voltage is dropping when the relay is activated.
    Check the power supply voltage with the arduino pin set to HIGH.
  2. Transistor is not entering saturation and +- 3.15 volts left from transistor collector for GND.
    In this case, reduce the transistor base resistor to values around 330 Ohms to 220 Ohms.
    Then say the result.

Also, make sure the arduino ground is connected to the ground of your 2n2222.

Also, make sure you have your Arduino output pin set to pinMode(pin, OUTPUT). If it's left as an INPUT then setting it to HIGH just turns on the internal pull-up resistor and you get very little current out of the pin.

3 Likes

Hi
From the questions that were asked, you may have noticed that a lot of information was missing.
To better help you, how about posting between tags </>

ArduinoForum
your code, a photo of your mounting and a schematic, (no fitzing), of your project?

Which Arduino? Make sure you have transistor emitter and collector connections correct.
2N2222
2N2222
P2N2222
P2N2222

Hi,
Can you tell us the EXACT number written on the transistor?

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

This was the problem, thank you! I've changed it to OUTPUT and it works now.
Maybe someone new like me will have similar questions, so as ruilviana suggested here is my code:

int sensePin = A0; //This is the Arduino Pin that will read the sensor output
int sensorInput; //The variable we will use to store the sensor input
double temp; //The variable we will use to store temperature in degrees.
int ledPin = 2; 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //Start the Serial Port at 9600 baud (default)
pinMode(ledPin, OUTPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
  sensorInput = analogRead(A0); //read the analog sensor and store it
  temp = (double)sensorInput / 1024; //find percentage of input reading
  temp = (temp * 5) - 0.5; //multiply by 5V to get voltage
  temp = temp * 100; //Convert to degrees

if (temp >= 25) {
  digitalWrite(ledPin, HIGH); // do stuff if the condition is true
}
  else {
    digitalWrite(ledPin, LOW);
  }  }

the schematic looks something like this

It's a pleasure to see how helpful this community is. Thanks again everyone

p.s. Now it actually works directly from the digital pin 2, i'm just not sure if it is okay to let it go directly, it uses 60 mA when activated.

Hi,
No 60mA is not.

What is the part number of your relay?
If it is configured as the top of the relay in your Fritzy, it cannot operate.
The under protoboard strips would short the coil out.

Can I recommend you hand draw your circuit including ALL part numbers and pin labels.

Thanks.. Tom.... :grinning: :+1: :coffee: :australia:
PS. An image of your project would help also.

Hi, I'm sorry for the confusion, the relay is connected directly with wires as you can see in the picture above (it does not let me to make a post with multiple pictures). I just used this layout and missed the fact that it is shorted here.
And the relay itself is this one:
image

I've measured the resistance of the coil, it is 72ohm.
So in this case i'll stick to transistor since 5/72 = 0,069 A (even more current)

P.s. Does anybody know why "Serial monitor" doesn't show temperature anymore?

Check you connections.

A proper circuit diagram would help, hand drawn will be fine.

Tom.. :grinning: :+1: :coffee: :australia:

Hello,

Finally had time to get back to this project :smiley:
here is the hand drawn schematic (hope it is clear).
image

Also there was a mistake at the code, therefore it was not printing

Hi,

So everything is working correctly?
What was wrong in your code?
Can you post a final copy of it please.

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

1 Like

Yes, now it is working well :slight_smile:
Somehow deleted one letter of temp in Serial.print(temp); leaving it Serial.print(tem);

int sensePin = A0; //This is the Arduino Pin that will read the sensor output
int sensorInput; //The variable we will use to store the sensor input
double temp; //The variable we will use to store temperature in degrees.
int ledPin = 2; 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600); //Start the Serial Port at 9600 baud (default)
pinMode(ledPin, OUTPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
  sensorInput = analogRead(A0); //read the analog sensor and store it
  temp = (double)sensorInput / 1024; //find percentage of input reading
  temp = (temp * 5) - 0.5; //multiply by 5V to get voltage
  temp = temp * 100; //Convert to degrees
 Serial.print(temp);
  Serial.print("C ");
   delay(1000);

if (temp >= 28) {
  digitalWrite(ledPin, HIGH); // do stuff if the condition is true
}
  else {
    digitalWrite(ledPin, LOW);
  }  }

This is my final code

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.