When I open my serial plotter to get the graph for my HC-SR04 sensor it doesn't show anything. My plotter looks different too. I have attached images below as well.
Only those numbers on the top-most move with time.(100,200,300) Here's my code:
int trigPin = 12;
int echoPin = 11;
int pingTravelTime;
float pingTravelDistance;
float distToTarget;
int baudRate = 9600;
int dT = 10;
int dT2 = 500 ;
String msg1 = "The distance is equal to ";
String msg2 = "cm";
void setup() {
// put your setup code here, to run once:
Serial.begin(baudRate);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(trigPin, LOW);
delayMicroseconds(dT);
digitalWrite(trigPin, HIGH);
delayMicroseconds(dT);
digitalWrite(trigPin, LOW);
pingTravelTime = pulseIn(echoPin, HIGH);
pingTravelDistance = pingTravelTime * ((765. * 5280. * 12.) / (3600. * 1000000));
pingTravelDistance = 2.54 * pingTravelDistance;
distToTarget = (pingTravelDistance / 2);
Serial.println(msg1 + distToTarget + msg2);
delay(dT2);
}
What do I do??
-
Does the serial monitor connect without issue with this code?Zhelyazko Grudov– Zhelyazko Grudov2021年04月13日 08:12:51 +00:00Commented Apr 13, 2021 at 8:12
-
Yes, the serial monitor behaves properly and poses no problem for me. It's just the serial plotter that seems to have a problem.akshay.gjha– akshay.gjha2021年04月14日 05:48:37 +00:00Commented Apr 14, 2021 at 5:48
1 Answer 1
The serial plotter expects you to send numbers, and only numbers. If it reads any other text, like for example
"The distance is equal to 9.88cm"
It assumes these are the names of the columns of data that are to follow. So it chooses one color for each column and prints the color key on top of the graph.
What do I do??
Just remove the prose and print only the numbers. You may print
something like "distance(cm)" in setup()
if you want to have the key
displayed, but that is not required.
-
@unibeam Then mark this answer as correct.Python Schlange– Python Schlange2021年04月14日 10:18:40 +00:00Commented Apr 14, 2021 at 10:18