Increase Arduino Speed

Hello. I am new to Arduino. I started about a month ago because I wanted to design a project for my garage. Two cars. Report distance to side wall, fender and trunk of each car, four sensors total, with Yellow/Red flashers, and monitor and close garage doors if they were left open, with a warning beeper. I am using Arduino Uno with the IDE I downloaded from the website.

All done. Works fine. But it's slow, making a full pass about every two seconds. My wife could wreck the car by then!

Just kidding!

So I did some homework about speeding it up. New to programming as I am, I was looking to install the digitalWriteFast library to try to increase speed instead of learning about mapping out each pin - a poor man's shortcut, I know, but probably the best place for me to start.

I installed the latest zip library from 2010, best I could find, but when I put "#include<digitalWristFast.h>" into the sketch, Arduino will not compile when I try to verify, even before I try to change any of the commands in my sketch. I already have a code in the sketch to include a servo library "#include <Servo.h>" and that one works fine, so I don't think I'm typing wrong.....and I used the drop down shortcuts to install the library just to make sure.

Soooooo, questions are:

  1. Is using this library an acceptable method of increasing speed.
  2. How do I include the library and get it to compile.

Thanks sooooo much!

Harv-e

(deleted)

I agree with above, maybe its the code that can be improved to be faster.

Harv-e:
Works fine. But it's slow, making a full pass about every two seconds.

;yikes !!!
I will bet that you have a command delay(??) or multiple ones !
you should be saying that it scans about 20 times a second....
read the sticky post on the forum about how to use this forum and scroll down about how to post code.
I will venture that we can speed it up way faster !

Thanks for suggesting to review my code. It is attached as a doc file as it is long.

Double garage door closer.doc (54 KB)

I think that it is because it is a doc file that it is long. There is no way I will stoop to opening it in Word. Some people can't even do that. Please read these two posts:

How to use this forum - please read.
and
Read this before posting a programming question ...
You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons.
If you have already posted without using code tags, open your message and select "modify" from the pull down menu labelled, "More", at the lower left corner of the message. Highlight your code by selecting it (it turns blue), and then click on the "</>" icon at the upper left hand corner. Click on the "Save" button. Code tags can also be inserted manually in the forum text using the code and /code metatags.

Unless the sketch is really too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

If you must attach it, please attach a plain text file (.ino)

Anyway...messy.

 pinMode(buzzer, OUTPUT);
 pinMode (trigPinFrontLeft, OUTPUT);
pinMode(echoPinFrontLeft, INPUT);
pinMode(trigPinRearLeft, OUTPUT);
pinMode(echoPinRearLeft, INPUT);
pinMode(dangerGateLeft, OUTPUT);
pinMode(cautionGateLeft, OUTPUT);
pinMode(servoControlPin, OUTPUT);
pinMode(garageSwitchLeft, INPUT);
pinMode(garageSwitchRight, INPUT);
pinMode(closeLeftGarage, OUTPUT);
pinMode(closeRightGarage, OUTPUT);

pinMode(trigPinFrontRight, OUTPUT);
pinMode(echoPinFrontRight, INPUT);
pinMode(trigPinRearRight, OUTPUT);
pinMode(echoPinRearRight, INPUT);
pinMode(dangerGateRight , OUTPUT);
pinMode(cautionGateRight, OUTPUT);

Could easily be:

byte output_pins[]={1,2,3,4,5};  //replace with relvent pin numbers
byte input_pins[]={6,7,8,9,10};  //replace with relevent pin numbers

for (byte i=0;i<sizeof(output_pins);i++){
  pinMode(output_pins[i],OUTPUT);
}
for (byte i=0;i<sizeof(input_pins);i++){
  pinMode(input_pins[i],INPUT);
}

There is probably even a "shorter/correct" way to do this...but at least it will tidy up that "mess".

Anyway...the amount of code you have for such a simple system is almost mind-boggling....there must be something more logical...

