Arduino Nano Motion Detection With OV7670 and Dual ESP8266 Setup
by Breadboard_tinker_2024_ in Circuits > Microcontrollers
193 Views, 1 Favorites, 0 Comments
Arduino Nano Motion Detection With OV7670 and Dual ESP8266 Setup
This project involves building a movement detection system using computer vision, powered by an Arduino Nano and two Node MCUs as microcontrollers. The system leverages basic computer vision techniques to detect motion in almost real-time, making it an ideal solution for small-scale monitoring or security applications. Despite using minimal hardware, it efficiently processes video data and communicates between the microcontrollers for accurate detection. The combination of the Arduino Nano and Node MCUs offers both simplicity and flexibility,
Supplies
1 x Arduino Nano
2 x Node MCU
1 x ov7670 camera(no FIFO)
1 x breadboard
1 x led
1 x TXSO108E level shifter(any high speed level shifter should work)
1 x normal level shifter(any thing would work)
Computer (with Arduino IDE installed)
jumper wire(male to male and female to female)
2 x 4.2k resistors
1 x USB cable for Nano
2 USB cables for Node MCU
Connection
connections
Connections for Arduino Uno/Nano
OV7670 connections:
VSYNC - PIN2
XCLCK - PIN3 (must be level shifted from 5V -> 3.3V)
PCLCK - PIN12
SIOD - A4 (I2C data) - 4.2K resistor to 3.3V
SIOC - A5 (I2C clock) - 4.2K resistor to 3.3V
D0..D3 - A0..A3 (pixel data bits 0..3)
D4..D7 - PIN4..PIN7 (pixel data bits 4..7)
3.3V - 3.3V
RESET - 3.3V
GND - GND
PWDN - GND
Connections between Arduino and Node MCU1
Arduino Node MCU1
TX (level shifter TXSO108E) RX
Ground (level shifter TXSO108E) Ground
5V (level shifter TXSO108E)
connections between Node MCU1 and Node MCU2
Node MCU1 Node MCU1
TX RX
Ground Ground
3.3v 3.3v
Camera to LED
Camera LED
HS(HREF) +
Arduino to LED
Arduino LED
G G
Libraries and Arduino IDE
For this we will be using Arduino ide 1.8.18 (I get what you are probably thinking right now) but this is for a reason. since we are using the Live Ov7670 library which was created by Indrek Luuk and the good thing about this library is that the creator of the library also made a tool which can take advantage of the library. So basically this tool allows you to display the captured images on the screen (although this feature wont be used in the movement detection project its still petty cool to play around with and most importantly for debugging. But Arduino discontinued the functionality of custom libraries over time. So we have to stick to a old ide version for now.
Get Arduino ide 1.8.18 from here
Download the libraries
The library used in this project was made by Indrekluuk.
In order to download the Live OV7670 library you have to visit here then
step1
visit the GitHub page i gave.
Step2
Download ZIP.
Step3
extract the ZIP
Step4
copy the libraries and past them in the Arduino libraries folder
Step5
open the Live ov7670 file
got to src
then click the Arduino file
The Code of Arduino
Step1
click on ExampleUart.cpp file in the ide"
Step2
Change UART mode to 2
Step 3
open step.h
Look at the comment section for instructions
with
Code for Node MCU 1
This Code handles the data for noise reduction.
Step1
Download the file attached and upload it to a Node MCU.
Note: make sure to disconnect the RX and TX pins before uploading and then reconnecting them.
Note: if you have a question feel free to ask it in the comments.
The code
Downloads
Node MCU 2 Code
This MCU handles the actual motion detection task
This code works by substracting a frame from another frame the farer the result is to 0 the higher the movement is.
currently if the difference is over 40 the program will count it as movement which you can adjust with
The code
Step1
Download the file attached and upload it to a Node MCU.
Note: make sure to disconnect the RX and TX pins before uploading and then reconnecting them.
Note: if you have a question feel free to ask it in the comments.
Finalizing
Step2
plug in everything except Node MCU1(because it receives power via Node MCU 2)
Step1
open the serial monitor on Node MCU2 (the first few statement may not be correct because the camera take time to adjust ) Wait until you get 3 - 4 outputs typically 1 minute - 2 minute then you should see a reliable output.
if there is noise(the outputs going crazy while nothing is moving o the camera is still and even after 3 minutes if this
check for loose connections still if the issue persists move on to step3.
Step 3(debugging)
disconnect Node MCU 2 and connect Node MCU 1 to the Seria1 monitor then u should be seeing that the a string or a 40x40 array being printed on the same frequency the led turns on and off if it is so then use shorter wires and if this doesn't fix it then move on to step 4.
if you don't see the led blink at the rate the serial monitor prints then use shorter wires with the Arduino.
if you see no led blinks recheck the wiring of the camera or tighten it
if you see nothing in the serial monitor move on to step4
Step4(even more debugging)
if you are here then comment the error and the symptoms in the comment section.
I will try by best to help you.