Hey guys,
I am using one of the schematics from the book arduino robotics (schematic below). I have assembled the circuit on a breadboard and while testing I was using a 12 volt 1 amp wall wart for the power supply. using a parallax joystick for motor speed and direction control everything worked good for the first few minutes but then the motor would slow to a stop even with the joystick pushed all the way forward. After testing the mosfets I found the P-Channel in position Q1 to be burned out. I replaced the mosfet (thinking it may have been bad from the start) and got the same result. I looked over the circuit and my sketch for a couple of days then I sent pictures (also below) and my sketch to JD that wrote arduino robotics. He said the circuit looked good and he went over my code and fixed some things that could have caused potential issues. He also told me not to use a battery instead of a wall wart and to make sure to test ALL mosfets. So after testing all mosfets, uploading the new code and using a deep cycle battery from my boat for power supply, I pushed the joystick forward and got a little smoke at full power. Then instead of being smart and stopping I went ahead and pulled it into reverse which caused the Q2 position P channel mosfet to explode. I tried again with the same result( partly because it was cool) and another mosfet bit the dust. Now I did try putting a rectifier diode between the drain pin of both P-channel mosfets and the motor terminal in place of the wires and the H-bridge worked perfectly up until I drew over the 1amp that the diode was rated for and it popped but I expected this. Also if I disconnect from the bread board Q1 and Q4 forward will work and unplugging the opposite lets reverse or vice versa work perfectly. I am tempted to just put higher current rated diodes in place and just continue with my project but I do not want to apply the "duct tape" repair to this. I am new to arduino and I am learning as I go but I want to learn the correct way to do things and I also want to learn the "why" behind what I am doing. If I just skip over this problem with a quick fix whatever I am doing wrong weather it is my fundamentals or my execution will continue to come back and cause problems in future projects until I figure out what I am doing wrong. Any help would be greatly appreciated. Oh by the way the motor being controlled is a small gear motor out of a kids power wheels and I am pretty sure it is not drawing anywhere near the 27amp current limit of these mosfets. The p and n channel mosfets are from sparkfun N-Channel MOSFET 60V 30A - COM-10213 - SparkFun Electronics and N-Channel MOSFET 60V 30A - COM-10213 - SparkFun Electronics
Here is the sketch
int potpin = 0; // joystick
int gearspeed = 0;
int rvgearlight = 12; // led reverse gear indicator
int fwgearlight = 11; // led forward gear indicator
int neutrallight = 13; // led neutral indicator
int deadband = 25;
int AHI = 2; // these names are more descriptive - A side High input (AHI) - you can open one switch on the A side and one on the B side at a time with no problems.
int BHI = 3; // B side High input
int ALI = 5; // A side Low input
int BLI = 6; // B side Low input
void setup()
{
Serial. begin(9600);
pinMode(potpin, INPUT);
pinMode(fwgearlight, OUTPUT);
pinMode(rvgearlight, OUTPUT);
pinMode(neutrallight, OUTPUT);
pinMode(AHI, OUTPUT);
pinMode(ALI, OUTPUT);
pinMode(BHI, OUTPUT);
pinMode(BLI, OUTPUT);
neutral();
}
void loop(){
read_signal(); // read the potentiometer, adjust the value to a fwd/rev, then make sure it doesn't go over the
Serial.println(potpin);
if (gearspeed > deadband){ //joystick pushed forward
forward();
}
else if (gearspeed < -deadband){ //joystick pulled back
reverse();
}
else { //joystick sitting in center
neutral();
}
}
void read_signal(){
potpin = analogRead(0);
gearspeed = map(potpin, 0, 1023, -255, 255);
if (gearspeed > 255){
gearspeed = 255;
}
else if (gearspeed < -255){
gearspeed = -255;
}
}
void forward(){
digitalWrite(neutrallight, LOW);
digitalWrite(rvgearlight, LOW);
digitalWrite(fwgearlight, HIGH);
// write motor values
digitalWrite(AHI, LOW);
digitalWrite(BLI, LOW);
digitalWrite(BHI, HIGH);
analogWrite(ALI, gearspeed);
}
void reverse(){
digitalWrite(neutrallight, LOW);
digitalWrite(fwgearlight, LOW);
digitalWrite(rvgearlight, HIGH);
// write motor values
digitalWrite(BHI, LOW);
digitalWrite(ALI, LOW);
digitalWrite(AHI, HIGH);
analogWrite(BLI, -gearspeed); // since the gearspeed value is negative, we want to make it positive but use the same speed value.
}
void neutral(){
// everything is turned off except the neutral indicator light
digitalWrite(neutrallight, HIGH);
digitalWrite(fwgearlight, LOW);
digitalWrite(rvgearlight, LOW); // turns off forward and reverse indicator leds
digitalWrite(BHI, LOW);
digitalWrite(AHI, LOW);
digitalWrite(ALI, LOW);
digitalWrite(BLI, LOW);
}



