Hi everyone! Please take your time and read through this and give me your solutions for the problems I am facing. I am trying to do a simple school project regarding a sprinkler system but I wanted to improve it by setting a number of times(example 3 times) to play a sound from my speaker to alert anyone nearby to stay clear because the sprinkler is about to turn on. Is it possible to do that because I couldn't find anything on google and if it is possible what is the code I need to put and where? Below is the code for the program:
#include <SoftwareSerial.h>
#include <DFPlayer_Mini_Mp3.h>
SoftwareSerial mySerial(11, 10);
#define relay 2
#define interval 1000
// These constants won't change. They're used to give names to the pins used:
const int smSensor = A2; // Analog input pin that the soil moisture sensor (smSensor) is connected to
int sensorValue = 0; // declare sensorValue to store sensor readings later
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
mySerial.begin (9600);
mp3_set_serial (mySerial);
mp3_set_volume (15);
pinMode(relay, OUTPUT);
}
void loop() {
// read the analog sensor value and store in sensorValue.
sensorValue = analogRead(smSensor);
// print the results to the Serial Monitor:
Serial.print("sensor = ");
Serial.println(sensorValue); // New line after every sensorValue displayed
// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(2);
if (sensorValue < 80)
{
mp3_play (6);
delay (6000);
digitalWrite(relay, HIGH);
delay(interval);
}
else
{
mp3_stop();
digitalWrite(relay, LOW);
delay(interval);
}
}
Thanks for taking the time to read this and sorry if this post was already published before!