Even by glancing over your code, there are multiple delay() functions which pause your program for quite a while (not added them up...but I bet it is at least a second or two!)

Johnny010, I strongly disagree. The OP has used named constants for the pins and should not be discouraged from doing so. Using pin numbers instead is a backwards step.

aarg:
Johnny010, I strongly disagree. The OP has used named constants for the pins and should not be discouraged from doing so. Using pin numbers instead is a backwards step.

Fair enough, I thought there may be a reason it is not done.

Johnny010:
Fair enough, I thought there may be a reason it is not done.

In either case, it's in setup() where it can't slow the program except at the instant when it is started.

the whole sketch was too long, here is just under vold loop()

as you can see, there are delay() places all over the code.

void loop() {
  //left garage
  // digitalWrite(garageSwitchLeft, LOW);//not sure this line should be here
  digitalWriteFast(dangerGateLeft, LOW);
  digitalWrite(cautionGateLeft, LOW);
  if (digitalRead(garageSwitchLeft) == LOW)
  {
    timingCounterLeft = 0;
  }

  if (digitalRead(garageSwitchLeft) == HIGH)
  {
    //start the left timer code here
    timingCounterLeft++;
    if (timingCounterLeft > 800)
    {
      digitalWrite(garageSwitchLeft, HIGH);
      delay(250);
      digitalWrite(garageSwitchLeft, LOW);
    }

    digitalWrite(trigPinFrontLeft, LOW); // set the trigger pin low
    delayMicroseconds(200);//pause to let signal settle
    digitalWrite(trigPinFrontLeft, HIGH);// set trigger pin high
    delayMicroseconds(15);//pause in high state
    digitalWrite(trigPinFrontLeft, LOW);// bring trig pin back low

    pingTimeFrontLeft = pulseIn(echoPinFrontLeft, HIGH);// measure ping time at echo pin in microseconds
    //pingTimeFrontLeft = pingTimeFrontLeft/1000000.0;//converts pingtime to seconds
    //pingTimeFrontLeft = pingTimeFrontLeft/3600.0;//converts pingtime in seconds to pingtime in hours
    pingTimeFrontLeft = pingTimeFrontLeft / 3600000000.0;
    targetDistanceFrontLeft = speedOfSound * pingTimeFrontLeft;//distance equals rate times time to calculate distance in miles
    targetDistanceFrontLeft = targetDistanceFrontLeft / 2; //accounts for round trip for ping
    targetDistanceFrontLeft = targetDistanceFrontLeft * 63360.0;//converts target distance to inches  (63360 inches in a mile)

    digitalWrite(trigPinRearLeft, LOW); // set the trigger pin low
    delayMicroseconds(200);//pause to let signal settle
    digitalWrite(trigPinRearLeft, HIGH);// set trigger pin high
    delayMicroseconds(15);//pause in high state
    digitalWrite(trigPinRearLeft, LOW);// bring trig pin back low

    pingTimeRearLeft = pulseIn(echoPinRearLeft, HIGH);// measure ping time at echo pin in microseconds
    //pingTimeRearLeft = pingTimeRearLeft/1000000.0;//converts pingtime to seconds
    //pingTimeRearLeft = pingTimeRearLeft/3600.0;//converts pingtime in seconds to pingtime in hours
    pingTimeRearLeft = pingTimeRearLeft / 3600000000.0;

    targetDistanceRearLeft = speedOfSound * pingTimeRearLeft;//distance equals rate times time to calculate distance in miles
    targetDistanceRearLeft = targetDistanceRearLeft / 2; //accounts for round trip for ping
    targetDistanceRearLeft = targetDistanceRearRight * 63360.0;//converts target distance to inches  (63360 inches in a mile)

    /*
      Serial.print("The Distance to the Left Front target is   ");
      Serial.print(targetDistanceFrontLeft);
      Serial.print("  inches");
      Serial.print("......The Distance to the Left Rear target is   ");
      Serial.print(targetDistanceRearLeft);
      Serial.println("  inches");
      Serial.print("Timing Counter Left  ");
      Serial.println(timingCounterLeft);
    */

    //looking for danger distances
    int dangerLeft = 0;//no danger before readings

    if (( targetDistanceFrontLeft < minTargetDistanceFrontLeft) || (targetDistanceRearLeft < minTargetDistanceRearLeft))
    {

      digitalWrite(dangerGateLeft, HIGH);
      int dangerLeft = 1;
    }

    //looking for caution distances
    if (((targetDistanceFrontLeft < maxTargetDistanceFrontLeft) && (targetDistanceFrontLeft > minTargetDistanceFrontLeft)) || ((targetDistanceRearLeft < maxTargetDistanceRearLeft) && (targetDistanceRearLeft > minTargetDistanceRearLeft)) && dangerLeft == 0)
    {

      digitalWrite(cautionGateLeft, HIGH);
    }

    //setting up the pointer for front distances
    if (targetDistanceFrontLeft > 7.0)
    {
      targetDistanceFrontLeft = 7.0;//range pointer cannot be greater than 7
    }
    servoAngle = (120. / 7.) * targetDistanceFrontLeft + 30; //calculate servoAngle myPointer.write(servoAngle);//write servo angle to myPointer 30 to 150 every 17 degrees to 7 inches maximum
    delay(1);//delay to slow things down

  }
  //right garage
  //digitalWrite(garageSwitchRight, LOW);//not sure this line should be here
  digitalWrite(dangerGateRight, LOW);
  digitalWrite(cautionGateRight, LOW);
  if (digitalRead(garageSwitchRight) == LOW)
  {
    timingCounterRight = 0;
  }

  if (digitalRead(garageSwitchRight) == HIGH)
  {
    //start the right timer code here
    timingCounterRight++;
    if (timingCounterRight > 800)
    {
      digitalWrite(garageSwitchRight, HIGH);
      delay(250);
      digitalWrite(garageSwitchRight, LOW);
    }


    digitalWrite(trigPinFrontRight, LOW); // set the trigger pin low
    delayMicroseconds(200);//pause to let signal settle
    digitalWrite(trigPinFrontRight, HIGH);// set trigger pin high
    delayMicroseconds(15);//pause in high state
    digitalWrite(trigPinFrontRight, LOW);// bring trig pin back low

    pingTimeFrontRight = pulseIn(echoPinFrontRight, HIGH);// measure ping time at echo pin in microseconds
    //pingTimeFrontRight = pingTimeFrontRight/1000000.0;//converts pingtime to seconds
    //pingTimeFrontRight = pingTimeFrontRight/3600.0;//converts pingtime in seconds to pingtime in hours
    pingTimeFrontRight = pingTimeFrontRight / 3600000000.0;

    targetDistanceFrontRight = speedOfSound * pingTimeFrontRight;//distance equals rate times time to calculate distance in miles
    targetDistanceFrontRight = targetDistanceFrontRight / 2; //accounts for round trip for ping
    targetDistanceFrontRight = targetDistanceFrontRight * 63360.0;//converts target distance to inches  (63360 inches in a mile)

    digitalWrite(trigPinRearRight, LOW); // set the trigger pin low
    delayMicroseconds(200);//pause to let signal settle
    digitalWrite(trigPinRearRight, HIGH);// set trigger pin high
    delayMicroseconds(15);//pause in high state
    digitalWrite(trigPinRearRight, LOW);// bring trig pin back low

    pingTimeRearRight = pulseIn(echoPinRearRight, HIGH);// measure ping time at echo pin in microseconds
    //pingTimeRearRight = pingTimeRearRight/1000000.0;//converts pingtime to seconds
    //pingTimeRearRight = pingTimeRearRight/3600.0;//converts pingtime in seconds to pingtime in hours
    pingTimeRearRight = pingTimeRearRight / 3600000000.0;

    targetDistanceRearRight = speedOfSound * pingTimeRearRight;//distance equals rate times time to calculate distance in miles
    targetDistanceRearRight = targetDistanceRearRight / 2; //accounts for round trip for ping
    targetDistanceRearRight = targetDistanceRearRight * 63360.0;//converts target distance to inches  (63360 inches in a mile)

    //Serial.print("The Distance to the Right Front target is   ");
    //Serial.print(targetDistanceFrontRight);
    //Serial.print("  inches");
    //Serial.print("......The Distance to the Right Rear target is   ");
    Serial.print(targetDistanceRearRight);
    //Serial.println("  inches");

    //Serial.println("Loop Time Left is ");
    //Serial.print(loopTimeLeft);
    //Serial.print("   microseconds.....");
    //Serial.print("Loop Time Right is  ");
    //Serial.print(loopTimeRight);
    //Serial.println("   microseconds");


    //looking for danger distances
    int dangerRight = 0;//no danger before readings

    if (( targetDistanceFrontRight < minTargetDistanceFrontRight) || (targetDistanceRearRight < minTargetDistanceRearRight))
    {

      digitalWrite(dangerGateRight, HIGH);
      int dangerRight = 1;
    }

    //looking for caution distances
    if (((targetDistanceFrontRight < maxTargetDistanceFrontRight) && (targetDistanceFrontRight > minTargetDistanceFrontRight)) || ((targetDistanceRearRight < maxTargetDistanceRearRight) && (targetDistanceRearRight > minTargetDistanceRearRight)) && dangerRight == 0)
    {

      digitalWrite(cautionGateRight, HIGH);
    }


  }
  /*
    Serial.print("Left Timing Counter = ");
    Serial.print(timingCounterLeft);
    Serial.print(".......Right Timing Counter = ");
    Serial.println(timingCounterRight);
  */

  //It takes 800 passes to go through the program in about 20 minutes
  if (((timingCounterLeft > 750) || (timingCounterRight > 750)) && ((timingCounterLeft < 780) || (timingCounterRight < 780)))
  {
    tone(A4, 2000, 10);//A0 output for buzzer does not have to be declared

    delay(500);        // delay in between reads between 500 (slow) and 100 (fast)
  }
  if ((timingCounterLeft > 780) || (timingCounterRight > 780))
  {
    tone(A4, 2000, 10);
    delay(100);
  }
}

