system
February 7, 2013, 8:17am
1
Hi
I'm making a linefollower/robot.
I'm using 2 parallex continouos servo's, 5 line tracking sensors that's detect a black line. A "HC-SR04 Ultrasonic Sensor" for detecting when something is on the route.
I have a big problem with my detecting.
When I testing my linefollower/robot with the servo's and linetracking sensors attached then I have a big problem with my HC-SR04 sensor, the sensor don't work properly.
When I disassemble my servo's and my linetracking sensors then the HC-SR04 works properly.
Maybe it's the voltage or the current?
Greatz
system
February 7, 2013, 10:41am
2
bizonpl18:
Hi
I'm making a linefollower/robot.
I'm using 2 parallex continouos servo's, 5 line tracking sensors that's detect a black line. A "HC-SR04 Ultrasonic Sensor" for detecting when something is on the route.
I have a big problem with my detecting.
When I testing my linefollower/robot with the servo's and linetracking sensors attached then I have a big problem with my HC-SR04 sensor, the sensor don't work properly.
When I disassemble my servo's and my linetracking sensors then the HC-SR04 works properly.
Maybe it's the voltage or the current?
Greatz
Could be. How do you have the servos wired? They need their own power supply.
holmes4
February 7, 2013, 11:12am
3
It could be your hardware it could be you code. How can we tell?
Mark
system
February 7, 2013, 12:18pm
4
I have connected my servo's directly on my arduino. here's my code:
/*
Jaar: 2012-2013
*/
#include <Servo.h>
#define trigPin 13
#define echoPin 11 // library van de servos
Servo leftServo; // creert linker servo obje
Servo rightServo; // creert rechter servo object
int s1Left = 2, s2Left = 4, s3Center = 7, s4Right = 8, s5Right = 12; // Initialiseren van sensoren
void setup() {
leftServo.attach(9); // pin 9 op arduino voor linkerservo
rightServo.attach(10); // pin 10 op arduino voor rechterservo
Serial.begin(9600);
pinMode (s1Left,INPUT); // Lezen van de waardes
pinMode (s2Left, INPUT);
pinMode (s3Center, INPUT);
pinMode (s4Right, INPUT);
pinMode (s5Right, INPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
/* Servos stoppen als ALLE sensoren de zwarte lijn detecteren*/
if ((digitalRead(s1Left) == HIGH) && (digitalRead(s2Left) == HIGH) && (digitalRead(s3Center) == HIGH) && (digitalRead(s4Right) == HIGH) && (digitalRead(s5Right) == HIGH)) {
leftServo.write(90);
rightServo.write(90);
Serial.print("*ALLE DETECTIE -> AUTO STOPPEN* ");
}
/* Servos stoppen als de sensoren niks detecteren*/
if ((digitalRead(s1Left) == LOW) && (digitalRead(s2Left) == LOW) && (digitalRead(s3Center) == LOW) && (digitalRead(s4Right) == LOW) && (digitalRead(s5Right) == LOW)) {
leftServo.write(90);
rightServo.write(90);
Serial.print("*GEEN DETECTIE -> AUTO STOPPEN* ");
}
/* auto rijd vooruit als middelste sensor zwarte lijn detecteert */
if ((digitalRead(s1Left) == LOW) && (digitalRead(s2Left) == LOW) && (digitalRead(s3Center) == HIGH) && (digitalRead(s4Right) == LOW) && (digitalRead(s5Right) == LOW)) {
leftServo.write(180);
rightServo.write(0);
Serial.print("*Center DETECTIE -> AUTO RIJD VOORUIT* ");
}
//Auto draait zacht naar links want de buitenste linker sensor detecteert de zwarte lijn
if ((digitalRead(s1Left) == LOW) && (digitalRead(s2Left) == HIGH) && (digitalRead(s3Center) == LOW) && (digitalRead(s4Right) == LOW) && (digitalRead(s5Right) == LOW)) {
leftServo.write(0);
rightServo.write(0);
Serial.print("*[s2Left detecteert] -> AUTO DRAAIT NAAR LINKS* ");
}
//Auto draait zacht naar rechts want de binnenste rechter sensor detecteert de zwarte lijn
if ((digitalRead(s1Left) == LOW) && (digitalRead(s2Left) == LOW) && (digitalRead(s3Center) == LOW) && (digitalRead(s4Right) == HIGH) && (digitalRead(s5Right) == LOW)) {
leftServo.write(180);
rightServo.write(180);
Serial.print("*[s4Right detecteert] -> AUTO DRAAIT NAAR RECHTS* ");
}
/* //Auto draait hard naar rechts want de buitenste rechter sensoren detecteren de zwarte lijn
if ((digitalRead(s1Left) == LOW) && (digitalRead(s2Left) == LOW) && (digitalRead(s3Center) == LOW) && (digitalRead(s4Right) == HIGH) && (digitalRead(s5Right) == HIGH)) {
leftServo.write(180);
rightServo.write(120);
Serial.print("*[s4Right & s5Right detecteert] -> AUTO DRAAIT hard NAAR RECHTS* ");
}*/
//Auto draait hard naar links want de buitenste linkse sensoren detecteren de zwarte lijn
if ((digitalRead(s1Left) == HIGH) && (digitalRead(s2Left) == HIGH) && (digitalRead(s3Center) == LOW) && (digitalRead(s4Right) == LOW) && (digitalRead(s5Right) == LOW)) {
leftServo.write(0);
rightServo.write(0);
Serial.print("*[s1Left & s2Left detecteert] -> AUTO DRAAIT hard NAAR LINKS* ");
}
//Auto draait naar links want de buitenste linkse sensor detecteert de zwarte lijn
if ((digitalRead(s1Left) == HIGH) && (digitalRead(s2Left) == LOW) && (digitalRead(s3Center) == LOW) && (digitalRead(s4Right) == LOW) && (digitalRead(s5Right) == LOW)) {
leftServo.write(0);
rightServo.write(0);
Serial.print("*[s1Left detecteert] -> AUTO DRAAIT NAAR LINKS* ");
}
//Auto draait naar rechts want de buitenste rechtse sensor detecteert de zwarte lijn
if ((digitalRead(s1Left) == LOW) && (digitalRead(s2Left) == LOW) && (digitalRead(s3Center) == LOW) && (digitalRead(s4Right) == LOW) && (digitalRead(s5Right) == HIGH)) {
leftServo.write(180);
rightServo.write(180);
Serial.print("*[s5Right detecteert] -> AUTO DRAAIT NAAR RECHTS");
}
//Auto draait naar rechts want de buitenste rechtse sensor detecteert de zwarte lijn
if ((digitalRead(s1Left) == LOW) && (digitalRead(s2Left) == LOW) && (digitalRead(s3Center) == HIGH) && (digitalRead(s4Right) == HIGH) && (digitalRead(s5Right) == LOW)) {
leftServo.write(180);
rightServo.write(180);
Serial.print("*[s5Right detecteert] -> AUTO DRAAIT NAAR RECHTS");
}
//Auto draait naar links want de buitenste linkse sensor detecteert de zwarte lijn
if ((digitalRead(s1Left) == LOW) && (digitalRead(s2Left) == HIGH) && (digitalRead(s3Center) == HIGH) && (digitalRead(s4Right) == LOW) && (digitalRead(s5Right) == LOW)) {
leftServo.write(0);
rightServo.write(0);
Serial.print("*[s1Left detecteert] -> AUTO DRAAIT NAAR LINKS* ");
}/*
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 20){
leftServo.write(90);
rightServo.write(90);
Serial.println("Auto stoppen");
}
}
system
February 7, 2013, 3:52pm
5
Can you post a wiring diagram? "I have connected my servo's directly on my arduino" sounds rather ominous.
system
February 7, 2013, 3:56pm
6
if ((digitalRead(s1Left) == HIGH) && (digitalRead(s2Left) == HIGH) && (digitalRead(s3Center) == HIGH) && (digitalRead(s4Right) == HIGH) && (digitalRead(s5Right) == HIGH))
This isn't your problem, but why not just read the sensors once at the top of "loop()"?
If the line following code works with out the ping sensor and the ping sensor code works with out the servos then you need an extra power source for the servos.
Mark