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);
}
}
}
}