This project involves building a pool safety monitoring device using an Arduino board, a gyroscope sensor, and a microphone. The device detects movement and sound to identify if anyone is swimming in the pool when there is no lifeguard present. Upon detection, it sends a Bluetooth notification to another Arduino, which is connected to a buzzer and LED, alerting the concerned individuals.
Components Needed- Arduino Uno (2 units)
- Gyroscope Sensor (e.g., MPU-6050)
- Microphone Sensor
- Bluetooth Module (e.g., HC-05)
- Buzzer
- LED
- Breadboard & Jumper Wires
- 9V Battery (or any suitable power source)
- Detection Phase:The Arduino with the gyroscope and microphone continuously monitors movement in the pool and listens for sounds.When either sensor detects movement or sound that matches swimming activity, it triggers an alert.
- Communication Phase:Upon detecting swimming activity, the first Arduino sends a Bluetooth signal to another Arduino stationed remotely (e.g., near the lifeguard station).
- Alert Phase:The second Arduino receives the signal and activates a buzzer and an LED, warning of pool activity.
Assembling the Sensor Unit:
- Connect the gyroscope and microphone sensor to the first Arduino.
- Connect the Bluetooth module (HC-05) to transmit data wirelessly.
- Assembling the Sensor Unit:Connect the gyroscope and microphone sensor to the first Arduino.Connect the Bluetooth module (HC-05) to transmit data wirelessly.
- Assembling the Receiver Unit:Connect the second Bluetooth module to the second Arduino.Connect the buzzer and LED to the output pins of the Arduino.
- Coding:Upload the sensor code to the first Arduino and the receiver code to the second Arduino.
You'll need two sets of code for this project:
Transmitter Arduino Code (with Gyro, Microphone, and Bluetooth):
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
#include <Wire.h>
const int MPU_addr = 0x68;
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
int minVal = 265;
int maxVal = 402;
double x;
double y;
double z;
// Set up a new SoftwareSerial object
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
// Example 5 - Receive with start- and end-markers combined with parsing
void setup() {
// put your setup code here, to run once:
mySerial.begin(9600);
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
}
int sound;
void loop() {
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14, true);
AcX = Wire.read() << 8 | Wire.read();
AcY = Wire.read() << 8 | Wire.read();
AcZ = Wire.read() << 8 | Wire.read();
int xAng = map(AcX, minVal, maxVal, -90, 90);
int yAng = map(AcY, minVal, maxVal, -90, 90);
int zAng = map(AcZ, minVal, maxVal, -90, 90);
x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);
int soundValue = 0; //create variable to store many different readings
for (int i = 0; i < 32; i++) //create a for loop to read
{
soundValue += analogRead(A0); //read the sound sensor
}
soundValue >>= 5; //bitshift operation
Serial.println(soundValue); //print the value of sound sensor
//if a value higher than 500 is registered, we will print the following
//this is done so that we can clearly see if the threshold is met
if (soundValue > 500) {
sound = 1;
}
//Serial.print("AngleX= ");
//Serial.println(x);
//
//Serial.print("AngleY= ");
//Serial.println(y);
//
//Serial.print("AngleZ= ");
//Serial.println(z);
//Serial.println("-----------------------------------------");
// put your main code here, to run repeatedly:
mySerial.print("<" + String(x) + "," + String(y) + "," + String(z) + "," + String(sound) + ">");
mySerial.println();
delay(800);
sound = 0;
}
Receiver Arduino Code (with Bluetooth, Buzzer, and LED):
#include <SoftwareSerial.h>
#define rxPin 10
#define txPin 11
// Set up a new SoftwareSerial object
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars]; // temporary array for use when parsing
// variables to hold the parsed data
int integer1,integer2,integer3,integer4;
boolean newData = false;
//============
void setup() {
mySerial.begin(9600);
Serial.begin(9600);
Serial.println("This demo expects 3 pieces of data - text, an integer and a floating point value");
Serial.println("Enter data in this style <HelloWorld, 12, 24.7> ");
Serial.println();
pinMode(3,OUTPUT);
digitalWrite(3,LOW);
pinMode(A0,OUTPUT);
digitalWrite(A0,LOW);
pinMode(A3,OUTPUT);
digitalWrite(A3,LOW);
pinMode(2,OUTPUT);
digitalWrite(2,LOW);
}
//============
void loop() {
recvWithStartEndMarkers();
if (newData == true) {
strcpy(tempChars, receivedChars);
// this temporary copy is necessary to protect the original data
// because strtok() used in parseData() replaces the commas with \0
parseData();
showParsedData();
newData = false;
if(integer4 == 0 || (integer1 >10 && integer1<350) || (integer2 >10 && integer2<350)){
digitalWrite(A0,HIGH);
digitalWrite(3,HIGH);
delay(1000);
digitalWrite(A0,LOW);
digitalWrite(3,LOW);
delay(1000);
}
}
}
//============
void recvWithStartEndMarkers() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (mySerial.available() > 0 && newData == false) {
rc = mySerial.read();
if (recvInProgress == true) {
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
//============
void parseData() { // split the data into its parts
char * strtokIndx; // this is used by strtok() as an index
strtokIndx = strtok(tempChars,","); // get the first part - the string
integer1 = atoi(strtokIndx);
strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
integer2 = atoi(strtokIndx); // convert this part to an integer
strtokIndx = strtok(NULL, ",");
integer3 = atof(strtokIndx); // convert this part to a float
strtokIndx = strtok(NULL, ",");
integer4 = atof(strtokIndx); // convert this part to a float
}
//============
void showParsedData() {
Serial.print("x ");
Serial.println(integer1);
Serial.print("y ");
Serial.println(integer2);
Serial.print("z");
Serial.println(integer3);
Serial.print("Sound");
Serial.println(integer4);
}
Testing:Simulate swimming activity in the pool (by moving the gyro sensor or generating sound) and check if the second Arduino triggers the buzzer and LED alert.
Comments