Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Luke StroudDavid Arguello
Published

IoT Project Group 38 - Pet Sound Monitoring

We all love pets and want to keep them safe, allow us to help you monitor them with the use of sound!

BeginnerProtip1 hour46
IoT Project Group 38 - Pet Sound Monitoring

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×2
Elegoo Large Microphone Module
×1
Elegoo Small Microphone module
×1
Female/Female Jumper Wires
Female/Female Jumper Wires
×6
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×2

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Circuit Schematic for Device A configuration

Circuit Schematic for Device B configuration

Code

Pin Header file

C/C++
As the title says this file is to guard against multiple inclusion errors for pin declarations
#ifndef PINS_H
#define PINS_H

const int bigSoundSensorPin = D2;
const int smallSoundSensorPin = D3;

#endif // PINS_H

Thingspeak Header File

C/C++
As the title says this file is to guard against multiple inclusion errors for thingspeak functions
#ifndef THINGSPEAK_H
#define THINGSPEAK_H

extern char thingSpeakAPIKey[];

void publishToThingSpeak(String data);

#endif // THINGSPEAK_H

Device A

C/C++
This is the code for device A which connects to the big sound sensor, subscribing to device B readings, and publishing them accordingly for field chart updates.
#include "Particle.h"
#include "thingspeak.h"
#include "pins.h"

extern char thingSpeakAPIKey[];

void handleSmallSoundEvent(const char *event, const char *data);

void deviceA_setup() {
  pinMode(bigSoundSensorPin, INPUT);
  Particle.subscribe("small-sound-detected", handleSmallSoundEvent);
}

void deviceA_loop() {
  int bigSoundValue = digitalRead(bigSoundSensorPin);

  if (bigSoundValue == HIGH) {
    // Publish an event when the big sound sensor detects a sound
    Particle.publish("big-sound-detected", "1", PRIVATE);

    // Publish the big sound value to ThingSpeak
    publishToThingSpeak("field1=" + String(bigSoundValue));
  }

  // Your additional logic for device A goes here

  delay(1000); // Adjust delay as needed
}

void handleSmallSoundEvent(const char *event, const char *data) {
  // Process the received event data here if needed

  // Turn on D7 LED when a small sound event is received
  digitalWrite(D7, HIGH);
  delay(4000);  // Keep the LED on for 4 seconds
  digitalWrite(D7, LOW);
}

Device B

C/C++
This is the code for device B which connects to the small sound sensor, subscribing to device A readings, and publishing them accordingly for field chart updates.
#include "Particle.h"
#include "thingspeak.h"
#include "pins.h"

extern char thingSpeakAPIKey[];

void handleBigSoundEvent(const char *event, const char *data);

void deviceB_setup() {
  pinMode(smallSoundSensorPin, INPUT);
  Particle.subscribe("big-sound-detected", handleBigSoundEvent);
}

void deviceB_loop() {
  int smallSoundValue = digitalRead(smallSoundSensorPin);

  if (smallSoundValue == HIGH) {
    // Publish an event when the small sound sensor detects a sound
    Particle.publish("small-sound-detected", "1", PRIVATE);

    // Publish the small sound value to ThingSpeak
    publishToThingSpeak("field2=" + String(smallSoundValue));
  }

  delay(1000); // Adjust delay as needed
}

void handleBigSoundEvent(const char *event, const char *data) {
  // Process the received event data here if needed

  // Turn on D7 LED when a big sound event is received
  digitalWrite(D7, HIGH);
  delay(4000);  // Keep the LED on for 4 seconds
  digitalWrite(D7, LOW);
}

Thingspeak File

C/C++
This file is for uploading purposes to Thingspeak for live readings from the field charts with API Key insert
#include "Particle.h"
#include "thingspeak.h"

char thingSpeakAPIKey[] = "Write API Key";// Replace with your ThingSpeak API Key

void publishToThingSpeak(String data) {
  Particle.publish("ThingSpeak", data, PUBLIC);
}

Credits

Luke Stroud

Luke Stroud

1 project • 1 follower
David Arguello

David Arguello

1 project • 1 follower

Comments