Hi
I've done a simple object removing robot car using two continuous servos (FS1503) and using a sensor (HC-SR04). The basic car is fine and worked yesterday - with both USB and then with 9V battery.
Doing trial and error to fine tune the car. But since morning, the car is not working properly with the batter, although it is doing as expected with the USB. Also, I believe the motors are not rotating the way they rotate with USB.
Do I just need to replace the battery? is there a difference in power inputs? Why did the response change?
Code if it helps:
#include <NewPing.h>
#include <Servo.h>
Servo Motora;
Servo Motorb;
const int trigPin = 6;
const int echoPin = 7;
long duration;
unsigned long distance = 0;
int distanceCms;
int maximumRange =100;
int minimumRange= 5;
NewPing sonar(trigPin, echoPin, maximumRange);
void setup() {
// put your setup code here, to run once:
Motora.attach(4);
Motorb.attach(5);
Serial.begin(9600);
}
void go_forward(){
Motora.write(80);
Motorb.write(100);
delay(1000);
}
void go_back(){
Motora.write(100);
Motorb.write(80);
delay(1000);
}
void stop_car(){
Motora.write(91); //right
Motorb.write(89); //left
delay(1000);
}
void turnRight(){
Motora.write(85);
Motorb.write(170);
delay(500);
}
void turnLeft(){
Motora.write(95);
Motorb.write(85);
delay(500);
}
void loop() {
distanceCms=sonar.ping_cm();
Serial.println(distanceCms);
if (distanceCms >0 && distanceCms<15){
stop_car();
Serial.println("Stopping");
go_back();
Serial.println("Go Back");
turnRight();
Serial.println("Turn");
}
else{
go_forward();
Serial.println("Going Forward");
}
delay(50);
}