Transistor Digital Switch Problem

I have an issue with a simple digital switch for my uni project. I have an issue where i have built this digital NPN transistor switch. I have connected the VDD to an 8V power supply. I connect all grounds to the same ground. When i short the base to VDD it works exactly like a switch should. When i do it with the arduino PWM output it will not work at all. The arduino outputs a 500Hz 5V 50% PWM.

Here is a schematic to make things clearer.

The reason i need this to work is that the mosfets we are using on the H Bridge need at least 6V to saturate and the arduino only outputs 5V

When i short the base to VDD it works exactly like a switch should. When i do it with the arduino PWM output it will not work at all. The arduino outputs a 500Hz 5V 50% PWM.

Post your code .
Identify the pin you used to test the pwm.
Replace the 100 ohm resistor with a 470 ohm resistor with a led in series with the cathode connected to the collector. Repeat your test with the code.

raschemmel:
Post your code .
Identify the pin you used to test the pwm.
Replace the 100 ohm resistor with a 470 ohm resistor with a led in series with the cathode connected to the collector. Repeat your test with the code.

I tested the pwm output with my ossiloscope and it showed it was working properly. I changed it to an LED is series and i still get the same :confused: .

Here is my code:
int BTTX = 1; //Bluetooth Transmit
int BTRX = 0; //Bluetooth Receive
int RFWD = 9; //Right Motor Forward PWM
int LBWD = 10; //Left Motor Backward PWM
int RBWD = 11; //Right Motor Backward PWM
int LFWD = 12; //Left Motor Forward PWM
int CPWM1 = 4; //62khZ Constant PWM
int CPWM2 = 13; //62khZ Constant PWM
String LeftDIR = "";
String LeftVAL = "";
String RightDIR = "";
String RightVAL = "";
String serialRead = "";
String LeftVALBin;
String RightVALBin;
int LStr2Byte = 0;
int RStr2Byte = 0;
char LeftVALBinArray[8];
char RightVALBinArray[8];

//Created by Alexander Bolton

void setup() {
// put your setup code here, to run once:
TCCR0B = TCCR0B & B11111000 | B00000001; // Sets pins 4 and 13 to 62Khz

Serial.begin(9600);
analogWrite(CPWM1, 173); //Set for the mosfet switch on the Buck Booster
analogWrite(CPWM2, 173); //Set for the mosfet switch on the Buck Booster
}

void loop() {
// put your main code here, to run repeatedly:

if (Serial.available() > 0) {
serialRead = Serial.readStringUntil('/N');
Serial.println(serialRead);
LeftDIR = serialRead.substring(0, 1);
LeftVALBin = serialRead.substring(1, 9);
LeftVALBin.toCharArray(LeftVALBinArray, 8);
RightDIR = serialRead.substring(9, 10);
RightVALBin = serialRead.substring(10, 17);
RightVALBin.toCharArray(RightVALBinArray, 8);
long LeftVAL1 = strtol(LeftVALBinArray, NULL, 2);
long RightVAL1 = strtol(RightVALBinArray, NULL, 2);
LeftVAL = String(LeftVAL1);
RightVAL = String(RightVAL1);
if (LeftDIR == "1") {
LStr2Byte = LeftVAL.toInt(); //Turn to string
analogWrite(LFWD, LStr2Byte * 2);
analogWrite(LBWD, 0);
Serial.println("Left Forward");
Serial.println(LStr2Byte * 2);
}
else if (LeftDIR == "0") {
LStr2Byte = LeftVAL.toInt();
analogWrite(LBWD, LStr2Byte * 2);
analogWrite(LFWD, 0);
Serial.println("Left Reverse");
Serial.println(LStr2Byte * 2);
}

if (RightDIR == "1") {
RStr2Byte = RightVAL.toInt();
analogWrite(RFWD, RStr2Byte * 2);
analogWrite(RBWD, 0);
Serial.println("Right Forward");
Serial.println(RStr2Byte * 2);
}
else if (RightDIR == "0") {
RStr2Byte = RightVAL.toInt();
analogWrite(RBWD, RStr2Byte * 2);
analogWrite(RFWD, 0);
Serial.println("Right Reverse");
Serial.println(RStr2Byte * 2);
}
}
}

dude, you need to start doing your homework.
Look at the pinout of an arduino.
Which pins are PWM pins ?

