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:
However, if I remove the angle print statement, I get a proper graph for the other 2 as this:
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);
}