Need help with controlling all components in build using ultrasonic sensor please help asap

I'm very new to Arduino and do not know C++ code too well either. I need help with my code. I need to make a smart water bottle stand for a project using an LCD screen, a buzzer, and an ultrasonic sensor for a project with a close deadline The purpose of the code is to make sure the buzzer and LCD screen display telling you to drink water goes off every 30 minutes but only if the ultrasonic sensor detects something, which in this case, will be the bottle. The LCD and the Buzzer are working so far, but I need to incorporate the 30-minute delay and figure out how to make the sensor work the rest of the component when triggered. I know my code isn't complete, so I need help with it asap. This is my code so far-

// Include the library:
#include <LiquidCrystal.h>
#include<UltraDistSensor.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Create an LCD object. Parameters: (RS, E, D4, D5, D6, D7):

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

float reading;

int stringStart, stringStop = 0;
int scrollCursor = 16;

UltraDistSensor mysensor;

const int buzzer = 8;
const int trig_pin = 9;
const int echo_pin = 10;

int distance_cm;
long duration;

int screenWidth = 16; //Screen Width
int screenHeight = 2; //Screen Height

void setup() {

//set up the LCD's number of columns and rows:
Serial.begin(9600);
mysensor.attach(9,10);//Trigger pin , Echo pin
pinMode(buzzer, OUTPUT);
pinMode(trig_pin, OUTPUT);
pinMode(echo_pin, INPUT);
pinMode(buzzer, OUTPUT);

}

void loop()

{
digitalWrite(buzzer, HIGH);
lcd.setCursor(2, 0);
if (reading < 100)
{
lcd.begin(16, 2);
lcd.display();
lcd.print(" Time To");
lcd.setCursor(2, 1);
lcd.print("Drink Water!");
tone(buzzer, 391);
lcd.display();
delay(690);
lcd.noDisplay();
delay(690);
}
else
{
lcd.noDisplay();
}

}

I think I may need to incorporate the millis or boolean functions to make it work. I also know that I might need an RTC, but accuracy does not matter too much. Please let me know why my code isn't working properly. Simple terms would be greatly appreciated since I am pretty much new to C++.

Help might be available if you told us what that means.
Paul

Could it be something to do with the fact that nothing happens to mysensor?

Strange value.

Please remember to use code tags when posting code

My buzzer and LCD are working, but the sensor won't do anything. What should I add or change from my code for it to work?

Have you thought a little further about why that could be?

// Include the library:
#include <LiquidCrystal.h>
#include<UltraDistSensor.h>
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
// Create an LCD object. Parameters: (RS, E, D4, D5, D6, D7):

const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

float reading;

int stringStart, stringStop = 0;  
int scrollCursor = 16;

UltraDistSensor mysensor;

const int buzzer = 8;
const int trig_pin = 9;
const int echo_pin = 10;

int distance_cm;
long duration;

int screenWidth = 16; //Screen Width
int screenHeight = 2; //Screen Height

void setup() {
  
   //set up the LCD's number of columns and rows:
   Serial.begin(9600);
   mysensor.attach(9,10);//Trigger pin , Echo pin
   pinMode(buzzer, OUTPUT);
   pinMode(trig_pin, OUTPUT);
   pinMode(echo_pin, INPUT);
   pinMode(buzzer, OUTPUT);
  
} 

void loop() 
 
{
    digitalWrite(buzzer, HIGH); 
    lcd.setCursor(2, 0);
    if (reading < 100) 
  {
    lcd.begin(16, 2);
    lcd.display();
    lcd.print("    Time To");
    lcd.setCursor(2, 1);
    lcd.print("Drink Water!");
    tone(buzzer, 391);
    lcd.display();
    delay(690);
    lcd.noDisplay();
    delay(690);
  }
  else
  {
    lcd.noDisplay();
  }

}
 

does that work?

How the Hell do I know?
You're the one with the hardware to test it.

The buzzer, and lcd should reset and start again every 30 minutes like a half hour reminder but this should only happen if the ultrasonic sensor detects something very close to it. So far, the circuit is working without anything remotely near the sensor, and I want to fix that.

I was asking if the code tags were working properly

Did you read the documentation before you wrote the code? I see "attach() This function configure sensor with arduino" in the documentation, but do not see it in your code.
Paul

I don't really get how to make the sensor connect with the arduino in the proper way, but I have wired it correctly. Can you tell me what to change then?

Does this help?

a little but not a lot since I only want the prompt to drint water to show up on the lcd every 30 minutes if the ultrasonic sensor was triggered. The link shows how to incorporate and show how far the object is from the sensor onto the lcd

Isn't how far the object is what you wanted to know so you can begin the timing?
Paul

Hi, @pras33da

Have you written code that JUST uses the ultrasonic to establish you have control of it before adding all the other code?

You need to make sure the ultrasonic is working?

Can you please post a circuit diagram?
Please include power supply and label components and pin names.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Yes exactly thanks for intensifying my knowledge

I though it wasn’t at first but then I incorporated it and now my circuit is working

The sensor is indeed working and I am using a variable power supply that can go up to 9v
The circuit is now working, so thanks anyway

Thanks to everyone for helping out, I found all of your help useful, my circuit is now working. Thanks a lot for the early replies

Hi, @pras33da

Good ,now can you post your code to show the fruits of our efforts and a circuit diagram to help any other people enquiring?

Thanks.. Tom... :grinning_face_with_smiling_eyes: :+1: :coffee: :australia: