Austen CrabtreeBoothe PfaffNick Lindley
Published

Light Activated by Motion or Sound

Automatic lights in your house may sound futuristic, but with this design it can easily be implemented in any room.

BeginnerShowcase (no instructions)200
Light Activated by Motion or Sound

Things used in this project

Hardware components

LED (generic)
LED (generic)
×1
Breadboard (generic)
Breadboard (generic)
×3
Jumper wires (generic)
Jumper wires (generic)
×8
Mini Pyroelectric PIR Human Sensor Module PIR Infrared IR Sensor Body Manual Motion Infrared IR Detector
×1
Sound Sensor Sound Detector for Arduino, ESP32, ESP8266
×1
Photon 2
Particle Photon 2
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×3

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Adafruit

Story

Read more

Schematics

Sound Sensor Circuit Diagram

The setup for this sensor is very simple to construct. Three wires connecting the grounds, input voltage, and output voltages are inputted into the breadboard directly from the Photon Particle 2 to the sound sensor.

Sound Sensor Graph

Motion Sensor Circuit Diagram

This circuit connects the input voltage, output voltage, and ground from the Photon Particle 2 to the motion sensor.

Motion Sensor Graph

LED Light Circuit Diagram

The LED Light is connected to the D7 and the ground of the Photon Particle 2. This makes it directly connected to the D7 light. Our code turns the D7 light on when there is sound or motion which in turn turns on the LED Light.

LED Light Graph

Code

Motion Detector Code

C/C++
#include "Particle.h"

// Pin definitions
const int motionPin = A2;
const int ledPin = D7;

// Declares the outputs and inputs
void setup() {
 pinMode(motionPin, INPUT);
  pinMode(ledPin, OUTPUT);
 
}

void loop() {
 if (analogRead(motionPin) > 700){//
    digitalWrite(ledPin, HIGH);
    Particle.publish("motionDetected", "Motion detected!", PUBLIC);
    delay(100);
    digitalWrite(ledPin, LOW);
   
}
}

Sound Sensor Code

C/C++
// Define the pin to which the sound sensor is connected
const int soundSensorPin = A0;

void setup() {
  // Subscribe to the "soundDetected" event
  Particle.subscribe("soundDetected", soundDetectedHandler);

  // Print a message to indicate that the Photon is ready
  Serial.begin(9600);
  Serial.println("Particle Photon is ready!");
}

void loop() {
  // Read the analog value from the sound sensor
  int soundValue = analogRead(soundSensorPin);

  // Adjust the threshold value based on your sensor and environment
  int soundThreshold = 1500;

  // Check if the sound value exceeds the threshold
  if (soundValue > soundThreshold) {
    // Publish the "soundDetected" event
    Particle.publish("soundDetected", "Sound detected!");

    // Wait for a moment to avoid continuous triggering
    delay(1000);
  }
}

void soundDetectedHandler(const char *event, const char *data) {
  // Print a message when the event is received
  Serial.println("Sound detected event received: " + String(data));
}

LED Light Code

C/C++
int ledPin = D7;

void setup() {

pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW); 
Particle.subscribe("motionDetected", motionDetectedHandler, "0a10aced202194944a04a3ec");
Particle.subscribe("soundDetected", soundDetectedHandler), "0a10aced202194944a04979c";

}

void motionDetectedHandler(const char *event, const char *data)

{
digitalWrite(ledPin, HIGH); 
delay (5000);
digitalWrite(ledPin, LOW); 
}
void soundDetectedHandler(const char *event, const char *data)
{
digitalWrite(ledPin, HIGH); 
delay (5000);
digitalWrite(ledPin, LOW);
}
void loop() {

}

Credits

Austen Crabtree

Austen Crabtree

1 project • 1 follower
Boothe Pfaff

Boothe Pfaff

1 project • 1 follower
Nick Lindley

Nick Lindley

1 project • 1 follower

Comments