We have implemented a code basically to trigger the range value of VL6180X, when Lux levels reach 2 targeted levels, the 1st level message is getting triggered but the 2nd level trigger is getting skipped, no able to figure out reason, pl do help me in debugging the error(enclosing the code for your reference)
Best,
Ramesha
#include <SoftwareSerial.h>
SoftwareSerial GPRS(10, 11);// RX, TX #include <Wire.h> #include "Adafruit_VL6180X.h"
Adafruit_VL6180X vl = Adafruit_VL6180X();
int error = 0, i = 0, sample = 10, k = 0, l = 0, j = 0, start = 0, sms = 0, sms1 = 0;
int value = 0, reference = 71; //71-change 66,60,64//74
//22-08-18
int lux;
String a = "Message1 ";
String e = "Message2 ";
String b = "Message3 ";
String c = "Message4 ";
String d = " Message5 ";
String f = "lux:";
String contact[7] {
"8123745416",
};
void setup()
{
GPRS.begin(115200);
Serial.begin(115200);
GPRS.println("AT");//AT commands
delay( 2500);
GPRS.println("AT+CMGF=1");//AT for messages mode
delay( 2500);
if (! vl.begin()) {
Serial.println("sensor not found");
errorsms(1);
};
// value = sensorCheck();
Serial.print("Reference- value = ");
Serial.println(value);
delay(600000);//10-minutes delay
start = 0;
sms = 1, sms1 = 1;
}
void loop()
{
i = 0, k = 0, l = 0, j = 0;
value = sensorCheck();
Serial.print("continous- value = ");
Serial.println(value);
if ((lux >= 1001 && lux <= 1450)) {
Serial.print("Thickness Range");
start = 1;
}
if ((lux >= 750 && lux <= 1000))
{ Serial.print("System health OK");
start = 2;
}
if (start == 1)
{ if (sms1 == 1)
{
Serial.print("smsreference==== ");
Serial.println(value);
SMS (value);
start = 0;
sms1++;
}
}
if (start == 2)
{
if (sms == 1)
{
Serial.print("SMS System ==== ");
Serial.println(value);
SMS (value);
start = 0;
sms++;
}
}
}
int sensorCheck()
{
Serial.print("checking ");
// Serial.println(value);
float range = 0;
uint8_t status;
while (i < sample) {
lux = vl.readLux(VL6180X_ALS_GAIN_1);
range = vl.readRange();
status = vl.readRangeStatus();
// range = range * 0.9;
// Serial.print("status");Serial.println(status);
if (status == VL6180X_ERROR_NONE) {
// Serial.print("Range: "); Serial.println(range);
}
// Some error occurred, print it out!
if ((status >= VL6180X_ERROR_SYSERR_1) && (status <= VL6180X_ERROR_SYSERR_5)) {
Serial.println("System error");
errorsms(2);
}
else if (status == VL6180X_ERROR_ECEFAIL) {
Serial.println("ECE failure");
errorsms(3);
}
else if (status == VL6180X_ERROR_NOCONVERGE) {
Serial.println("No convergence");
errorsms(4);
}
else if (status == VL6180X_ERROR_RANGEIGNORE) {
Serial.println("Ignoring range");
errorsms(5);
}
else if (status == VL6180X_ERROR_SNR) {
Serial.println("Ambient conditions too high ");
errorsms(6);
}
else if (status == VL6180X_ERROR_RAWUFLOW) {
Serial.println("Raw reading underflow");
errorsms(7);
}
else if (status == VL6180X_ERROR_RAWOFLOW) {
Serial.println("Raw reading overflow");
errorsms(8);
}
else if (status == VL6180X_ERROR_RANGEUFLOW) {
Serial.println("Range reading underflow");
errorsms(9);
}
else if (status == VL6180X_ERROR_RANGEOFLOW) {
Serial.println("Range reading overflow");
errorsms(10);
}
// delay(100);
k = k + range;
i++;
}
l = k / sample;
Serial.println(l);
j = reference - l;
Serial.print("Lux: "); Serial.println(lux);
return j;
}
void SMS(int Thickness) {
int mem = 0;
Serial.flush();
GPRS.flush();
delay(2000);
Serial.print("Thickness=");
Serial.println(Thickness);
if ( Thickness >= 0 && Thickness < 10) mem = 7;
else if ( Thickness >= 10 && Thickness < 20) mem = 7;
else if ( Thickness >= 20 && Thickness < 30) mem = 7;
else if ( Thickness >= 30) mem = 7;
else mem = 7;
// if ( Thickness >= 11 && Thickness < sample)Thickness =Thickness - 10;
for (int i = 0; i < mem; i++) {
Serial.println(i);
GPRS.println("AT+CMGF=1\r");
delay(1000);
Serial.println(contact*);*
_ Serial.println("AT+CMGS="+91" + contact + ""\r");_ _ GPRS.println("AT+CMGS="+91" + contact + ""\r");
* delay(1000); if (Thickness >= 0 && Thickness <= 9) { GPRS.println(a); Serial.println(a); GPRS.print(Thickness);// The SMS value*
* Serial.println(Thickness); GPRS.println(b); Serial.println(b); GPRS.print(f); Serial.print(f); GPRS.println(lux); Serial.println(lux); } else if (Thickness >= 10 && Thickness < 20) { GPRS.println(a); Serial.println(a); GPRS.print(Thickness);// The SMS value*
* Serial.println(Thickness); GPRS.println(b); Serial.println(b); GPRS.print(f); Serial.print(f); GPRS.println(lux); Serial.println(lux); } else if ( Thickness >= 20 && Thickness < 30) { GPRS.println(a); Serial.println(a); GPRS.print(Thickness);// The SMS value*
* Serial.println(Thickness); GPRS.println(b); Serial.println(b); GPRS.println(c); Serial.println(c); } else if (Thickness >= 30) { GPRS.println(a); Serial.println(a); GPRS.print(Thickness);// The SMS value*
* Serial.println(Thickness); GPRS.println(b); Serial.println(b); GPRS.println(d); Serial.println(d); GPRS.print(f); Serial.print(f); GPRS.println(lux); Serial.println(lux); } else { GPRS.print(Thickness);// The SMS value*
* Serial.println(Thickness); GPRS.println(b); Serial.println(b); GPRS.println(e); Serial.println(e); GPRS.print(f); Serial.print(f); GPRS.println(lux); Serial.println(lux); } delay(100); GPRS.write( 0x1a ); // ctrl+Z character*
* GPRS.println((char)26); delay(10000); } } int errorsms(int error) {//error sms String f = "Failed to find sensor"; String g = "System error"; String h = " laser convergence estimate fail"; String m = "No convergence of laser triangulation"; String n = "Ignoring range"; String o = "Ambient light too high"; String p = "Range underflow"; String q = "Range overflow"; for (int i = 0; i < 6; i++) { Serial.println(contact); Serial.println("AT+CMGS="+91" + contact + ""\r"); GPRS.println("AT+CMGS="+91" + contact + ""\r"); delay(1000); if (error == 1) { GPRS.println(f); Serial.println(f); } else if (error == 2) { GPRS.println(g); Serial.println(g); } else if (error == 3) { GPRS.println(h); Serial.println(h); } else if (error == 4) { GPRS.println(m); Serial.println(m); } else if (error == 5) { GPRS.println(n); Serial.println(n); } else if (error == 6) { GPRS.println(o); Serial.println(o); } else if (error == 7 || error == 9) { GPRS.println(p); Serial.println(p); } else if (error == 8 || error == 10) { GPRS.println(q); Serial.println(q); } delay(100); GPRS.write( 0x1a ); // ctrl+Z character* * GPRS.println((char)26); delay(10000); } start = 8; } prg-1.ino (7.01 KB)*_
rockwellramesha:
I don't know, how smiley cropped in! it is (8);
The code is below,do not where the error is
You have just been told why the smiley appeared in the code. You have failed to post your code correctly after being told how to do that. If you cannot follow simple instructions, you will not be able to write code, so maybe you should choose another hobby.
You really do seem to be going to a lot of trouble to make it difficult to help you. By now I have forgotten what the problem was and you have been posting code in your last 4 Replies with no dialogue whatever.
You seem to have plenty of print statements in your program so please post an example of the output when you run the program - especially the output that is relevant to the problem.
Robin2:
You really do seem to be going to a lot of trouble to make it difficult to help you. By now I have forgotten what the problem was and you have been posting code in your last 4 Replies with no dialogue whatever.
You seem to have plenty of print statements in your program so please post an example of the output when you run the program - especially the output that is relevant to the problem.
...R
Thanks All -
I, did figure out, there is no issue with the code.