Do you see any of the NON-pwm pins listed here ?

int RFWD = 9; //Right Motor Forward PWM
int LBWD = 10; //Left Motor Backward PWM
int RBWD = 11; //Right Motor Backward PWM
int LFWD = 12; //Left Motor Forward PWM
int CPWM1 = 4; //62khZ Constant PWM
int CPWM2 = 13; //62khZ Constant PWM

raschemmel:
dude, you need to start doing your homework.
Look at the pinout of an arduino.
Which pins are PWM pins ?

Do you see any of the NON-pwm pins listed here ?

int RFWD = 9; //Right Motor Forward PWM
int LBWD = 10; //Left Motor Backward PWM
int RBWD = 11; //Right Motor Backward PWM
int LFWD = 12; //Left Motor Forward PWM
int CPWM1 = 4; //62khZ Constant PWM
int CPWM2 = 13; //62khZ Constant PWM

It an Arduino Mega 2560

Oh, sorry, got you confused with another post.

The arduino outputs a 500Hz 5V 50% PWM.

I tested the pwm output with my ossiloscope and it showed it was working properly. I changed it to an LED is series and i still get the same :confused: .

What does this mean ?
What do you mean by "doesn't work ?"
Are you saying the led doesn't light when you pwm the base resistor of the switch ?

raschemmel:
Oh, sorry, got you confused with another post.
What does this mean ?
What do you mean by "doesn't work ?"
Are you saying the led doesn't light when you pwm the base resistor of the switch ?

I'm experiencing a very weird characteristic now. I have found that sometimes when the resistor is plugged in it is saturated but won't turn off and if i wiggle it a bit it will turn off and wont turn back on.

500Hz is the frequency on the squarewave
5V is the voltage peak to peak
50% is the duty cycle of the square wave

Something you are trying to say is just not getting across.

If you are pwming the led , it shouldn't be turning off so what did mean by that ?
Second, if you are testing PWM , using a 50% duty cycle is not the way to do it. You should use the FADE LED Example "File\Examples\Basics\Fade.

raschemmel:
Something you are trying to say is just not getting across.

If you are pwming the led , it shouldn't be turning off so what did mean by that ?
Second, if you are testing PWM , using a 50% duty cycle is not the way to do it. You should use the FADE LED Example "File\Examples\Basics\Fade.

I change my pwm duty cycle via serialmonitor. I have just tried fade as you requested and im getting the same results.

I have just tried fade as you requested and im getting the same results.

What results ?

I'm experiencing a very weird characteristic now. I have found that sometimes when the resistor is plugged in it is saturated but won't turn off and if i wiggle it a bit it will turn off and wont turn back on.

That does not make any sense (it shouldn't happen) with a simple transistor switch. I have never seen it happen.

You shouldn't be touching the wire unless there is a reason to.
Post a photo of your circuit. Something is just not right here.

alexsketchees:
I change my pwm duty cycle via serialmonitor. I have just tried fade as you requested and im getting the same results.

Just to expand more i have tried multiple duty cycles 1% to 99%

raschemmel:
What results ?

That does not make any sense (it shouldn't happen) with a simple transistor switch. I have never seen it happen.

You shouldn't be touching the wire unless there is a reason to.
Post a photo of your circuit. Something is just not right here.

My professor was scratching his head too along with a couple of PHD students. Unfortunately i do not have a working camera. I only have my phone which the camera is broken.

I still don't know what the problem is. If the problem is the transistor won't turn off then there is something wrong with the transisor. I don't know what transistor you are using or what your circuit looks like.
Everything about your post screams "operator error" or "something wrong with the transistor".
We are just going around in circles . In order for this post to get anywhere, you have to describe what you are seeing every time you say you tried something. "seeing the same results" is just not cutting it.

At this point I can only suggest you change the breadboard, transistor and wires. and start over, using just a resistor and led.

If you shorted the base to VDD you probably destroyed the transistor.

Like I said , op error or bad transistor

Are you using one of these?

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What is the part number on the transistor?

With you circuit operating, and a signal coming out of the arduino, what is the voltage between the base and emitter of the transistor?

And definitly check dlloyd point in #15

Thanks ..Tom... :slight_smile:

I've asked for base emitter voltage. The voltage across the base resistor would help too.