I am working on a project in which the user inputs characters into the Serial port which get translated into integers and sent to the Arduino for controlling two servos.
I have researched how to translate these characters into integers for the servos, and the code seems to work for a single servo. However, when I tried to incorporate a second servo with an if statement, the code works once for one of the servos and thereafter fails for the second one.
I have thoroughly checked my circuitry, and it seems that the problem resides in the program.
#include<Servo.h> // Servo library
servo2.attach(8); // attach motors to the pins
int numCollect() // function for char to int conversion in Serial port
int numInput= 0;
while(Serial.available() > 0)
numInput *= 10;
numInput += (Serial.read() - ‘0’);
if(Serial.available() > 0) // checks if there is data
if(Serial.read() == ‘D’) // condition for switching from the first servo to the second
delay(100); // wait for the motor to get there
Your help is very much appreciated