I’m using adxl335 to measure coordinates of x,y and z axis when i try to plot x axis individually without y and z axis i get a graph but when i try to plot all the three data doesn’t get uploaded it takes all the three values as 1. I’m uploading the data serially I have attached the screenshots below Arduino code
#include<LiquidCrystal.h> // lcd Header
#include <SoftwareSerial.h>
SoftwareSerial mySerial(8,9);
LiquidCrystal lcd(7,6,5,4,3,2); // pins for LCD Connection
#define buzzer 12 // buzzer pin
#define led 13 //led pin
#define x A0 // x_out pin of Accelerometer
#define y A1 // y_out pin of Accelerometer
#define z A2 // z_out pin of Accelerometer
/*variables*/
int xsample=0;
int ysample=0;
int zsample=0;
long start;
int buz=0;
/*Macros*/
#define samples 50
#define maxVal 20 // max change limit
#define minVal -20 // min change limit
#define buzTime 5000 // buzzer on time
void setup()
{
lcd.begin(16,2); //initializing lcd
Serial.begin(9600);
mySerial.begin(9600); // initializing serial
delay(1000);
lcd.print("EarthQuake ");
lcd.setCursor(0,1);
lcd.print("Detector ");
delay(2000);
lcd.clear();
lcd.print("Calibrating.....");
lcd.setCursor(0,1);
lcd.print("Please wait...");
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
buz=0;
digitalWrite(buzzer, buz);
digitalWrite(led, buz);
for(int i=0;i<samples;i++) // taking samples for calibration
{
xsample+=analogRead(x);
ysample+=analogRead(y);
zsample+=analogRead(z);
}
xsample/=samples; // taking avg for x
ysample/=samples; // taking avg for y
zsample/=samples; // taking avg for z
delay(3000);
lcd.clear();
lcd.print("Calibrated");
delay(1000);
lcd.clear();
lcd.print("Device Ready");
delay(1000);
lcd.clear();
lcd.print(" X Y Z ");
}
String data;
void loop()
{
int value1=analogRead(x); // reading x out
int value2=analogRead(y); //reading y out
int value3=analogRead(z); //reading z out
int x_value =xsample-value1; // finding change in x
int y_value=ysample-value2; // finding change in y
int z_value=zsample-value3; // finding change in z
/*displying change in x,y and z axis values over lcd*/
lcd.setCursor(0,1);
lcd.print(x_value );
lcd.setCursor(6,1);
lcd.print(y_value);
lcd.setCursor(12,1);
lcd.print(z_value);
delay(100);
/* comparing change with predefined limits*/
if(x_value < minVal || x_value > maxVal || y_value < minVal || y_value > maxVal || z_value < minVal || z_value > maxVal)
{
if(buz == 0)
start=millis(); // timer start
buz=1; // buzzer / led flag activated
}
else if(buz == 1) // buzzer flag activated then alerting earthquake
{
lcd.setCursor(0,0);
lcd.print("Earthquake Alert ");
if(millis()>= start+buzTime)
buz=0;
}
else
{
lcd.clear();
lcd.print(" X Y Z ");
}
digitalWrite(buzzer, buz); // buzzer on and off command
digitalWrite(led, buz); // led on and off command
/*sending values to processing for plot over the graph*/
Serial.print("x=");
Serial.println(x_value );
Serial.print("y=");
Serial.println(y_value);
Serial.print("z=");
Serial.println(z_value);
Serial.println(" $");
if (mySerial.available() > 0)
{
delay(1000);
String readData = "";
while (mySerial.available() > 0 ) {
readData = readData + (float)mySerial.read();
}
Serial.println(readData);
{
mySerial.print(x_value);
// mySerial.print(y_value);
// mySerial.print(z_value);
}}
String data;
}
Then edited the pretext to make it print on serial monitor. Open the serial Monitor on Arduino IDE, to view the updated data. Will help you troubleshoot as well.
data count is zero nothing is being pushed and serial monitor doesn’t show any data.
i added Serial.println(x_value ); to check if any data is being measured, and I was getting the value of x.
Below, you can see the data being pushed to the cloud, like it is supposed to. Comment out Serial.print statements to avoid disturbance in the serial communication. You can use your lcd to view the data for updates.
Your 8 and 9 pin of Arduino is connected to Bolt. And 0 and 1 pin of Arduino is open. You should be able to see the serial monitor as well as pushing to the cloud.
Your BoltDeviceCredentials.h file has the Bolt credentials (API key and Device ID) in it.
You can add below script in the program as well. But if you add #include <BoltDeviceCredentials.h> which is supposed to have the credentials in it already, then don’t call below script.
That must be an issue on our side! I will update you by tomorrow EOD with this.
Till then, you can remove time_stamp and directly use
plotChart('xvar', 'yvar', 'zvar');
Or use multiple line graph
var Graph1 = new boltGraph();
Graph1.setChartType("lineGraph");
Graph1.setAxisName('X-Axis Name','Y-axis Name');
Graph1.plotChart('time_stamp','xvar');
var Graph2 = new boltGraph();
Graph2.setChartType("lineGraph");
Graph2.setAxisName('X-Axis Name','Y-axis Name');
Graph2.plotChart('time_stamp','yvar');
var Graph3 = new boltGraph();
Graph3.setChartType("lineGraph");
Graph3.setAxisName('X-Axis Name','Y-axis Name');
Graph3.plotChart('time_stamp','zvar');