here is the other half

//Double garage door closer, two car parking monitor with graphic display and warning lights

#include <Servo.h>//load the server library


int buzzer = A4;
int trigPinFrontLeft = A0;
int echoPinFrontLeft = 10;
int trigPinRearLeft = A1;
int echoPinRearLeft = 11;
int dangerGateLeft = 2;//to turn on red flasher transistor base
int cautionGateLeft = 1;//to turn on yellow flasher transistor base
int servoControlPin = 3;
int dangerLeft;
int dangerRight;
int garageSwitchLeft = 8;//NC when garage is closed
int garageSwitchRight = 9;//NC when garage is closed
int closeLeftGarage = 6;//output to close the left garage door relay
int closeRightGarage = 7;//output to close right garage door relay

int trigPinFrontRight = A2;
int echoPinFrontRight = 12;
int trigPinRearRight = A3;
int echoPinRearRight = 13;
int dangerGateRight = 5;//to turn on red flasher transistor base
int cautionGateRight = 4;//to turn on yellow flasher transistor base

int timingCounterLeft;//counts the number of times through the program when garage door open
int timingCounterRight;
//counts to 40 for each minute

float pingTimeFrontLeft;//time for ping to travel to target and return
float targetDistanceFrontLeft;//distance from sensor to target

float pingTimeRearLeft;//time for ping to travel to target and return
float targetDistanceRearLeft;//distance from sensor to target

