IS THAT ABLE TO DIGITAL READ A I2C BUS SENSOR

jremington:
Then, rather than reading a "digital pin", you will read values from the VL6180X sensor, using the I2C bus and the Wire library.

Send a Telegram message when the proper value is received.

But first, write a program that just receives values from the VL6180X sensor, and get it working properly, before adding anything else.

jremington:
Then, rather than reading a "digital pin", you will read values from the VL6180X sensor, using the I2C bus and the Wire library.

Send a Telegram message when the proper value is received.

But first, write a program that just receives values from the VL6180X sensor, and get it working properly, before adding anything else.

sorry i tried not using reading a digital pin , i'm using the reading values from the VL6180X sensor at first it work well it shown the range and the telegram message send , but the message wont send successfully it will stuck there .

<Range: 8
Checking Full Condition again
Range: 6
sent notifcation1 to Telegram>
like this ,it will not send successfully

If you want help, why did you not post your latest code, using code tags?

jremington:
If you want help, why did you not post your latest code, using code tags?

//Including the two libraries
#include <UniversalTelegramBot.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <VL6180X.h>
#include <Wire.h>
VL6180X sensor;
long Bot_lasttime;
int bulk_messages_mtbs = 36000; // testing to delay 6sec to detecting another distance and which message been sent .
int Range = 0;   //Set  Range to integer
//------- WiFi Settings -------
char ssid[] = "";       // your network SSID (name)
char password[] = "";  // your network key

// ------- Telegram config --------
#define BOT_TOKEN ""  // your Bot Token (Get from Botfather)
#define CHAT_ID "" // Chat ID of where you want the message to go (You can use MyIdBot to get the chat ID)

// SSL client needed for both libraries
WiFiClientSecure client;

UniversalTelegramBot bot(BOT_TOKEN, client);

String ipAddress = "";

volatile bool telegramButton1PressedFlag = false;
volatile bool telegramButton2PressedFlag = false;

void setup() {

Serial.begin(115200);
Wire.begin();
sensor.init();
sensor.configureDefault();
// Reduce range max convergence time and ALS integration
// time to 30 ms and 50 ms, respectively, to allow 10 Hz
// operation (as suggested by Table 6 ("Interleaved mode
// limits (10 Hz operation)") in the datasheet).
sensor.writeReg(VL6180X::SYSRANGE__MAX_CONVERGENCE_TIME, 30);
sensor.writeReg16Bit(VL6180X::SYSALS__INTEGRATION_PERIOD, 50);

sensor.setTimeout(500);

// stop continuous mode if already active
sensor.stopContinuous();
// in case stopContinuous() triggered a single-shot
// measurement, wait for it to complete
delay(300);
// start interleaved continuous mode with period of 100 ms
sensor.startInterleavedContinuous(350); 





// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);

// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
    delay(500);
 }
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);

 ipAddress = ip.toString();

}
void telegramButton1Pressed() {
  Serial.print("\tRange: ");
  Serial.println(sensor.readRangeContinuousMillimeters());
  if (sensor.readRangeContinuousMillimeters()<15) {
  {
      telegramButton1PressedFlag = true;
  }
  return;
}

void sendTelegramMessage1() {
  String message1 = "FULL!";                   //FULL
  if(bot.sendMessage(CHAT_ID, message1, "Markdown")){
    Serial.println("TELEGRAM Message 1 Successfully sent");
  }
  telegramButton1PressedFlag = false;
}

void telegramButton2Pressed() {
  Serial.print("\tRange: ");
  Serial.println(sensor.readRangeContinuousMillimeters());
  if(sensor.readRangeContinuousMillimeters()>80) {
  {
      telegramButton2PressedFlag = true;
  }
  return;
}
}
void sendTelegramMessage2(){
  String message2 = "EMPTY!";               //Empty
  if(bot.sendMessage(CHAT_ID, message2, "Markdown2")){
    Serial.println("TELEGRAM Message 2 Successfully sent");
  }
    telegramButton2PressedFlag = false;
}
void loop() {
  Serial.print("\tRange: ");
  Serial.println(sensor.readRangeContinuousMillimeters());
  static bool Range_reach = false;
  if(sensor.readRangeContinuousMillimeters()>80) {
       delay(1000);
       Serial.println("Checking Empited Condition again");
       delay(10000);       //delay 10 second for checking propose.
       if(!Range_reach)
{
          
            Serial.print("\tRange: ");
            Serial.println(sensor.readRangeContinuousMillimeters());
            if(sensor.readRangeContinuousMillimeters()>80){
                Serial.println("sent notifcation1 to Telegram");
                sendTelegramMessage2();
                delay(bulk_messages_mtbs);
                Bot_lasttime = 0;
                if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
                Range_reach = true;            
           
                Serial.println();
}   
}
}

  else if (sensor.readRangeContinuousMillimeters()<15) {
                 delay(1000);
                 Serial.println("Checking Full Condition again");
                 delay(5000);     //delay 3 minutes for checking propose.
          if(Range_reach) {
      
                   Serial.print("\tRange: ");
                   Serial.println(sensor.readRangeContinuousMillimeters());
                   if(sensor.readRangeContinuousMillimeters()<15){
                       Serial.println("sent notifcation2 to Telegram");
                       sendTelegramMessage1();
                       delay(bulk_messages_mtbs);
                       Bot_lasttime = 0;
                       if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
                       Serial.println();
          Range_reach = false;


}
}
}
}

after that it will shown sending which message but it did not successfully sending to the chat group .

What you seem to be saying is that this bit of code executed properly

void sendTelegramMessage2(){
  String message2 = "EMPTY!";               //Empty
  if(bot.sendMessage(CHAT_ID, message2, "Markdown2")){
    Serial.println("TELEGRAM Message 2 Successfully sent");
  }
    telegramButton2PressedFlag = false;
}

and printed "TELEGRAM Message 2...", but nothing was received on the other end.

If so, that may not be a problem with the sending program.

Write a little program that just sends and receives those messages, and verify correct operation before adding all the other stuff.

By the way, use of Strings in Arduino causes memory problems and program crashes. We don't recommend them.

jremington:
What you seem to be saying is that this bit of code executed properly

void sendTelegramMessage2(){

String message2 = "EMPTY!";              //Empty
  if(bot.sendMessage(CHAT_ID, message2, "Markdown2")){
    Serial.println("TELEGRAM Message 2 Successfully sent");
  }
    telegramButton2PressedFlag = false;
}



and printed "TELEGRAM Message 2...", but nothing was received on the other end.

If so, that may not be a problem with the sending program.

Write a little program that just sends and receives those messages, and verify correct operation before adding all the other stuff.

By the way, use of Strings in Arduino causes memory problems and program crashes. We don't recommend them.

yeah i testing using ultrasonic its working now i'm testing VL6180X.

The code is a mess.

For example, this does nothing useful, and the variable telegramButton2PressedFlag is never tested or used for anything:

 if(sensor.readRangeContinuousMillimeters()>80) {
  {
      telegramButton2PressedFlag = true;
  }

jremington:
The code is a mess.

For example, this does nothing useful, and the variable telegramButton2PressedFlag is never tested or used for anything:

 if(sensor.readRangeContinuousMillimeters()>80) {

{
      telegramButton2PressedFlag = true;
  }

yeah thank you. i have cleaning up my code . now its work thanks for your help.