using <UniversalTelegramBot.h>how to sent different message when distance change

eg:

void telegramButton1Pressed() {
Serial.println(“Telegram Button-1 Pressed”);
int echo = digitalRead(ECHOPIN );
if(dist <10 && SendingMessage)
{
telegramButton1PressedFlag = true;
return;
}

void sendTelegramMessage1() {
String message = “Dustbin is full,needed to clean up!”;
if(bot.sendMessage(CHAT_ID, message, “Markdown”)){
Serial.println(“TELEGRAM Message 1 Successfully sent”);
}
telegramButton1PressedFlag = false;
}

void telegramButton2Pressed() {
Serial.println(“Telegram Button-2 Pressed”);
int echo = digitalRead(ECHOPIN );
if(dist >10 )
{
telegramButton2PressedFlag = true;
}
return;
}

void sendTelegramMessage2() {
String message2 = “Dustbin is been clean up!”;
if(bot.sendMessage(CHAT_ID, message2, “Markdown”)){
Serial.println(“TELEGRAM Message 2 Successfully sent”);
}
telegramButton2PressedFlag = false;
}

it will only appearing first message when it detected the distance <10 it will not shown the message 2 when distance appeared >10

Post code that actually compiles. Use code tags when you do. Post code that is complete and exhibits the problem. If you have compiler errors then post them as well.

Your code as posted has functions defined inside functions and other errors. Please post actual code that will compile.

void telegramButton2Pressed() {
Serial.println("Telegram Button-2 Pressed");
int echo = digitalRead(ECHOPIN );
if(dist >10 )
{
telegramButton2PressedFlag = true;
}
return;
}

I wonder what the use of echo is since it goes out of scope before it is ever used. Is it shadowing some global variable? That's why we want to see complete code.

Delta_G:
Use code tags when you do.

#include <UniversalTelegramBot.h>
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <SoftwareSerial.h> // Software Serial library
#include “NewPing.h”

#define ECHOPIN D2// Pin to receive echo pulse
#define TRIGPIN D1// Pin to send trigger pulse
#define MAX_DISTANCE 400 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
boolean SendingMessage = true;
boolean SendingMessage2 = true;
NewPing sonar(TRIGPIN, ECHOPIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
long duration; // declare duration as long. Long can store a bigger number than int.
int dist = 0; // declare dist as 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(9600);
pinMode(TRIGPIN, OUTPUT); // Sets the trigPin as an Output
pinMode(ECHOPIN, INPUT);// Sets the echoPin as an Input
digitalWrite(ECHOPIN, HIGH);

// 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.println(“Telegram Button-1 Pressed”);
int echo = digitalRead(ECHOPIN );
if(dist <10 && SendingMessage)
{
telegramButton1PressedFlag = true;
SendingMessage = false;
telegramButton2PressedFlag = true;
}if (dist >10 && SendingMessage2)
SendingMessage2 = true;
return;
}

void sendTelegramMessage1() {
String message = “Dustbin is full,needed to clean up!”;
if(bot.sendMessage(CHAT_ID, message, “Markdown”)){
Serial.println(“TELEGRAM Message 1 Successfully sent”);
}
telegramButton1PressedFlag = false;
}

void telegramButton2Pressed() {
Serial.println(“Telegram Button-2 Pressed”);
int echo = digitalRead(ECHOPIN );
if(dist >10 && SendingMessage2)
{
telegramButton2PressedFlag = true;
SendingMessage2 = false;
}
return;
}

void sendTelegramMessage2() {
String message2 = “Dustbin is been clean up!”;
if(bot.sendMessage(CHAT_ID, message2, “Markdown”)){
Serial.println(“TELEGRAM Message 2 Successfully sent”);
}
telegramButton2PressedFlag = false;
}

void loop() {
dist = sonar.ping_cm();
Serial.print(dist);
Serial.println(" cm");
delay(100);

if (dist <10 && SendingMessage) {
Serial.println(“sent notifcation1 to Telegram”);
sendTelegramMessage1();
SendingMessage = false;

if(dist >10 && SendingMessage2){
Serial.println(“sent notifcation2 to Telegram”);
sendTelegramMessage2();
SendingMessage2 = false;

}
}
}

I don't see where SendingMessage or SendingMessage2 can ever get set to true.

I see this:

if (dist >10 && SendingMessage2) 
       SendingMessage2 = true;

But it would have to already be true to get there anyway, so that can't be it.

And it shouldn't print any messages unless one of those is true.

int echo = digitalRead(ECHOPIN );

You know you don't use digitalRead on an ultrasonic sensor right?

please format your code AND USE CODE TAGS if you post anything further.

If you ignore this request then you will not get anymore replies.

If you don't know what I mean by code tags, then read the "How to use this forum" thread which you should have read before you got started.

Delta_G:

Delta_G:
Use code tags when you do.

What?

Delta_G:
please format your code AND USE CODE TAGS if you post anything further.

If you ignore this request then you will not get anymore replies.

If you don't know what I mean by code tags, then read the "How to use this forum" thread which you should have read before you got started.

@Mrtian2, this is actually quite important. Code gets mangles when you post it the way you did. Follow the link in the above quote abd read the stuff there.

``sorry beginner to coding .I though ultrasonic is a digital Pin because i need to reading the value of distance so that the message will been post .

Mrtian2:
``sorry beginner to coding .I though ultrasonic is a digital Pin because i need to reading the value of distance so that the message will been post .

Have you read anything about how to use an ultrasonic sensor with an Arduino? Seems to me like reading a few tutorials would be a lot better way to learn than just guessing at it and wondering why it doesn't work.

ChrisTenone:
What?

There was more code posted that got removed after I posted. It made sense when I posted it.

Delta_G:
There was more code posted that got removed after I posted. It made sense when I posted it.

My "What?" was rhetorical. OP still hasn't posted in code tags (although it looks as if an attempt has been made), and has not used Autoformat in the IDE. I wonder if the spate of poorly formatted code is due to Arduino's newfangled online editor lacking that capability. Couple this with the 5 minute posting rule for newbs, and we get slow to react, and frustrated newbs.

Both those problems could be addressed by an active administration, a lot of communication issues here could be alleviated.

Its works only that when it change to distance more than 10 it will not post second message .

Have you addressed the issue I brought up in #5?

On a phone right now so I can't see the code you attached.

Since you are ignoring my request to post the code formatted in tags I'm going to ignore your post now. Best of luck.