Go Down

Topic: Multiple graphs on the serial plotter with LED status (Read 271 times) previous topic - next topic

adusumir

Hey guys, I'm trying to  run an Arduino code that simultaneously:
1) blinks an led on-off every 3 seconds
2) gets a voltage input from an EMG sensor and positions a servo motor accordingly

While I run this program, I'd like to plot the following on the same graph
1) LED status on/off printed as 600 if on and 0 if off
2) EMG value being fed to the arduino
3) The angle the Arduino is sending to the servo motor

I wrote the following code which works to an extent but the problem I'm facing is, I only get two graphs on the plotter instead of 3, I think the EMG value and the angle have combined into a single line as seen in this picture: https://ibb.co/k6yN1Pr . However, if I remove the angle print statement, I get a proper graph for the other 2 as this: https://ibb.co/fFvqNQ9
How do I change my code so I can plot all three separately?
Thanks in advance.


#include <Servo.h>
Servo myservo;
const int ledPin =  LED_BUILTIN;
int ledState = LOW;
unsigned long previousMillis = 0;
const long interval = 3000;
int led=0;
int servovalue=0;
void setup() {
 Serial.begin(9600);
 myservo.attach(9);
 pinMode(ledPin, OUTPUT);
}
void loop() {
 int sensorValue = analogRead(A0);   
int angle = map(sensorValue, 0, 1023, 0, 180);
myservo.write(angle);
Serial.print(sensorValue);
Serial.print(" ")
Serial.println(angle);
delay(15);
 unsigned long currentMillis = millis();
 if (currentMillis - previousMillis >= interval) {
   previousMillis = currentMillis;
   if (ledState == LOW) {
     ledState = HIGH;
     led = 600;
   } else {
     ledState = LOW;
     led = 0;
   }
   digitalWrite(ledPin, ledState);
 }
 Serial.print(" ");
   Serial.println(led);
}


Grumpy_Mike

#2
Sep 28, 2019, 10:36 am Last Edit: Sep 28, 2019, 10:38 am by Grumpy_Mike
Look at https://forum.arduino.cc/index.php?topic=525090.0

To stop the plots overlapping consider adding a constant offset value to two of the readings to separate them.

Go Up