Arduino Mega writes to servo despite no write command

I'm working on a robotic dog project and the servo TFR goes to the angle 93 despite no angle ever being written to the TFR servo. In addition the TWBRR servo would go to the same position as the TWFR servo despite no write command to the TWBRR servo (That's why it's commented out). Any Ideas?

#include <Servo.h>

float x;
float anga;
float angarad;
float angb;
float angbrad;
float angl;

Servo TFL;
Servo BFL;
Servo TWFL;
Servo TFR;
Servo BFR;
Servo TWFR;
Servo TBL;
Servo BBL;
Servo TWBL;
Servo TBR;
Servo BBR;
Servo TWBRR;

void setup() {
  // put your setup code here, to run once:
TFL.attach(48);
BFL.attach(46);
TWFL.attach(51);
TFR.attach(50);
BFR.attach(52);
TWFR.attach(53);
TBL.attach(44);
BBL.attach(47);
TWBL.attach(49);
TBR.attach(43);
BBR.attach(42);
//TWBRR.attach(45);
Serial.begin(9600);
Serial.println("Begin");
//TFR.write(15);
BFR.write(90);
TWFR.write(95);
x = 150;
delay(1000);
}

void loop() {
delay(100);
angarad = acos(x/180);
anga = ((angarad * 180) / 3.14159);
angbrad = 90 - acos(x/194);
angb = ((angbrad * 180) / 3.14159);
//BFR rotates CCW with increasing values.
//TFR rotates CCW with increasing values.
BFR.write(90-anga);
angl = TFR.read();
Serial.println(angl);
delay(100);
}

Welcome to the forum

Your topic was MOVED to its current forum category which is more appropriate than the original

When you attach() a servo it moves to the default angle of 90 degrees. If you want it to move to a different initial angle then write() that angle to it before attaching it

This servo never was attached.

Is that the mid position, initial position for each attached servo?

Check this. Explain it to me real slow, like I never took trigonometry and don't know how those functions work.

a7

That's probably it. I didn't realize it set an initial position without a write command, Thanks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.