Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! ✅Check out the new docs.

Unable to plot a third trace for some reason. Please Help

Hello,

I have a small project running on my Arduino Yun (collect data for temp, humidity, light and motion detection) streaming data to plotly using this guide (https://github.com/plotly/arduino-api/tree/master/plotly_yun). But for what ever reason I’m unable to get the third plot(light) to show on the graph. The first two traces( temp and humidity) work every time but the third trace is very erratic, it sometimes starts and just stops plotting or doesn’t start at all. I can’t seem to figure out the problem . Has anyone else faced this?

This is the code I run using my Arduino IDE:

#include <PlotlyYun.h>
#include <YunMessenger.h>
#include <Bridge.h>
#include <Console.h>
#include “DHT.h”

#define DHTPIN 4

#define DHTTYPE DHT22
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the analog resistor divider
DHT dht(DHTPIN, DHTTYPE);
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int speakerPin = 12;
plotly plotter(“token1”);
plotly plotter1(“token2”);
plotly plotter2(“token3”);

void setup(void) {
// We’ll send debugging information via the Serial monitor
pinMode(inputPin, INPUT); // declare sensor as input
Bridge.begin();
delay(2000);
while(!Console){
;
}
Console.buffer(64);
delay(2000);
}
void loop() {
attachInterrupt(digitalPinToInterrupt(inputPin), motion, CHANGE);
float h = dht.readHumidity();
float t= dht.readTemperature();
photocellReading = analogRead(photocellPin);
Serial.print(photocellReading); // the raw analog reading
Serial.print(",");
Serial.print(h);
Serial.print(",");
Serial.print(t);
Serial.println();
plotter.plot(h);
plotter1.plot(t);
plotter2.plot(photocellReading);
delay(10000);
}

void motion()
{
val = digitalRead(inputPin); // read input value

if (val == HIGH) { // check if the input is HIGH
if (pirState == LOW) {
// we have just turned on
// Serial.println(millis());
Serial.println(“Motion detected!”);
tone(speakerPin,800,1500);
}
// We only want to print on the output change, not state
pirState = HIGH;
}
else {
// digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
{
tone(speakerPin,200,1500);
}
// We only want to print on the output change, not state
pirState = LOW;
}
}
}

Please let me know if you need anything else to understand my situation completely.

Thank you!