Here is an AutoCAD Project of the rover you can use.
Not 100% accurate, but very close.
[ATTACH]598[/ATTACH]
rover_V2_PCB.zip (1.64 MB)
Here is an AutoCAD Project of the rover you can use.
Not 100% accurate, but very close.
Two main ways: 1) stick the servo to the solder prototyping area using double-sided adhesive tape 2) Use the expansion plate.
Are you trying to get the physical model working or a 3D simulation?
Nicely done! Complete with headers & all. Do you have it up and running?
Glad we can help! Did you get robot to move and stop like you want it to?
Hi Joseph,
Can you try adding the following lines to the end of your main() function?
Serial.print("Distance: ");
Serial.println(cm);
After you upload this to your robot, you will be able to see the cm values output to the Serial Monitor (ensure you have it open at 9600 kpbs). If you can provide us with the output, we way be able to see what’s going on.
Here are a few recommendations:
1- Change your delayMicroseconds from 5ms to 10ms between your output high and output low. This is the value recommended for the sensor.
2- Change your “microseconds” argument to your microsecondsToCentimeters function from type “long” to type “unsigned long”, to match the data type of your “duration” variable.
3- You can also move your entire microsecondsToCentimeters function below the outside of the main() function since this is a common practice.
4- You might also want to change the data type of your “cm” variable to be “long” instead of “int” for it to match the type returned by your microsecondsToCentimeters function. Alternatively, you can change your return type to “int” to match your variable.
We hope this helps,
Yes I did. I also added a sweep for the servo and a left turn.
Great advice. Thanks. Here is my new code for go, stop, and turn.
[code]const int E1 = 6; //M1 Speed Control
const int E2 = 5; //M2 Speed Control
const int M1 = 8; //M1 Direction Control
const int M2 = 7; //M2 Direction Control
const int pingPin = 10;
int leftspeed = 255;
int rightspeed = 255;
void setup() {
Serial.begin(9600);
}
void loop()
{
long duration, inches, cm;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print(“cm”);
Serial.println();
delay(100);
if (cm > 20) {
analogWrite(E1,255);
digitalWrite(M1,LOW);
analogWrite(E2,255);
digitalWrite(M2,LOW);
delay(100);
} else {
analogWrite (E1,0);
digitalWrite(M1,LOW);
analogWrite (E2,0);
digitalWrite(M2,LOW);
delay(1000);
analogWrite(E1,255);
digitalWrite(M1,HIGH);
analogWrite(E2,255);
digitalWrite(M2,HIGH);
delay(1000);
analogWrite(E1,255);
digitalWrite(M1,HIGH);
analogWrite(E2,255);
digitalWrite(M2,LOW);
delay(550);
}
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}[/code]
Not running yet. Still working on code. Trying to assign code blocks to 3D algorithm in CAD file, but having little luck with the structure. I may need a different approach. Any ideas?
A Physical model. I can get it to move and I can get the ping code to work, but I can’t figure out how to make it stop with the ping sensor.
I’m trying to get my rover to go forward and stop when the ping sensor reads 10cm. Here is my code. What am I missing?
[code]const int E1 = 6; //M1 Speed Control
const int E2 = 5; //M2 Speed Control
const int M1 = 8; //M1 Direction Control
const int M2 = 7; //M2 Direction Control
const int pingPin = 10;
int leftspeed = 255;
int rightspeed = 255;
unsigned long distance;
int cm;
int duration;
void setup() {
Serial.begin(9600);
}
void loop () {
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
cm = microsecondsToCentimeters(duration);
Serial.print(cm);
Serial.println();
delay(100);
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
if (cm < 10) {
analogWrite(E1,0);
digitalWrite(M1,LOW);
analogWrite(E2,0);
digitalWrite(M2,LOW);
delay(100);
} else {
analogWrite (E1,255);
digitalWrite(M1,LOW);
analogWrite (E2,255);
digitalWrite(M2,LOW);
delay(100);
}
}[/code]