Could be a tough one. Sorry in advance.

Hello,
Sorry in advance like i say. idk what is going on here hoping one of you pro's might get it. Ill post the code under. Would seem to work. My arduino has two servos that are wired direct to the motors, running of a l9110 dual h-bridge. it should back up when the ultrasonic sensor reads <4. It does that part fine. When I try to use the IR remote i am using to control it. it shorts. i pull the power really fast and its not fried but something is wrong with the code and not the wiring is what im fairly certain of.

code:

#include "IRremote.h"

int RECV_PIN = 7;

IRrecv irrecv(RECV_PIN);   
decode_results results;  

int trigPin = 13;
int echoPin = 12;

int MOTOR_1A = 2;   
int MOTOR_1B = 3;   
int MOTOR_2A = 4;
int MOTOR_2B = 5; 

int LED6 = 6; 
int LED10 = 10;
int LED11 = 11;

long duration;  //long duration = 0;
int distance;   //int distance = 0;


void setup()
 {
  Serial.begin(9600); 
  Serial.println("Serial communication working");
  irrecv.enableIRIn(); 
  delay(1000);
  Serial.println("IR enabled");
   
  pinMode(trigPin, OUTPUT);  
  pinMode(echoPin, INPUT);
  
  pinMode(MOTOR_1A, OUTPUT); 
  pinMode(MOTOR_1B, OUTPUT); 
  pinMode(MOTOR_2A, OUTPUT); 
  pinMode(MOTOR_2B, OUTPUT);   
  
  pinMode(LED6, OUTPUT);
  digitalWrite(LED6, HIGH);
  delay(1000);
  digitalWrite(LED6,LOW);
  delay(20);  
  digitalWrite(LED10, HIGH);
  delay(1000);
  digitalWrite(LED10,LOW);
  delay(20);
  digitalWrite(LED11, HIGH);
  delay(1000);
  digitalWrite(LED11,LOW);
  delay(20);
 }
 
void loop()
{
  if(irrecv.decode(&results))
 {
  Serial.println(results.value);
  processButton();
  irrecv.resume();   
 }

 {    
   digitalWrite(trigPin, LOW);
   delayMicroseconds(2); 

   digitalWrite(trigPin, HIGH);
   delayMicroseconds(10);

   digitalWrite(trigPin, LOW); 
   duration = pulseIn(echoPin, HIGH); 

   distance= duration*0.034/2; 
   Serial.print("Distance: ");
   Serial.println(distance);
 }

  if(distance <= 4)
  {
    digitalWrite(MOTOR_1A, HIGH);
    digitalWrite(MOTOR_1B, LOW);
    digitalWrite(MOTOR_2A, HIGH);
    digitalWrite(MOTOR_2B, LOW);
    digitalWrite(LED6, HIGH);
    digitalWrite(LED10, LOW);
  }
    else if (distance > 4)
  {
    digitalWrite(MOTOR_1A, LOW);
    digitalWrite(MOTOR_1B, LOW);
    digitalWrite(MOTOR_2A, LOW);
    digitalWrite(MOTOR_2B, LOW); 
    digitalWrite(LED6, LOW);
    digitalWrite(LED10, HIGH);
  } 
} 
  
    
void processButton()
{
  switch (results.value)
  { 
    
    //**********************FORWARD ARROW_A
    case 32:
    //  Serial.println("1");
      digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, HIGH);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, HIGH);
      break;
 
    //**********************FORWARD ARROW_B
    case 2080:
   //   Serial.println("1");
      digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, LOW);
      break;
 
    //**********************BACK ARROW_A
    case 33:
  //    Serial.println("2");
      digitalWrite(MOTOR_1A, HIGH);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, HIGH);
      digitalWrite(MOTOR_2B, LOW);    
      break;
 
    //**********************BACK ARROW_B
    case 2081:
   //   Serial.println("2");
      digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, LOW);
      break;
 
    //**********************LEFT ARROW_A
    case 17:
  //    Serial.println("3");
      digitalWrite(MOTOR_1A, HIGH);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, HIGH);
      break;
 
    //**********************LEFT ARROW_B
    case 2065:
   //   Serial.println("3");
     digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, LOW);
      break;
 
    //**********************RIGHT ARROW_A
    case 16:
   //   Serial.println("4");
      digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, HIGH);
      digitalWrite(MOTOR_2A, HIGH);
      digitalWrite(MOTOR_2B, LOW);
      break;
 
    //**********************RIGHT ARROW_B
    case 2064:
 //     Serial.println("4");
      digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, LOW);
      break; 
  }
}

