Build a Smart Night Light That Responds to Sound

Create a smart night light that uses sound detection to turn on automatically!

Posted by Nina Alvarez on May 10, 2025 · 5 mins read

Build a Smart Night Light That Responds to Sound

Introduction

Hey there, smart home enthusiasts! Have you ever come home late, tiptoed through the dark, and wished for a friendly little night light that could turn on as soon as you entered the room? Well, you’re in luck! In this blog post, we’ll walk you through the process of building a smart night light that responds to sound using Node-RED and some simple hardware components. This project is not only a fun way to dive into automation but also a great introduction to using Alexa with Node-RED to enhance your living space!

This tutorial is beginner-friendly, so even if you’re just starting with DIY smart home projects, you’ll find it easy to follow. Let’s get that night light shining!

Step-by-step setup guide

What You’ll Need

Before we jump into building, here’s a quick list of the components you’ll need:

  • Node-RED installed and running on your Raspberry Pi or computer
  • A microphone (USB or compatible with your system)
  • An LED light (you can use a smart LED bulb or a standard LED with a controller)
  • optional: a relay module to control the LED if it’s not smart
  • A power source for the LED light
  • Basic tools (screwdriver, wires, etc.)

Step 1: Setup Node-RED

  1. Install Node-RED: If you haven’t done this yet, install Node-RED by following these instructions.
  2. Access Node-RED: Open your web browser and go to http://localhost:1880 (or the corresponding address on your Raspberry Pi).

Step 2: Create Your Node-RED Flow

  1. Drag in nodes: Start by dragging in the following nodes: inject, rpi microphone, function, switch, light (smart or relay).
  2. Connect the nodes: Wire the nodes as follows:
    • Connect the inject node to the rpi microphone node to capture audio.
    • Wire the microphone node to a function node where you will analyze the sound.
  3. Sound Detection Logic: In the function node, write a simple script to detect sound. For example:

    if (msg.payload > threshold) { return msg; // Pass on if sound detected } return null; // Block message otherwise

  4. Set Up a Switch Node: Connect the output of the function node to a switch node that checks if sound is detected.

  5. Connect to Light: Finally, connect the switch node to the light node (or your relay) to turn the LED on when the sound threshold is met.

Step 3: Deploy Your Flow

Once everything is wired up, hit the Deploy button. Congratulations! You’ve created your basic flow to control the night light based on sound.

Step 4: Connect Alexa with Node-RED

To control your night light with Alexa, set up an integration with node red alexa:

  1. Install the Alexa Home Skill: In Node-RED, use the node-red-contrib-alexa-home-skill node to create an Alexa skill.
  2. Connect Your Light: Set this node to connect with the light control, enabling voice commands to turn on/off the light.
  3. Set Up an Announcement: You can even add an announcement feature with alerts for when the light is activated!

Helpful Tip Block

Enhance Your Project

  • Experiment with Voice Commands: Instead of just sound detection, try programming unique voice commands for your light. For example, “Alexa, light up!” could turn on the night light.
  • Use Automation: Consider integrating your night light with other smart home devices. For instance, program it to turn off after a certain time or link it with motion sensors for additional functionality.

Common Issues & Troubleshooting

  • Microphone Not Detected: Ensure that your microphone is connected properly and recognized by your OS. Try using a different USB port or cable if necessary.
  • Light Doesn’t Respond: Double-check your flow connections in Node-RED. Ensure all nodes are deployed correctly, and check that the relay is properly wired if you’re using one.
  • Sound Sensitivity Issues: If the night light continuously lights up due to ambient noise or doesn’t respond at all, adjust the threshold in your function node’s script.

Final Thoughts

And there you have it! You’ve built an innovative smart night light that not only glows to guide you in the dark but can also listen for commands or sounds. This project serves as an excellent introduction to the world of Node-RED and its integration with Alexa.

As you dive deeper into smart home automation, you’ll find countless ways to customize and enhance your projects. So don’t hesitate to tinker with your setup, explore new features, and share your experiences with the community. Happy automating, and may your nights always be bright!