float pingTimeFrontRight;//time for ping to travel to target and return
float targetDistanceFrontRight;//distance from sensor to target

float pingTimeRearRight;//time for ping to travel to target and return
float targetDistanceRearRight;//distance from sensor to target

float speedOfSound = 776.5;//speed of sound in mph
float servoAngle;//variable for the angle of the servo

//set up the parameters for the CAUTION range
float maxTargetDistanceFrontRight = 2.0;
float minTargetDistanceFrontRight = 1.0;
float maxTargetDistanceRearRight = 4.0;
float minTargetDistanceRearRight = 3.0;

float maxTargetDistanceFrontLeft = 2.0;
float minTargetDistanceFrontLeft = 1.0;
float maxTargetDistanceRearLeft = 4.0;
float minTargetDistanceRearLeft = 3.0;




Servo myPointer;//create a servo object called myPointer

void setup() {

  pinMode(buzzer, OUTPUT);
  pinMode (trigPinFrontLeft, OUTPUT);
  pinMode(echoPinFrontLeft, INPUT);
  pinMode(trigPinRearLeft, OUTPUT);
  pinMode(echoPinRearLeft, INPUT);
  pinMode(dangerGateLeft, OUTPUT);
  pinMode(cautionGateLeft, OUTPUT);
  pinMode(servoControlPin, OUTPUT);
  pinMode(garageSwitchLeft, INPUT);
  pinMode(garageSwitchRight, INPUT);
  pinMode(closeLeftGarage, OUTPUT);
  pinMode(closeRightGarage, OUTPUT);

  pinMode(trigPinFrontRight, OUTPUT);
  pinMode(echoPinFrontRight, INPUT);
  pinMode(trigPinRearRight, OUTPUT);
  pinMode(echoPinRearRight, INPUT);
  pinMode(dangerGateRight , OUTPUT);
  pinMode(cautionGateRight, OUTPUT);



  Serial.begin(9600);
  pinMode(servoControlPin, OUTPUT);//servo control pin is an output
  myPointer.attach(servoControlPin);//tell Arduino where the servo is connected

}

