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 Heightvoid 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++.