I have my whole code written and it worked great, however when i re assembled it on the base of the robot the servo will go to nine and then it acts like its glitching out and goes all the way to the left. This is the code i used, but i feel like it might be a grounding issue. Any help would be super!
#include <Servo.h>
#include <CompactQik2s9v1.h>
#include <NewSoftSerial.h>
Servo myservo;
#define rxPin 3
#define txPin 4
#define rstPin 5
NewSoftSerial mySerial = NewSoftSerial(rxPin, txPin);
CompactQik2s9v1 motor = CompactQik2s9v1(&mySerial,rstPin);
void setup()
{
mySerial.begin(9600);
motor.begin();
motor.stopBothMotors();
myservo.attach(6);
myservo.write(90);
}
void loop()
{
motor.motor1Forward(100);
motor.motor0Forward(100);
delay(2000);
int object = analogRead(0);
if ( object >= 170 )
{
motor.stopBothMotors();
delay(2000);
myservo.write(0);
delay(2000);
int left = analogRead(0);
delay(2000);
myservo.write(180);
delay(2000);
int right = analogRead(0);
if ( left > right )
{
motor.motor1Reverse(100);
motor.motor0Forward(100);
delay(1000);
myservo.write(90);
}
else
{
motor.motor0Reverse(100);
motor.motor1Forward(100);
delay(1000);
myservo.write(90);
}
}
else
{
return;
}
}