Brandon PinedaJacob KellyTravis Horne
Published

Sound Activated Lights

This is a cool way to turn on LED lights by simply using sounds to activate them

IntermediateFull instructions provided144
Sound Activated Lights

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×3
Breadboard (generic)
Breadboard (generic)
×1
uxcell Sound Microphone Sensor Detection Module with DO AO for Arduino UNO R3 AVR PIC 3pcs
×1
Jumper wires (generic)
Jumper wires (generic)
×1
5V USB LED Strip
×1
AA Batteries
AA Batteries
×1
Teyleten Robot DC 1 Channel Optocoupler 3V/3.3V Relay High Level Driver Module Isolated Drive Control Board 3V/3.3V Relay Module for Arduino
×1
Battery Holder, AA x 4
Battery Holder, AA x 4
×1
Slide Switch
Slide Switch
×1

Software apps and online services

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

Story

Read more

Schematics

Switch Sensor Photon Circuit

LED Photon Circuit

Sound Sensor Photon Circuit

Code

Photon #1 with LED strip, battery, and relay module

C/C++
// Define the pin for output
int outputPin = D7;

// Flags to keep track of received events
bool event1Received = false;
bool event2Received = false;

// Function prototypes
void eventHandler1(const char *event, const char *data);
void eventHandler2(const char *event, const char *data);

void setup() {
  // Setup pin mode
  pinMode(outputPin, OUTPUT);

  // Subscribe to Particle Cloud events
  Particle.subscribe("onoffswitch", eventHandler1);
  Particle.subscribe("turnOnOffLED", eventHandler2);
}

void loop() {
  // Check if both events have been received simultaneously
  if (event1Received && event2Received) {
    // Trigger action (e.g., send voltage to pin D7)
    digitalWrite(outputPin, HIGH);

    // Stay on for an additional 0.5 seconds
    delay(300);

    // Turn off pin D7
    digitalWrite(outputPin, LOW);

    // Reset flags for the next iteration
    event1Received = false;
    event2Received = false;
  } else {
    // If both events are not received simultaneously, turn off pin D7
    digitalWrite(outputPin, LOW);
  }

  // You can add other code here as needed
}

// Event handler for the first event
void eventHandler1(const char *event, const char *data) {
  // Set the flag for event1Received
  event1Received = true;
  Particle.Publish("Recieved_Sound", PRIVATE);
}

// Event handler for the second event
void eventHandler2(const char *event, const char *data) {
  // Set the flag for event2Received
  event2Received = true;
  Particle.Publish("Recieved_Switch", PRIVATE);
}

Photon #2 with sound sensor

C/C++
// Sender Particle Photon 2 code

const int analogInputPin = D1;      // Analog input pin for voltage measurement
const int senderLedPin = D7;         // Pin connected to the sender Photon's LED
const double voltageThreshold = 0.2; // Threshold voltage to trigger the command

Particle.subscribe("Recieved_Sound", PRIVATE);

void setup() {
  // Initialize LED pin as an output
  pinMode(senderLedPin, OUTPUT);
}

void loop() {
  // Read the voltage from the analog input
  double voltage = analogRead(analogInputPin) * (3.3 / 4095.0);

  // Print the voltage to the serial monitor
  Serial.print("Voltage: ");
  Serial.println(voltage);

  // Check if the voltage is higher than the threshold
  if (voltage > voltageThreshold) {
    // Turn on the sender Photon's LED
    digitalWrite(senderLedPin, HIGH);

    // Trigger the command to the receiver Photon
    Particle.publish("turnOnOffLED", "TurnOnOffLED");

    delay(300);  // Keep the LED on for 2 seconds

    // Turn off the sender Photon's LED
    digitalWrite(senderLedPin, LOW);
  }

  delay(1);  // Delay between voltage readings
}

Photon #3 with switch sensor

C/C++
// Define the pin for input
int inputPin = D7;

// Flag to track whether to send signals
bool sendSignal = false;

// Function prototype
void sendParticleSignal();

void setup() {
  // Setup pin mode
  pinMode(inputPin, INPUT);

  // You can adjust the debounce time based on your requirements
  attachInterrupt(inputPin, detectVoltageChange, CHANGE);
  
  Particle.Subscribe("Recieved_switch", PRIVATE);
}

void loop() {
  if (sendSignal) {
    // Continuously send Particle Cloud signal
    sendParticleSignal();
  }

  // You can add other code here as needed
}

void detectVoltageChange() {
  // Read the voltage level on pin D7
  int voltageLevel = digitalRead(inputPin);

  // If voltage is detected, set the flag to true
  // If voltage is not detected, set the flag to false
  sendSignal = (voltageLevel == HIGH);
}

void sendParticleSignal() {
  // Modify this function to send your desired Particle Cloud signal
  Particle.publish("onoffswitch", "OnOffSwitch");

  // You can add a delay here if needed to control the frequency of signal sending
  delay(300);
}

Credits

Brandon Pineda
1 project • 0 followers
Jacob Kelly
1 project • 0 followers
Travis Horne
1 project • 0 followers

Comments