Can everybody help me with a code for:
a robot that has to drive around an object.
I have:
6 Ultrason HC-SR04 sensors
2 Motors on an adafruit motorshield.
I am coding for 2 weeks and I haven't a result ;(
Can everybody help me with a code for:
a robot that has to drive around an object.
I have:
6 Ultrason HC-SR04 sensors
2 Motors on an adafruit motorshield.
I am coding for 2 weeks and I haven't a result ;(
When is the deadline for our assignment?
Post your best effort, and tell us what it does and doesn't do.
the deadline is 11 november.
the sensors print in the serial monitor but the motors don't rotate...
if I remove the code for the sensors the motors rotate
#include <AFMotor.h>
// 100% Gideon Dijkhuis :<)
AF_DCMotor motorlinks(3);
AF_DCMotor motorrechts(2);
const int Voortrig = 13;
const int Voorecho = 6;
const int Rechtstrig1 = 2;
const int Rechtsecho1 = 6;
const int Achtertrig = 3;
const int Achterecho = 7;
const int Linkstrig = 1;
const int Linksecho = 5;
const int Rechtstrig2 = 11;
const int Rechtsecho2 = 9;
const int Linkstrig2 = 10;
const int Linksecho2 = 8;
int Rechtsduration1;
int Rechtsdistance1;
int Rechtsduration2;
int Rechtsdistance2;
int Voorduration;
int Voordistance;
int i;
int Distance;
void setup()
{
motorlinks.setSpeed(150);
motorlinks.run(RELEASE);
motorrechts.setSpeed(150);
motorrechts.run(RELEASE);
pinMode(Rechtstrig1, OUTPUT);
pinMode(Rechtsecho1, INPUT);
pinMode(Rechtstrig2, OUTPUT);
pinMode(Rechtsecho2, INPUT);
pinMode(Voortrig, OUTPUT);
pinMode(Voorecho, INPUT);
}
void loop() {
motorlinks.setSpeed(150);
motorlinks.run(FORWARD);
motorrechts.setSpeed(150);
motorrechts.run(FORWARD);
}
void Sensor() {
digitalWrite(Rechtstrig1, LOW);
delayMicroseconds(2);
digitalWrite(Rechtstrig1, HIGH);
delayMicroseconds(10);
digitalWrite(Rechtstrig1, LOW);
Rechtsduration1 = pulseIn(Rechtsecho1, HIGH);
Rechtsdistance1 = (Rechtsduration1 * 3.43) / 2;
Rechtsdistance1 = Rechtsdistance1 + 95;
digitalWrite(Rechtstrig2, LOW);
delayMicroseconds(2);
digitalWrite(Rechtstrig2, HIGH);
delayMicroseconds(10);
digitalWrite(Rechtstrig2, LOW);
Rechtsduration2 = pulseIn(Rechtsecho2, HIGH);
Rechtsdistance2 = (Rechtsduration2 * 3.43) / 2;
digitalWrite(Voortrig, LOW);
delayMicroseconds(2);
digitalWrite(Voortrig, HIGH);
delayMicroseconds(10);
digitalWrite(Voortrig, LOW);
Voorduration = pulseIn(Voorecho, HIGH);
Voordistance = (Voorduration * 0.0343) / 2;
}
//This won't work...
AF_DCMotor motorlinks(3);
AF_DCMotor motorrechts(2);
const int Voorecho = 6;
const int Rechtstrig1 = 2;
const int Rechtsecho1 = 6;
const int Achtertrig = 3;
A few repeats there.
#include <NewPing.h> // Library voor de Ultrasoon sensor
#define TRIGGER_PIN 13 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 4 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance in cm. Maximum distance is 400-500 cm.
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
int afstand = 0;
const int Measure_Period = 500; // Update measurement every 500 msec.
unsigned long time_to_Measure = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
Ultrasoon_Meting();
}
void Ultrasoon_Meting() {
if ((millis() - time_to_Measure) > Measure_Period) {
afstand = sonar.ping() / 58; // Send ping, get ping time, convert microseconds to cm.
time_to_Measure = millis();
Serial.println(afstand);
}
}
I've this code for the ultrason sensor, but it works for the first one, but then it works not....
const int Voorecho = 4;
it works the first one...
could it also be something with the Arduino, because i've 2 arduino's and if i switch to the 3th, it works for the first one