Hi,
I'm trying to use 2 servo motors (Tower Pro SG-5010) in a pan and tilt kit using the Arduino Uno with the motor driver shield L293D. Below is the code I'm currently using that I retrieved off a similar project with the servo motors connected to pins 9 & 10 on the L293D:
( Charles' Labs - 3D Lidar Scanner )
But, when using the below code only the yaw servo motor seems to be moving 180° in a continuous loop. I've checked both pins (9 & 10) with the example servo sweep code and they to work with no issue individually.
The goal is two be able to yaw sweep 180° and back to 0° then move up 1° in pitch - to a maximum of 45° pitch angle. This would enable me to attach a LiDAR scanner later on and scan a small slope.
Any help would be greatly appreciated!
#include <Servo.h>
#include <Wire.h>
//Delay between each sample to avoid mechanical wobble
#define DELAY_BETWEEN_SAMPLES 100
//Size of the steps of YAW/PITCH in degrees (1 = full res)
#define YAW_STEP 1
#define PITCH_STEP 1
#define MATH_PI 3.1415f
//Variables
Servo servoYaw,servoPitch;
char s[15];
int yawAngle,pitchAngle;
void setup() {
// Initialize serial connection to display distance readings
Serial.begin(115200);
//Servo init
servoYaw.attach(10);
servoPitch.attach(9);
}
void loop() {
delay(5000);
//Sweep Yaw servomotor
for (yawAngle = 0; yawAngle <= 180; yawAngle += YAW_STEP) {
servoYaw.write(yawAngle);
//Sweep Pitch servomotor. The direction depends on the current directory
if(pitchAngle < 90){
for (pitchAngle = 0; pitchAngle <= 180;pitchAngle+= PITCH_STEP){
servoPitch.write(pitchAngle);
}
}
}
}
