2
\$\begingroup\$

I have a circuit as shown below:

schematic

simulate this circuit – Schematic created using CircuitLab

Note:

In the above schematic some pins of Arduino Nano are not shown for simplicity purposes. Also, SW1 and SW2 are not switches but sensors as shown below:

enter image description here

Here is the arduino code:

//include LCD library
#include <LiquidCrystal.h>

//Initialize an LCD object
/*Pins should be mentioned in this order:
  Reset
  Enable
  Data4
  Data5
  Data6
  Data7
*/
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
int upSensor = 11;
int downSensor = 10;
int continuousSwitch = 8;
int suddenSwitch = 9;

unsigned long counter = 0;

void setup()
{
  Serial.begin(9600);

  pinMode(upSensor, INPUT);
  pinMode(downSensor, INPUT);
  pinMode(continuousSwitch, OUTPUT);
  pinMode(suddenSwitch, OUTPUT);

  //Begin the LCD interface
  lcd.begin(16, 2);

  lcd.print("MOTOR OFF");
}

void loop()
{

  if(counter == 1)
  {
    digitalWrite(suddenSwitch, HIGH);
    delay(1000); //1 Second
    digitalWrite(suddenSwitch, LOW);
  }

  Serial.println("upSensor: " + String(digitalRead(upSensor)));
  Serial.println("downSensor: " + String(digitalRead(downSensor)));

  if(digitalRead(upSensor) == HIGH && digitalRead(downSensor) == HIGH)
  {
    digitalWrite(continuousSwitch, HIGH);
    lcd.setCursor(6, 0);
    lcd.print("ON");
    counter++;
  }

  if((digitalRead(upSensor) == LOW && digitalRead(downSensor) == LOW))
  {
    digitalWrite(continuousSwitch, LOW);
    lcd.setCursor(6, 0);
    lcd.print("OFF");
    counter = 0;
  }

}

Everything is working fine except relay RLY2.

No matter if switch sw1 and sw2 are open or close, RLY2 is always ON. I mean RLY2's COMMON connection is always connected to NORMALLY OPEN Connection. If I measure the output from pin D9 of arduino, then I can see that it is changing according to the state of the switches SW1 and SW2. But the Relay RLY2 is always ON. WHY????

Update:

Before removing transistor:

I have added a diode between emitter and ground. Also changed the resistor R2 from 1K to 470E.

Voltages of Q2:

A. When D9 is HIGH:

Collector - Ground ----> 6.15V
Emitter - Ground ------> 0.70V
Base - Ground ---------> 1.40V

Collector - Base ----> 4.75V
Collector - Emitter -> 5.40V
Base - Emitter ------> 0.70V

B. When D9 is LOW:

Collector - Ground ----> 7.90V
Emitter - Ground ------> 0.70V
Base - Ground ---------> 0.65V

Collector - Base ----> 7.25V
Collector - Emitter -> 7.20V
Base - Emitter ------> 0.50V

I will remove the transistor, after Trevor checks above voltages and makes sure if transistor is sick.

Update2:

After removing transistor:

Voltages of Q2:

A. When D9 is HIGH:

Collector - Ground ----> 15.06V
Emitter - Ground ------>  0.15V
Base - Ground --------->  4.03V

Collector - Base ----> 12 V
Collector - Emitter -> 15.6V
Base - Emitter ------> 3.70V

B. When D9 is LOW:

Collector - Ground ----> 16.90V
Emitter - Ground ------> 0.12V
Base - Ground ---------> 0 V

Collector - Base ----> 16.8V
Collector - Emitter -> 16.4V
Base - Emitter ------> 0.15V

I have also measured the transistor:

Base - Collector    --> 647
Base - Emitter      --> 642
Collector - Emitter --> 1
Collector - Base    --> 1
Emitter - Base      --> 1
Emitter - Collector --> 1

So, from above mentioned readings, I think the transistor is OK. Am I right?

Update3:

I have put new 2N2222 after removing the first one:

Voltages of Q2:

A. When D9 is HIGH:

Collector - Ground ----> 0.76V
Emitter - Ground ------> 0.74V
Base - Ground ---------> 1.52V

Collector - Base ----> 0.74 V
Collector - Emitter -> 0.02V
Base - Emitter ------> 0.77V

B. When D9 is LOW:

Collector - Ground ----> 10.25V
Emitter - Ground ------> 0.70V
Base - Ground ---------> 0.73V

Collector - Base ----> 9.50V
Collector - Emitter -> 9.55V
Base - Emitter ------> 0.04V

Now, my diagram looks like:

schematic

simulate this circuit

Update4 (Working Diagram):

schematic

simulate this circuit

\$\endgroup\$
1
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Dave Tweed
    Mar 29, 2017 at 11:43

2 Answers 2

1
\$\begingroup\$

Unfortunately, there is no guarantee Arduino can pull the base that low...

enter image description here

You either need to add a diode under that transistor and reduce the resistor to closer to 500R so it turns on harder or better, switch to N-Channel MOSFETS.

\$\endgroup\$
28
  • 1
    \$\begingroup\$ OK. I will try it and tell you if I was successful. \$\endgroup\$
    – Vishal
    Mar 28, 2017 at 19:54
  • 1
    \$\begingroup\$ @Trevor: Aren't those specs worse-case when sinking 20mA? Surely that's not the case here. What is the part number of the relay you're using (link to datasheet?). Maybe the 2222's are cooked? What do you measure on DIO9? On the collector of Q2? Double-Quadruple check that the transistors are wired properly. Also, you could remove C2. Read this: link \$\endgroup\$ Mar 28, 2017 at 20:37
  • 1
    \$\begingroup\$ Can you please check the update part in question. I have noted down all the voltages for you to make sure that if transistor is sick. \$\endgroup\$
    – Vishal
    Mar 28, 2017 at 21:48
  • 2
    \$\begingroup\$ @Vishal, good luck. I am confident you can figure it out . You just have to think it though step by step :) \$\endgroup\$
    – Trevor_G
    Mar 29, 2017 at 19:40
  • 2
    \$\begingroup\$ Thanks for help. I got it to work by replacing IRF164 with 2N7000 \$\endgroup\$
    – Vishal
    Mar 29, 2017 at 21:10
0
\$\begingroup\$

B. When D9 is LOW:

Emitter - Ground ------> 0.70V Base - Ground ---------> 0.65V

that's your problem: when D9 is low, and emitter is grounded, there is no way you could have observed a voltage differential between the emitter and ground, and there is no way base is 0.65v above ground.

I would suspect faulty connection or faulty transistor.

BTW, no point in adding a diode to the emitter -> makes zero sense.

\$\endgroup\$
1
  • \$\begingroup\$ I have used N channel Mosfet instead of BJT and it works fine now. I have checked the BJT after removing it. It wasn't faulty at all. In the answer by trevor, he told me that I need a diode under BJT and so I did that. I think I misunderstood the concept that he was trying to explain me. Although my circuit is working fine now, I want to know the meaning of You need a diode under that transistor. Can you explain me? \$\endgroup\$
    – Vishal
    Apr 3, 2017 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.