Using ESP32 CAM and Raspberry Pi with MotionEye OS
Everyone wants a low budget security system. Whether you are looking to find out who is coming into your yard, entering a room they don’t belong, or simply who is stealing the last doughnut from the fridge. Or possibly all 3. Any IP camera worth something also comes with a high price tag, and offers little in the options of control. Whatever your reason there is always one to build a DIY system. In this post I will walk through the setup of using a Raspberry Pi with MotionEye OS, and then connecting to a low budget ESP32 Cam module.
Hardware
Raspberry Pi
- Raspberry Pi
- SD card
- Power Supply or Step down converter to use with a solar powered battery
- Or one of our great essentials kits
- Raspberry Pi camera
- Optional display
- Ethernet connection
ESP32
- Esp32 cam
- Some form of 5V power supply
- FTDI programmer
- Some female to female jumper cables
In this example I will describe using a broken 5V cellphone charger to power the ESP
Setup
First you will need to download all the required software.
What is MotionEyeOS?
MotionEyeOS is a Linux distribution that turns your single-board computer into a video surveillance system.
Flash the OS onto the Raspberry Pi SD card using the Raspberry Pi imaging tool. Raspberry Pi Imager makes the imaging process much easier. It centralizes all of the most common imaging tools and software you need into one package. You don’t even need NOOBs to install Raspberry Pi OS (formerly Raspbian). Raspberry Pi Imager includes Raspbian as well as a few other operating systems. If something isn’t listed, you can use the custom image tool to add your own images as we will do here.
- Visit the Raspberry Pi download page.
- Download the Raspberry Pi Imager installer for your Operating System.
- Run the installer and follow the prompts to complete the setup
- Insert the SD card into your laptop/desktop
- Launch Raspberry Pi Imager.
- Click Choose OS.
- Select Use custom to write an unlisted image.
- Select the MotionEye OS downloaded earlier.
- Click Choose SD card.
- Select from the list the SD card you want to write to.
- Click Write to begin the image writing process.
Start up your Pi
Insert the SD card into the Raspberry Pi. Add your wired connection, as this is a requirement for MotionEye and power up your Raspberry Pi. If you have opted to connect your Raspberry Pi to a display for the initial setup you will see your Raspberry Pi IP address on the display once booted. Otherwise you can scan your network with a 3rd party application like Angry IP scanner. The IP you’re looking for is the one with “meye” on the name.
Open your browser onto the IP of your Pi. You will now be faced with the quick setup of MotionEye. Log in using admin as user and no password. First I would advise changing the login settings by clicking on the three bars menu, and open the General Settings. Then Enable Advanced Settings. Click the orange button at the top right “Apply” to apply the changes – this will require a reboot.
If you have a camera connected to your Pi, it should be detected automatically, and you should see a live image from the camera. You can also enable Wireless Network in the Network menu. Simply add your wireless network information and if you would like; your static IP information. This will be useful later. Below mine is set to “10.0.0.101”
The software is intuitive to use. Take a look at the menus and see what they can do.
ESP32 CAM
Now that our Raspberry Pi is ready to go, let’s take a look at our ESP32 Cam.
The ESP32-CAM is a very small camera module with the ESP32-S chip that costs much less than any other product with similar features. Besides the OV2640 camera, and several GPIOs to connect peripherals, it also features a microSD card slot that can be useful to store images taken with the camera or to store files to serve to clients.
The ESP32-CAM doesn’t come with a USB connector, so you need an FTDI programmer to upload code through the U0R and U0T pins (serial pins). There are three GND pins and two pins for power: either 3.3V or 5V.
GPIO 1 and GPIO 3 are the serial pins. You need these pins to upload code to your board. Additionally, GPIO 0 also plays an important role, since it determines whether the ESP32 is in flashing mode or not. When GPIO 0 is connected to GND, the ESP32 is in flashing mode.
Once you have installed the Arduino IDE you need to add the ESP32 add-on. I will be walking through the Linux setup, but you can find the Mac setup here and the Windows setup here.
Important: before starting this installation procedure, make sure you have the latest version of the Arduino IDE installed in your computer. If you don’t, uninstall it and install it again. Otherwise, it may not work. Having the latest Arduino IDE software installed from arduino.cc/en/Main/Software, continue with this tutorial.
Open the preferences window from the Arduino IDE. Go to Arduino > Preferences
Enter “https://dl.espressif.com/dl/package_esp32_index.json” into the “Additional Board Manager URLs” field as shown in the figure below. Then, click the “OK” button
Note: if you already have the ESP8266 boards URL, you can separate the URLs with a comma as follows:
https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json
Open boards manager. Go to Tools > Board > Boards Manager
Search for ESP32 and press install button for the “ESP32 by Espressif Systems“
That’s it. It should be installed after a few seconds.
Testing the Installation
Plug the ESP32 board to your computer. Then, follow these steps:
- Open the Arduino IDE
- Select your Board in Tools > Board menu (in my case it’s the AI Thinker ESP32-CAM)
- Select your Port in Tools > Port menu (in my case /dev/ttyUSB0)
- Open the following example under File > Examples > WiFi (ESP32) > WiFi Scan, opening a new sketch.
- Press the Upload button in the Arduino IDE. Wait a few seconds while the code compiles and uploads to your board.
- If everything went as expected, you should see a “Done uploading.” message.
- Open the Arduino IDE Serial Monitor at a baud rate of 115200
- Press the ESP32 on-board Enable button and you should see the networks available near your ESP32
And that is it, hopefully you now have your system setup correctly to program and use your ESP32 Cam module.
Next Steps
If you have not yet done so, you now need to download the sketch for RTSP Video Streaming. You can download the code either by clicking on the green code drop down and selecting “Download ZIP”; and extract the file once downloaded. Or by opening a terminal where in the folder where you want to store your file. For Linux:
cd Documents
mkdir ESP32Cam-streamer
cd ESP32Cam-streamer
git clone https://github.com/bnbe-club/rtsp-video-streamer-diy-14.git
- You can of course use the file GUI system as well.
- You can then open the diy-e14.ino file in your Arduino IDE:
- Click on File > Open and navigate to where you have downloaded your sketch.
You need to edit the wifikey.h file by entering your SSID and Password. Then you can again verify and upload your code. Then open the serial monitor and described earlier. This should show you the RTSP url that you need to enter into your MotionEye setup.
Add a new camera to MotionEye
We will start by clicking on the 3 bars menu to open the settings. Then select the “Camera” menu next to the 3 bars. This will open a drop down where you will find the add camera option.
Here you enter the URL provided by the serial monitor of your Arduino IDE. Leave the username and password blank for now, and click on next to the word camera so the type of camera can be automatically generated.
After a small wait you should now see your camera feed from the ESP camera.
I needed to first change the frame rate in the Video Device and Video Streaming menus. I moved the scroller up to 30 in small increments at a time until I started getting my video output.
Now that you have both cameras streaming to MotionEye, you can repeat the steps for the ESP camera if you want to add more cameras. But the only thing left to do is to mount your cameras and arrange power for the cameras.
I 3D printed some enclosures, here are some good ones I came across in Thingiverse
- https://www.thingiverse.com/thing:3652452/files
- https://www.thingiverse.com/thing:4692583
- https://www.thingiverse.com/thing:4911478
There are several options available here. I will be using a step down converter to attach my Raspberry Pi and ESP to a solar charged battery. This module provides you with 2 USB ports.
For the Raspberry Pi I used a USB A to micro-USB cable. For the ESP I took an old USB phone charger cable that was no longer working and cut the Micro-USB point off to expose the power and ground wires. This I attached to the 5V and GND pins on the ESP. Which enabled me to power my entire setup from a battery.
Why not let us know what you used your Surveillance system for in the comments below.
If you want to chat to us or need any more help getting started, feel free to email us at [email protected]
Resources:
https://www.instructables.com/9-RTSP-Video-Streamer-Using-the-ESP32-CAM-Board/
https://randomnerdtutorials.com/install-motioneyeos-on-raspberry-pi-surveillance-camera-system/