void loop() {
[code/]

I thought the code was long so I attached it. Maybe it's not as long as I thought, so I have placed it here in <>. I could break this up into four separate programs, one to close each garage door, and one to park each car. That would be fastest. But as a learning process, I thought that I would try to make this run faster. I tried to load the library pinWriteFast.h and change my commands, but it will not load. If there are other delays in this code I am not aware of them in this stage of my programming, so help is MUCH appreciated. Thanks again.

//Double garage door closer, two car parking monitor with graphic display and warning lights

#include <Servo.h>//load the server library


int buzzer=A4;
int trigPinFrontLeft=A0;
int echoPinFrontLeft=10;
int trigPinRearLeft=A1;
int echoPinRearLeft=11;
int dangerGateLeft = 2;//to turn on red flasher transistor base
int cautionGateLeft = 1;//to turn on yellow flasher transistor base
int servoControlPin=3;
int dangerLeft;
int dangerRight;
int garageSwitchLeft = 8;//NC when garage is closed
int garageSwitchRight = 9;//NC when garage is closed
int closeLeftGarage = 6;//output to close the left garage door relay
int closeRightGarage = 7;//output to close right garage door relay

int trigPinFrontRight=A2;
int echoPinFrontRight=12;
int trigPinRearRight=A3;
int echoPinRearRight=13;
int dangerGateRight = 5;//to turn on red flasher transistor base
int cautionGateRight = 4;//to turn on yellow flasher transistor base

int timingCounterLeft;//counts the number of times through the program when garage door open
int timingCounterRight;
//counts to 40 for each minute

float pingTimeFrontLeft;//time for ping to travel to target and return
float targetDistanceFrontLeft;//distance from sensor to target

float pingTimeRearLeft;//time for ping to travel to target and return
float targetDistanceRearLeft;//distance from sensor to target

float pingTimeFrontRight;//time for ping to travel to target and return
float targetDistanceFrontRight;//distance from sensor to target

float pingTimeRearRight;//time for ping to travel to target and return
float targetDistanceRearRight;//distance from sensor to target

float speedOfSound = 776.5;//speed of sound in mph
float servoAngle;//variable for the angle of the servo

//set up the parameters for the CAUTION range
float maxTargetDistanceFrontRight = 2.0;
float minTargetDistanceFrontRight = 1.0;
float maxTargetDistanceRearRight = 4.0;
float minTargetDistanceRearRight = 3.0;

float maxTargetDistanceFrontLeft = 2.0;
float minTargetDistanceFrontLeft= 1.0;
float maxTargetDistanceRearLeft = 4.0;
float minTargetDistanceRearLeft = 3.0;




Servo myPointer;//create a servo object called myPointer

void setup(){

   pinMode(buzzer, OUTPUT);
 pinMode (trigPinFrontLeft, OUTPUT);
pinMode(echoPinFrontLeft, INPUT);
pinMode(trigPinRearLeft, OUTPUT);
pinMode(echoPinRearLeft, INPUT);
pinMode(dangerGateLeft, OUTPUT);
pinMode(cautionGateLeft, OUTPUT);
pinMode(servoControlPin, OUTPUT);
pinMode(garageSwitchLeft, INPUT);
pinMode(garageSwitchRight, INPUT);
pinMode(closeLeftGarage, OUTPUT);
pinMode(closeRightGarage, OUTPUT);

pinMode(trigPinFrontRight, OUTPUT);
pinMode(echoPinFrontRight, INPUT);
pinMode(trigPinRearRight, OUTPUT);
pinMode(echoPinRearRight, INPUT);
pinMode(dangerGateRight , OUTPUT);
pinMode(cautionGateRight, OUTPUT);


   
Serial.begin(9600);
pinMode(servoControlPin, OUTPUT);//servo control pin is an output
myPointer.attach(servoControlPin);//tell Arduino where the servo is connected

}

void loop() {
//left garage
// digitalWrite(garageSwitchLeft, LOW);//not sure this line should be here
  digitalWriteFast(dangerGateLeft, LOW);
    digitalWrite(cautionGateLeft, LOW);
if (digitalRead(garageSwitchLeft)== LOW)
{
 timingCounterLeft = 0;
}
 
  if (digitalRead(garageSwitchLeft) == HIGH)
  {
    //start the left timer code here  
timingCounterLeft++;
if (timingCounterLeft>800)
{
  digitalWrite(garageSwitchLeft, HIGH);
  delay(250);
  digitalWrite(garageSwitchLeft, LOW);
}
  
digitalWrite(trigPinFrontLeft, LOW); // set the trigger pin low
delayMicroseconds(200);//pause to let signal settle
digitalWrite(trigPinFrontLeft, HIGH);// set trigger pin high
delayMicroseconds(15);//pause in high state
digitalWrite(trigPinFrontLeft, LOW);// bring trig pin back low

pingTimeFrontLeft = pulseIn(echoPinFrontLeft, HIGH);// measure ping time at echo pin in microseconds
//pingTimeFrontLeft = pingTimeFrontLeft/1000000.0;//converts pingtime to seconds
//pingTimeFrontLeft = pingTimeFrontLeft/3600.0;//converts pingtime in seconds to pingtime in hours
pingTimeFrontLeft = pingTimeFrontLeft/3600000000.0;
targetDistanceFrontLeft = speedOfSound * pingTimeFrontLeft;//distance equals rate times time to calculate distance in miles
targetDistanceFrontLeft = targetDistanceFrontLeft/2;//accounts for round trip for ping
targetDistanceFrontLeft = targetDistanceFrontLeft * 63360.0;//converts target distance to inches  (63360 inches in a mile)

digitalWrite(trigPinRearLeft, LOW); // set the trigger pin low
delayMicroseconds(200);//pause to let signal settle
digitalWrite(trigPinRearLeft, HIGH);// set trigger pin high
delayMicroseconds(15);//pause in high state
digitalWrite(trigPinRearLeft, LOW);// bring trig pin back low

pingTimeRearLeft = pulseIn(echoPinRearLeft, HIGH);// measure ping time at echo pin in microseconds
//pingTimeRearLeft = pingTimeRearLeft/1000000.0;//converts pingtime to seconds
//pingTimeRearLeft = pingTimeRearLeft/3600.0;//converts pingtime in seconds to pingtime in hours
pingTimeRearLeft = pingTimeRearLeft/3600000000.0;

targetDistanceRearLeft = speedOfSound * pingTimeRearLeft;//distance equals rate times time to calculate distance in miles
targetDistanceRearLeft = targetDistanceRearLeft/2;//accounts for round trip for ping
targetDistanceRearLeft = targetDistanceRearRight * 63360.0;//converts target distance to inches  (63360 inches in a mile)

/*
Serial.print("The Distance to the Left Front target is   ");
Serial.print(targetDistanceFrontLeft);
Serial.print("  inches");
Serial.print("......The Distance to the Left Rear target is   ");
Serial.print(targetDistanceRearLeft);
Serial.println("  inches");
Serial.print("Timing Counter Left  ");
Serial.println(timingCounterLeft);
*/

//looking for danger distances
int dangerLeft = 0;//no danger before readings

if (( targetDistanceFrontLeft < minTargetDistanceFrontLeft) || (targetDistanceRearLeft < minTargetDistanceRearLeft))
{

digitalWrite(dangerGateLeft, HIGH);
int dangerLeft = 1;
}

//looking for caution distances
if (((targetDistanceFrontLeft< maxTargetDistanceFrontLeft) && (targetDistanceFrontLeft > minTargetDistanceFrontLeft)) || ((targetDistanceRearLeft< maxTargetDistanceRearLeft) && (targetDistanceRearLeft > minTargetDistanceRearLeft)) && dangerLeft == 0)
{
  
  digitalWrite(cautionGateLeft, HIGH);
}

//setting up the pointer for front distances
if (targetDistanceFrontLeft>7.0)
{
  targetDistanceFrontLeft = 7.0;//range pointer cannot be greater than 7
  }
servoAngle = (120./7.) * targetDistanceFrontLeft + 30;//calculate servoAngle myPointer.write(servoAngle);//write servo angle to myPointer 30 to 150 every 17 degrees to 7 inches maximum
delay(1);//delay to slow things down

}
//right garage
 //digitalWrite(garageSwitchRight, LOW);//not sure this line should be here
  digitalWrite(dangerGateRight, LOW);
    digitalWrite(cautionGateRight, LOW);
if (digitalRead(garageSwitchRight)== LOW)
{
 timingCounterRight = 0;
}
 
  if (digitalRead(garageSwitchRight) == HIGH)
  {
    //start the right timer code here  
timingCounterRight++;
if (timingCounterRight>800)
{
  digitalWrite(garageSwitchRight, HIGH);
  delay(250);
  digitalWrite(garageSwitchRight, LOW);
}
  
  
digitalWrite(trigPinFrontRight, LOW); // set the trigger pin low
delayMicroseconds(200);//pause to let signal settle
digitalWrite(trigPinFrontRight, HIGH);// set trigger pin high
delayMicroseconds(15);//pause in high state
digitalWrite(trigPinFrontRight, LOW);// bring trig pin back low

pingTimeFrontRight = pulseIn(echoPinFrontRight, HIGH);// measure ping time at echo pin in microseconds
//pingTimeFrontRight = pingTimeFrontRight/1000000.0;//converts pingtime to seconds
//pingTimeFrontRight = pingTimeFrontRight/3600.0;//converts pingtime in seconds to pingtime in hours
pingTimeFrontRight = pingTimeFrontRight/3600000000.0;

targetDistanceFrontRight = speedOfSound * pingTimeFrontRight;//distance equals rate times time to calculate distance in miles
targetDistanceFrontRight = targetDistanceFrontRight/2;//accounts for round trip for ping
targetDistanceFrontRight = targetDistanceFrontRight * 63360.0;//converts target distance to inches  (63360 inches in a mile)

digitalWrite(trigPinRearRight, LOW); // set the trigger pin low
delayMicroseconds(200);//pause to let signal settle
digitalWrite(trigPinRearRight, HIGH);// set trigger pin high
delayMicroseconds(15);//pause in high state
digitalWrite(trigPinRearRight, LOW);// bring trig pin back low

pingTimeRearRight = pulseIn(echoPinRearRight, HIGH);// measure ping time at echo pin in microseconds
//pingTimeRearRight = pingTimeRearRight/1000000.0;//converts pingtime to seconds
//pingTimeRearRight = pingTimeRearRight/3600.0;//converts pingtime in seconds to pingtime in hours
pingTimeRearRight = pingTimeRearRight/3600000000.0;

targetDistanceRearRight = speedOfSound * pingTimeRearRight;//distance equals rate times time to calculate distance in miles
targetDistanceRearRight = targetDistanceRearRight/2;//accounts for round trip for ping
targetDistanceRearRight = targetDistanceRearRight * 63360.0;//converts target distance to inches  (63360 inches in a mile)

//Serial.print("The Distance to the Right Front target is   ");
//Serial.print(targetDistanceFrontRight);
//Serial.print("  inches");
//Serial.print("......The Distance to the Right Rear target is   ");
Serial.print(targetDistanceRearRight);
//Serial.println("  inches");

//Serial.println("Loop Time Left is ");
//Serial.print(loopTimeLeft);
//Serial.print("   microseconds.....");
//Serial.print("Loop Time Right is  ");
//Serial.print(loopTimeRight);
//Serial.println("   microseconds");


//looking for danger distances
int dangerRight = 0;//no danger before readings

if (( targetDistanceFrontRight < minTargetDistanceFrontRight) || (targetDistanceRearRight < minTargetDistanceRearRight))
{

digitalWrite(dangerGateRight, HIGH);
int dangerRight = 1;
}

//looking for caution distances
if (((targetDistanceFrontRight< maxTargetDistanceFrontRight) && (targetDistanceFrontRight > minTargetDistanceFrontRight)) || ((targetDistanceRearRight< maxTargetDistanceRearRight) && (targetDistanceRearRight > minTargetDistanceRearRight)) && dangerRight == 0)
{
  
  digitalWrite(cautionGateRight, HIGH);
}


}
/*
Serial.print("Left Timing Counter = ");
Serial.print(timingCounterLeft);
Serial.print(".......Right Timing Counter = ");
Serial.println(timingCounterRight);
*/

//It takes 800 passes to go through the program in about 20 minutes
if (((timingCounterLeft>750) || (timingCounterRight>750)) && ((timingCounterLeft<780) || (timingCounterRight<780)))
{
  tone(A4, 2000, 10);//A0 output for buzzer does not have to be declared
   
  delay(500);        // delay in between reads between 500 (slow) and 100 (fast)
}
if ((timingCounterLeft>780) || (timingCounterRight>780))
{
 tone(A4, 2000, 10);
delay(100); 
}
}

Harv-e:
If there are other delays in this code I am not aware of them in this stage of my programming, so help is MUCH appreciated.

The part of code you posted in that message a couple of delays. Did you try find (Ctrl-F)?

And if you want to speedup your code if it is still too slow after removing all delay() and most delayMicroseconds(),
you should drop all floating point stuff. It's hardly neccessary and very slow.

Compute you distances in mm, µm or whatever fits your need, no fractions needed.

Same holds true for angles, times, ...

All you needed to do was attach it as a text file. But it sounds like you have a lot of work to do, so next time it will be smaller :). I'm not trying to be mean, it just really is too much trouble to deal with .DOC files. If it was once, okay, but I do it too many times a day.