Building a Smart Baby Monitor with Raspberry Pi: A Journey into DIY Tech

Becoming a new parent is an adventure filled with joy, sleepless nights, and the constant urge to keep an eye on your little one. When my son was born, I found myself concerned about the privacy and cost of commercial baby monitors. So, I embarked on a DIY journey to build a smart baby monitor using a Raspberry Pi. Not only did this project cater to my privacy concerns, but it also turned out to be a cost-effective solution that taught me a lot about electronics and programming.

The Inspiration

The inspiration behind this project was simple: I wanted a secure, smart baby monitor without the hefty price tag and privacy risks associated with retail options. With a background in tech and a passion for learning, I decided to leverage my skills to create a custom solution that could grow and evolve with our needs.

The Components

Here’s a list of the hardware components I used for the project:

  • Raspberry Pi (Model 3B, 3B+, 4, or newer)
  • MicroSD Card (16GB or larger, with Raspbian OS installed)
  • Power Supply (5V 2.5A for Raspberry Pi 3 or 5V 3A for Raspberry Pi 4)
  • USB Microphone
  • Speaker (3.5mm jack or USB)
  • Raspberry Pi Camera Module
  • MAX9814 Microphone Amplifier (with Auto Gain Control)
  • MCP3008 (10-bit ADC - Analog to Digital Converter)
  • DHT22 Temperature and Humidity Sensor
  • PIR Motion Sensor (HC-SR501 or compatible)
  • Breadboard, Jumper Wires, Resistors, Capacitors

The Setup

Step 1: Setting up the Raspberry Pi

First, I installed Raspbian OS on a microSD card and booted up the Raspberry Pi. Connecting a keyboard, mouse, and monitor made the initial setup straightforward. I ensured the system was up to date with the latest software.

Step 2: Connecting the Camera and Sensors

I attached the Raspberry Pi Camera Module, ensuring it was securely connected to the Pi’s camera port. Next, I wired up the DHT22 sensor, PIR motion sensor, and the MAX9814 microphone to the MCP3008 ADC, which then connected to the Pi’s GPIO pins. This setup allowed the Pi to read analog signals from the microphone and other sensors.

Step 3: Coding the Functionality

Using Python and Flask, I wrote scripts to capture video and audio, read sensor data, and create a web API for real-time monitoring. Flask made it easy to set up endpoints for video streaming, audio playback, and sensor data display.

Here's an example of the Python Flask API


GPIO.setmode(GPIO.BCM)
app = Flask(__name__)
CORS(app)

# Initialize components with config values
camera = CameraModule()
temp_sensor = TempHumiditySensor(Config.I2C_PORT, Config.I2C_ADDRESS)
sound_sensor = SoundSensor(spi_channel=0, spi_bus=0, adc_channel=0)
motion_sensor = MotionSensor(Config.GPIO_MOTION)
speaker = Speaker()

# Initialize the sensor data manager
db_manager = SensorDataManager()

# Initialize the orchestrator with the components
orchestrator = Orchestrator(camera, temp_sensor, sound_sensor, motion_sensor, speaker, db_manager)

# Initialize and start the scheduler
scheduler = Scheduler(orchestrator, Config.POLL_INTERVAL_SECONDS, Config.CLEANUP_INTERVAL_SECONDS)
scheduler.start()

@app.route('/video_feed')
def video_feed():
    def generate():
        while True:
            frame = orchestrator.get_video_feed()
            yield (b'--frame\r\n'
                   b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
    return Response(generate(), mimetype='multipart/x-mixed-replace; boundary=frame')

@app.route('/play_audio', methods=['POST'])
def play_audio():
    audio_stream = request.files['audio']
    orchestrator.play_audio(audio_stream)
    return 'Audio played', 200

@app.route('/sensor_data')
def sensor_data():
    data = orchestrator.get_sensor_data()
    return jsonify(data)

@app.route('/historical_data')
def historical_data():
    limit = request.args.get('limit', default=None, type=int)
    data = orchestrator.get_historical_data(limit)
    return jsonify(data)

if __name__ == '__main__':
    app.run(host=Config.IP_ADDRESS, port=5000)

Once the API was complete I then wrote a simple web app with RazzleJS and Bootstrap to communicate with the API.

Step 4: Ensuring Privacy and Security

To address my privacy concerns, I ensured that all communications between the Pi and my devices were encrypted. I also set up the Pi on a separate network, minimizing exposure to potential security threats.

The Result

The final product was a smart baby monitor that provided live video, audio, and environmental data. I could access the monitor securely from any device within my home network, giving me peace of mind without compromising privacy.

The Learnings

This project was a fantastic learning experience. I delved deeper into Raspberry Pi, Python, and Flask, and learned how to integrate various sensors and modules. It was also a great way to brush up on my soldering skills and electronics knowledge.

Conclusion

Building a smart baby monitor with Raspberry Pi was a rewarding project that combined practicality with learning. For anyone interested in DIY tech projects, I highly recommend trying something similar. Not only can you tailor the solution to your specific needs, but you’ll also gain valuable skills and knowledge along the way. Plus, there’s nothing quite like the satisfaction of creating something functional and meaningful with your own hands.

So, if you’re a new parent with a knack for technology, why not give it a try? Your baby (and your wallet) will thank you!

TreJon House / RaspiBaby · GitLab
GitLab.com
Completed Open Source Project
Author image
About TreJon House
You've successfully subscribed to Coding House
Great! Next, complete checkout for full access to Coding House
Welcome back! You've successfully signed in.
Unable to sign you in. Please try again.
Success! Your account is fully activated, you now have access to all content.
Error! Stripe checkout failed.
Success! Your billing info is updated.
Error! Billing info update failed.