Introduction: ESP32 Remote Surveillance Robot
The ESP32 robot cam is a mobile surveillance robot that can be controlled over the internet. It is built around a standard ESP32-Cam board, plus a motor driver, batteries, power supply board, and motorized platform. It also includes an optional inductive charger so that it can "dock" and recharge itself while remaining connected to the internet and ready to respond to commands without depleting its battery.
UPDATE March 2021: These instructions were written for a breadboard, but since then I designed a PCB. If you're serious about building this and want to use a PCB, private message me.
- ESP32-Cam (AI-Thinker, or clone)
- The one I bought from BangGood was configured to use an external antenna, whereas the one from Amazon used the internal antenna. Both work, and you can switch a board from one to the other, though it requires some delicate desoldering and resoldering. If you need an external antenna, get one with a "U.FL Mini PCI" connector.
- AdaFruit PowerBoost 500
- DRV883 Motor Driver
- LiPoly battery, such as this one.
- 4x AA batteries
- Half-size breadboard
- Robot chassis, such as this one or search for "2WD Motor Smart Robot Car Chassis" on Aliexpress.
- Variable potentiometer (optional, for reporting charging status on the web page)
- Inductive charger (optional)
- Male to male Dupont wires, or other breadboard wires
Step 2: Assembly
- Assemble the robot chassis according to the instructions that come with it. The instructions that came with mine were pretty incomprehensible, but it's not that hard to figure out how to put it together even without instructions.
- Solder headers onto the Esp32-Cam, the PowerBoost, and the Motor Driver.
- If using an external antenna, (and assuming it is like mine) unscrew the two halves, drill a 1/4" hole in a convenient spot in the chassis, feed the body of the antenna through the top, then screw in the other half from below, and secure with the nut. Attach the wire to the underside of the ESP32-Cam.
- Plug the Esp32-Cam, the PowerBoost, and the Motor Driver into the breadboard with the PowerBoost at the top, Motor Driver in the middle, then the variable potentiometer, then the ESP32-Cam at the bottom. On a half-size breadboard, there are just barely enough rows to fit everything. The camera lens will be pointing up at the ceiling so you'll want to flex it 90 degrees so it is pointing forward; I put a cube of poster tack behind it to hold it up.
- Attach breadboard to car chassis, towards the front, with camera facing forward, using hot glue or adhesive strips.
- Plug the Li-poly battery into the PowerBoost. Important: Make sure the polarity of the battery matches the polarity of the PowerBoost; otherwise, you will destroy both. If you buy your battery from Adafruit, it will match. But if purchased elsewhere, it very well may be reversed. If you need to reverse the polarity, see this video.
- Use an adhesive strip to mount the inductive charger (the half with the oval copper coil) to the front of the top of the chassis so that the coil hangs over the front of the chassis like a bumper. See photo.
- Tape the other half of the inductive charger to a wall, at a height where it aligns with the half on the chassis. See photo. Attach USB power.
- Insert 4 AA batteries into the holder.
- Plug a USB cable from your PC to the FTDI board. Connect the FTDI's TX to the ESP32-Cam's RX, and the FTDI's RX to the ESP32-Cam's TX, and Gnd to Gnd. (The FTDI does not need to supply power because that will come from the PowerBoost.)
Step 3: Wiring
Now wire up everything according to the wiring table in the photo above.
Most of the wiring is just plugging wires into the breadboard, but you'll probably want to solder the wires to the motor terminals. And solder the AA battery pack wires to header pins to make them easier to insert into the breadboard. Same with the inductive charger wires.
I used the breadboard rails for USB and GND. For the 5V I just used the holes next to the PowerBoost 5V.
Step 4: Optional Wiring
You may want to put a pushbutton between the PowerBoost's EN and GND to make resetting easier. Or just have a dangling Dupont wire hanging off EN that you can plug into GND (also useful for turning off the power when robot is not in use). Or both.
You may want to connect the Motor Driver's EEP to GND temporarily. This will disable the motors until you are ready to actually use the robot, thereby preventing the robot from accidentally flying off your desk, or pulling out FTDI wires or whatever.
Step 5: Software
- If you are not already familiar with how to use the Arduino IDE to upload code to an Esp32-Cam, see this tutorial.
- The sketch is available on https://github.com/jasonful/esp32cam-car. It is based on this sketch by Hyuk Kang.
- Open the sketch in the Arduino IDE. Enter your SSID and password into esp32cam-car.ino. Under the Tools/Board menu choose "AI Thinker ESP32-CAM". Under Tools/Port choose the port corresponding to the FTDI.
- Upload the sketch and open the Serial Monitor (115200 baud).
- Disconnect Io0 from GND, and reset (by momentarily pulling PowerBoost's EN to GND, or pressing the button if you installed one).
Step 6: Usage
- The ESP32-Cam's LED will blink once when the camera is initialized correctly, and then twice when WiFi is connected. It will blink 3 times if camera initialization fails, and then reboot. (This happened to me sporadically.)
- In the Serial monitor, you will see the address of the robot's web page. You may want to go into your router's settings and permanently assign that IP address to your ESP32, so you never have to hook up the serial monitor again.
- Disconnect the FTDI from the ESP32.
- Is you disabled the motors, connect EEP to 5V now.
- Open the robot's web page, and you should see a streaming video and a set of buttons to control the robot. You should be able to now drive your robot from the web page. The go/back/left/right buttons take effect as long as they are held down. The smaller buttons outside those are the "nudge" buttons: They take effect for 100 milliseconds, and are useful for nudging the robot just a little bit.
- To recharge the robot, drive it over to the spot on the wall where you mounted the other half of the inductive charger. It might be difficult to get it perfectly aligned. Note you have to manually refresh the web page to see the "Charging" show up. You might want to manually align the two halves, then see what the camera sees, so you can try to duplicate that view in the future. NOTE: While this is an interesting proof of concept for remote charging, I do not recommend actually leaving the robot unattended while charging, because I don't want anyone to burn their house down.
Step 7: Final Notes
Calibrating the charge level
To detect when the battery is charging, there is a connection from the PowerBoost's USB pin to an input pin on the ESP32. When the input pin reads HIGH, the web page will say "Charging" on the bottom left. I would have expected this pin to be at 0V when not charging, but for some reason there is a small voltage, roughly 1.0 to 1.7V, which is enough to register as HIGH. So the variable potentiometer divides this voltage to a lower level that registers as LOW on the input pin. To calibrate this, rotate the potentiometer to a point where the web page will say "Charging" when a USB power cable is plugged into the PowerBoost, and not say "Charging" when not plugged in.
Accessing from the internet
By default, the robot's web page is only accessible from your local network. To access it from a remote location over the internet, you will need to set up a VPN to tunnel into your local network. Or you can set up port forwarding on your router, but if you don't want any random person on the internet controlling your robot, you will need to add authentication.
If your ESP32-Cam often says "Brownout trigger detected" on boot, it could be caused by any number of power-related problems. For me, it was poor wire connections on the breadboard.
The variable potentiometer is optional; it is there just so the web page can tell you when the robot is charging, i.e., when the robot is "docked" correctly to the inductive charger. But if you are not using the inductive charger, or not operating the robot remotely, you probably don't need it.
I used separate batteries for the ESP32 and for the motors. Theoretically, you could use one power source for both, but since the ESP32-Cam is so finicky about its power supply, I didn't risk it. But if you use a different 5V supply, and you don't care about charging it remotely, you could even get rid of the PowerBoost board entirely.
Other models of motor driver should certainly work.
Motors on startup
When the ESP32 boots, the left motor turns on (reverse) for a fraction of a second, which can be bad if the robot is on a desk or nearby something. I tried various solutions but was unable to fix this, so if anyone verifies a solution, let me know...
As mentioned above, I do not actually recommend leaving the robot unattended while charging, as these are handmade robots, not UL Listed, and I do not want to be responsible for any fires.
If you find any bugs in the code, the design, or this documentation, please log an issue on github.