I am trying to use the built in serial plotter to graphically see the movement of a servo arm in real time. I am using a the very basic sketch shown below. I don't know where to put the Serial.println command or what other information is needed to visualize the loop that goes from 0 to 90 to 180 in the serial plotter. Any help would be much appreciated. Thank you.
// Include the Servo library #include <Servo.h>
// Declare the Servo pin
int servoPin = 3;
// Create a servo object
Servo Servo1;
void setup() {
// We need to attach the servo to the used pin number
Servo1.attach(servoPin);
}
void loop(){
// Make servo go to 0 degrees
Servo1.write(0);
delay(1000);
// Make servo go to 90 degrees
Servo1.write(90);
delay(1000);
// Make servo go to 180 degrees
Servo1.write(180);
delay(1000);
}
Please edit your post, select all code and click the <CODE/> button; next save your post.
This will apply so-called code tags which makes the code easier to read and copy and the forum software will display it correctly.
You can't actually do that, because there is no way you can read the current position of a servo without some extra hardware. You can only read back the last positional command you sent the Servo.
You need to mechanically connect the servo to a rotary encoder and use the output from the encoder to display the progress of the motor as it turns.
This is a much more complex task and you might question yourself as to what this is going to tel you about things.
Note that using the IDE 2.x will limit the number of plots you can display on the serial plotter to 50. The on the IDE 1.8.19 you get 500 points to plot with.
See this tutorial:-
This image shows the plotting of all four analogue signals, and what happens when one signal (A3) gets disconnected, or as we say "is floating"
Notice how the floating input shows noise input along with a small vestige of the last reading that was made(A2 pot). Due to the charge of the input sample and hold capacitor.