I hope its not too much trouble I put great effort into trying not to ask for help.

Please post a hand drawn (not Fritzing) wiring diagram, showing ALL the connections, including the servo power.

I assume you modified the servos, but it would still be useful if you could post links to the originals. It is important to know the stall current.

The wiring is very complex. I would prefer not to have to even try what you are asking. I will If I simply must. Its not that I am lazy ok?

Ummm. This is why I feel you might find the problem without all that:

When I get close to it. <4 cm. It works as it should. No short.

The code is written the same for it too back up when too close and for using the remote
to make it go forward.

So why would it do that?

Must be code...

Also please identify the purpose of the MOTOR_xx variables. If they correspond to motor direction and enable, they should be so named.

What do your debug prints tell you?

jgreene33:
The wiring is very complex. I would prefer not to have to even try what you are asking. I will If I simply must. Its not that I am lazy ok?

Then what is your explanation for constructing "very complex" wiring without any documentation? Then you wonder out loud if it will be difficult for other people to help you with it...

MOTOR_XX variables are for the l9110 dual h-bridge. sorry that would have been helpfull for sure.

You are oscillating between implementing an IR instruction and braking the motor because
its not near the wall.

Your code to roll the thing back if too close to the wall should default to what the IR instruction
last told it to do, not a hard brake.

IR transmitters send a rapid stream of repeated codes - just record the last one read and
act on that (don't wait for a new code, otherwise after backing off you won't know what you
should be doing).

Its not a tough one, BTW, you just got confused by starting with the back-off code, rather than implementing
the IR commands first.

Note that the L9110 has no coast setting, its either forwards, backwards or brake.

MarkT!

I knew it was something like that!!! Thank you. Now lets see if I can fix it. if you can put it in order for me id love that. However I understand if its alot to ask. Thanks already!!

So far it looks as though I am only making it worse

#include "IRremote.h"

int RECV_PIN = 7;

IRrecv irrecv(RECV_PIN);   
decode_results results;  

int trigPin = 13;
int echoPin = 12;

int MOTOR_1A = 2;   
int MOTOR_1B = 3;   
int MOTOR_2A = 4;
int MOTOR_2B = 5; 

int LED6 = 6; 
int LED10 = 10;
int LED11 = 11;

long duration;  //long duration = 0;
int distance;   //int distance = 0;


void setup()
 {
  Serial.begin(9600); 
  Serial.println("Serial communication working");
  irrecv.enableIRIn(); 
  delay(1000);
  Serial.println("IR enabled");
   
  pinMode(trigPin, OUTPUT);  
  pinMode(echoPin, INPUT);
  
  pinMode(MOTOR_1A, OUTPUT); 
  pinMode(MOTOR_1B, OUTPUT); 
  pinMode(MOTOR_2A, OUTPUT); 
  pinMode(MOTOR_2B, OUTPUT);   
  
  pinMode(LED6, OUTPUT);
  digitalWrite(LED6, HIGH);
  delay(1000);
  digitalWrite(LED6,LOW);
  delay(20);  
  digitalWrite(LED10, HIGH);
  delay(1000);
  digitalWrite(LED10,LOW);
  delay(20);
  digitalWrite(LED11, HIGH);
  delay(1000);
  digitalWrite(LED11,LOW);
  delay(20);
 }
 
void loop()
{
  if(irrecv.decode(&results))
 {
  Serial.println(results.value);
  processButton();
  irrecv.resume();   
 }
}


void processButton()
{
  switch (results.value)
  { 
    
    //**********************FORWARD ARROW_A
    case 32:
    //  Serial.println("1");
      digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, HIGH);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, HIGH);
      break;
 
    //**********************FORWARD ARROW_B
    case 2080:
   //   Serial.println("1");
      digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, LOW);
      break;
 
    //**********************BACK ARROW_A
    case 33:
  //    Serial.println("2");
      digitalWrite(MOTOR_1A, HIGH);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, HIGH);
      digitalWrite(MOTOR_2B, LOW);    
      break;
 
    //**********************BACK ARROW_B
    case 2081:
   //   Serial.println("2");
      digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, LOW);
      break;
 
    //**********************LEFT ARROW_A
    case 17:
  //    Serial.println("3");
      digitalWrite(MOTOR_1A, HIGH);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, HIGH);
      break;
 
    //**********************LEFT ARROW_B
    case 2065:
   //   Serial.println("3");
     digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, LOW);
      break;
 
    //**********************RIGHT ARROW_A
    case 16:
   //   Serial.println("4");
      digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, HIGH);
      digitalWrite(MOTOR_2A, HIGH);
      digitalWrite(MOTOR_2B, LOW);
      break;
 
    //**********************RIGHT ARROW_B
    case 2064:
 //     Serial.println("4");
      digitalWrite(MOTOR_1A, LOW);
      digitalWrite(MOTOR_1B, LOW);
      digitalWrite(MOTOR_2A, LOW);
      digitalWrite(MOTOR_2B, LOW);
      break;
  }  
   digitalWrite(trigPin, LOW);
   delayMicroseconds(2); 

   digitalWrite(trigPin, HIGH);
   delayMicroseconds(10);

   digitalWrite(trigPin, LOW); 
   duration = pulseIn(echoPin, HIGH); 

   distance= duration*0.034/2; 
   Serial.print("Distance: ");
   Serial.println(distance);

   if(distance <= 4)
    digitalWrite(MOTOR_1A, HIGH);
    digitalWrite(MOTOR_1B, LOW);
    digitalWrite(MOTOR_2A, HIGH);
    digitalWrite(MOTOR_2B, LOW);
}

