Created
January 10, 2024 01:35
-
-
Save Ajak58a/34a10f90353cef6cc4b562f009dcfbf6 to your computer and use it in GitHub Desktop.
Fire detection alarm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "SoftwareSerial.h" | |
#include "DFRobotDFPlayerMini.h" | |
// Use pins 2 and 3 to communicate with DFPlayer Mini | |
static const uint8_t PIN_MP3_TX = 26; // Connects to module's RX | |
static const uint8_t PIN_MP3_RX = 27; // Connects to module's TX | |
SoftwareSerial softwareSerial(PIN_MP3_RX, PIN_MP3_TX); | |
// Create the Player object | |
DFRobotDFPlayerMini player; | |
const int Analog1 = 36; | |
int V1 = 0; | |
void setup() | |
{ | |
// Init USB serial port for debugging | |
Serial.begin(9600); | |
// Init serial port for DFPlayer Mini | |
softwareSerial.begin(9600); | |
// Start communication with DFPlayer Mini | |
if (player.begin(softwareSerial)) { | |
Serial.println("OK"); | |
// Set volume to maximum (0 to 30). | |
player.volume(20); | |
} else { | |
Serial.println("Connecting to DFPlayer Mini failed!"); | |
} | |
} | |
void loop(){ | |
v1 = analogRead(Analog1); | |
Serial.println(v1); | |
if (v1 > 1400) | |
{ | |
Serial.println("Please Give Me Water"); | |
player.play(1); | |
delay(1000); | |
} | |
else if ((v1 < 1400) && (v1 > 800)) | |
{ | |
Serial.println("Please Give Me Food"); | |
player.play(2); | |
delay(1000); | |
} | |
else if((v1 < 800) && (v2 > 450)) | |
{ | |
Serial.println("Give Me Medicine"); | |
player.play(3); | |
delay(1000); | |
} | |
else{ | |
} | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment