4 ping Ultrasonic sensor

Hello.

Someone bored can help me with my project?

I found this code for a 3 ping ultrasonic sensor. I have problems to make it work with my 4 ping ultrasonic sensor -
(HC-SR04).

I am getting crazy with something apparently easy.

I want you to change the code so it works with a 4 ping ultrasonic sensor.

i want to save the code so it works with the motors, only make it valid for a 4 ping ultrasonic sensor.

Thanks.

Code for the ZumoBot, with Ping Sensor on Servo to do obstacle avoidance.


*/

#include <Ping.h>
#include <ZumoMotors.h>

Ping ping = Ping(4);

int left = 150;
int right = 80;
int center = 120;

int count = 0;

ZumoMotors motors;
 
void setup() {  
  pinMode(13, OUTPUT);
    
  Serial.begin(9600);    // start serial communication at 9600 baud
} 
 
 
void loop() 
{ 
  if(count == 0) {
    for(int i = 0; i<5; i++) {    // do this 5 times
    ping.fire();
    
    int inches = ping.inches();  // where is everything?
    int cm = ping.centimeters();
    int mseconds = ping.microseconds();
    
    Serial.print(inches);  // print values out on serial monitor
    Serial.print(" , ");
    Serial.print(cm);
    Serial.print(" , ");
    Serial.println(mseconds);

    motors.setRightSpeed(400);  // full speed ahead
    motors.setLeftSpeed(400);
    
    delay(100);
    
    if(inches <= 6) {    // if the FuzzBot gets too close...
            
    digitalWrite(13, HIGH);  // turn the other way

    motors.setLeftSpeed(-400);
    motors.setRightSpeed(400);
 
    delay(300);
  }else{
    digitalWrite(13, LOW);
    
    motors.setLeftSpeed(400);
    motors.setRightSpeed(400);
    count = 1;
    }
  }
}
   if(count == 1) {
     for(int i = 0; i<5; i++) {  // do this 5 times
         
    ping.fire();
    
    int inches = ping.inches();   // where are we???
    int cm = ping.centimeters();
    int mseconds = ping.microseconds();
    
    Serial.print(inches);  // print on the serial monitor
    Serial.print(" , ");
    Serial.print(cm);
    Serial.print(" , ");
    Serial.println(mseconds);

    motors.setRightSpeed(400);  // full speed
    motors.setLeftSpeed(400);
    
    delay(100);
    
    if(inches <= 6) {    // if the FuzzBot is too close, turn the other way
            
    digitalWrite(13, HIGH);

    motors.setLeftSpeed(-400);
    motors.setRightSpeed(400);
 
    delay(300);
  }else{
    digitalWrite(13, LOW);
    
    motors.setLeftSpeed(400);
    motors.setRightSpeed(400);
       }
     }
   }
}

I found this code for a 3 ping ultrasonic sensor.

That's not code. That's a quote. Code goes in code tags, not quote tags.

What is a 3 ping ultrasonic sensor? What is a 4 ping ultrasonic sensor?

PaulS:

I found this code for a 3 ping ultrasonic sensor.

That's not code. That's a quote. Code goes in code tags, not quote tags.

What is a 3 ping ultrasonic sensor? What is a 4 ping ultrasonic sensor?

Sorry, I have changed the mistakes. I couldn´t find Code tag, that is the reason why I put it into de Quote tag.

I think the OP means a "4 pin" ultrasonic sensor.
The data sheet should explain what the pins do, so post a link.

That sensor uses one pin to sens a pulse, and the echo comes back to trigger the other pin. There is code on the playground to work with that sensor.

Solved,

Thanks.