jgreene33:
The wiring is very complex. I would prefer not to have to even try what you are asking. I will If I simply must. Its not that I am lazy ok?

What have you done to rule out a hardware problem? Because if something actually is "shorting out", that's what you most likely have. Some wire is attached incorrectly or touching something it shouldn't be.

The wiring you have described is not even close to "very complex". Even if it is, the complexity just makes it more important to have an explicit document detailing what's connected to what. Draw out your schematic, then retrace every wire to make sure it is connected exactly where you intend it to be. If that doesn't find the problem, post the schematic. Maybe you designed it incorrectly. Or maybe you designed it correctly but the code is operating it incorrectly. Don't worry about putting us off with complexity, we can handle it.

What is the exact malfunction you are seeing? Describe the symptoms (and the situation that causes those symptoms), not what you think is the cause. A short is not a malfunction, it is a cause of malfunctions.

jgreene33:
The wiring is very complex. I would prefer not to have to even try what you are asking. I will If I simply must. Its not that I am lazy ok?

That's the surest reason I can think of for why it is absolutely essential.

You will almost certainly benefit from the exercise more than we will. Who knows, you might even discover the problem.

...R

jgreene33:
The wiring is very complex.

Then its likely that you have made a wiring error.

Have you checked that all the wiring is correct ?

Its a waste of time (in my experience) trying to debug a project until the wiring is correct.

I am going with what MarkT stated. Did none of you read that? Still need help with that. thanks.

jgreene33:
I am going with what MarkT stated. Did none of you read that? Still need help with that. thanks.

I know the feeling - anything to avoid doing the right thing first :slight_smile:

...R

jgreene33:
I am going with what MarkT stated. Did none of you read that? Still need help with that. thanks.

Are you saying that you like what he said, but you don't understand it? :slight_smile:

Look, seriously, it's something you should look into - so go do it. Look at the program, try to understand the flow. If you can't do that, you can't really do anything much with the Arduino.

Also develop some troubleshooting skills and tricks - one good one is to write simple test programs to prove out different functions of your project. It's one aspect of what's called "divide and conquer" strategy.

lmao aarg that is your name? You do not bother me in the least.

jgreene33:
I am going with what MarkT stated. Did none of you read that? Still need help with that. thanks.

I did, but I am unsure if it actually would fix the problem you described. In fact, I am unsure about what the problem even is because the description is very brief and ambiguous. MarkT noticed that there was conflict between two different command modes, but you described a "short" happening.

I don't know you, so I don't know what level of fluency you have with the jargon. I can't trust that what you are calling a short is actually a short. That is why I asked you to describe exactly what happens under what circumstances, without coloring it with potentially incorrect guesses.

You also have an incomplete specification of behavior. Whenever you have two separate methods of controlling something, they are bound to conflict and you need to define exactly what it supposed to happen in all instances of conflict. What should the robot do if the distance is less than 4 and you are pressing forward on the remote? Should it stop? Back up? Press forward and damn the consequences? Flash its lights at you? Selfdestruct? Taunt you a second time? What does it do when distance is greater than 4?

ok. sorry. that was a mess up. The bot is supposed to and does. back up until its farther then 4cm from an obstacle. its no more advanced then that currently. the short i am referring to is jus a short? like any time you are high on both side of an h-bridge. Heats up so fast it will pop if you dont unplug it. i know you are familiar. jus dont forget. same chunk of code for moving forward via IR as it is for the UltraSonic. So Why the UltraSonic not shorting the h-bridge?