SSRN Id4166233
SSRN Id4166233
SSRN Id4166233
Ninad Mehendale
Abstract:
There are many ways to capture images with a single board computer. The Low-cost solution could be
to use INR 155/- OV 7670 module and INR 350/- Arduino. This article covers details about how to
interface the OV7670 module to Arduino and how to take images from it. It is a beginner's guide and
the codes provided in it are available on the internet.
Introduction:
Cameras have always dominated the electronics industry as it has lots of applications such as visitor
monitoring system, surveillance system, attendance system, etc. Cameras that we use today are smart
and have a lot of features that were not present in earlier cameras. While today's digital cameras not
only capture images but also captures high-level descriptions of the scene and analyze what they see. It
is used extensively in Robotics, Artificial Intelligence, Machine Learning, etc. The Captured frames are
processed using Artificial Intelligence and Machine Learning and then used in many applications like
Number plate detection, object detection, motion detection, facial recognition, etc. In this manuscript,
we will interface the most widely used camera module OV7670 with Arduino UNO. The camera
module OV7670 can be interfaced with Arduino Mega as well. The camera module is hard to interface
with because it has a large number of pins. Also, the wire becomes very important when using camera
modules as the choice of the wire and length of the wire can significantly affect the picture quality and
can bring the noise.
The camera is set to take a QVGA image so the resolution need to be selected. The function configures
the register to take a QVGA image.
setResolution();
In this manuscript, the images are taken in monochrome, so the register value is set to output a
monochrome image. The function sets the register values from register list which is predefined in the
program.
setColor();
Figure 5: Image after Actual wiring of OV7670 with Arduino with Jumper wire
Code:
#include <stdint.h>
#include <avr/io.h>
#include <util/twi.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#define qvga 1
#define qqvga 2
#define yuv422 0
#define rgb565 1
#define bayerRGB 2
/* Registers */
/*
*/
#define CMATRIX_LEN 6
struct regval_list{
uint8_t reg_num;
uint16_t value;
};
{ REG_COM14, 0x19 },
{ 0x72, 0x11 },
{ 0x73, 0xf1 },
{ REG_HSTART, 0x16 },
{ REG_HSTOP, 0x04 },
{ REG_HREF, 0xa4 },
{ REG_VSTOP, 0x7a },
{ REG_VREF, 0x0a },
};
{ REG_COM1, 0 },
{ REG_COM15, COM15_R00FF },
{ 0x51, 0 }, /* vb */
{ REG_COM13, COM13_UVSAT },
};
{ REG_COM7, COM7_RESET },
{ REG_TSLB, 0x04 }, /* OV */
{ REG_COM7, 0 }, /* VGA */
*/
{ REG_COM3, 0 }, { REG_COM14, 0 },
{ REG_GAIN, 0 }, { REG_AECH, 0 },
{ REG_HAECC7, 0x94 },
{ 0x8f, 0 }, { 0x90, 0 },
{ 0x91, 0 }, { 0x96, 0 },
{ 0x6e, 0x11 }, { 0x6f, 0x9e }, /* it was 0x9F "9e for advance AWB" */
{ REG_RED, 0x60 },
/* Matrix coefficients */
{ 0x58, 0x9e },
{ 0x78, 0x04 },
{ 0x79, 0x26 },
};
_delay_ms(100);
void twiStart(void){
error_led();
TWDR = DATA;
error_led();
error_led();
twiStart();
twiAddr(camAddr_WR, TW_MT_SLA_ACK);
twiWriteByte(reg, TW_MT_DATA_ACK);
twiWriteByte(dat, TW_MT_DATA_ACK);
_delay_ms(1);
if (nack){
error_led();
return TWDR;
else{
error_led();
uint8_t dat;
twiStart();
twiAddr(camAddr_WR, TW_MT_SLA_ACK);
twiWriteByte(reg, TW_MT_DATA_ACK);
_delay_ms(1);
twiStart();
twiAddr(camAddr_RD, TW_MR_SLA_ACK);
dat = twiRd(1);
_delay_ms(1);
return dat;
reg_addr = pgm_read_byte(&next->reg_num);
reg_val = pgm_read_byte(&next->value);
writeReg(reg_addr, reg_val);
void setColor(void){
wrSensorRegs8_8(yuv422_ov7670);
// wrSensorRegs8_8(qvga_ov7670);
void setResolution(void){
wrSensorRegs8_8(qvga_ov7670);
void camInit(void){
writeReg(0x12, 0x80);
_delay_ms(100);
wrSensorRegs8_8(ov7670_default_regs);
void arduinoUnoInut(void) {
cli();//disable interrupts
OCR2A = 0;//(F_CPU)/(2*(X+1))
_delay_ms(3000);
//enable serial
UBRR0H = 0;
UBRR0L = 1;//0 = 2M baud rate. 1 = 1M baud. 3 = 0.5M. 7 = 250k 207 is 9600 baud
rate.
do{
UDR0 = pgm_read_byte_near(str);
} while (pgm_read_byte_near(++str));
uint16_t y, x;
StringPgm(PSTR("*RDY*"));
y = hg;
while (y--){
x = wg;
while (x--){
_delay_ms(100);
void setup(){
camInit();
setResolution();
setColor();
writeReg(0x11, 10); //Earlier it had the value:writeReg(0x11, 12); New version works
better for me :) !!!!
void loop(){
captureImg(320, 240);
Just Upload the code and open the Serial Port Reader and grab the frames.
Serial Port Reader is a simple GUI. This captures the base64 encode and decodes it to form an
image. Just follow these simple steps to use Serial Port Reader
Step 4: One can also save this pictures by just clicking on “Save Picture”.
Discussions:
Try to use jumper wires as short as possible. Avoid any loose contact with any pins on Arduino or
OV7670. Be careful about connections as a large number of wiring can lead to short circuits. If the
UNO gives 5V output to GPIO then use Level Shifter. Use 3.3V Input for OV7670 as exceeding voltage
than can damage the OV7670 module.
References:
[1] https://circuitdigest.com/microcontroller-projects/how-to-use-ov7670-camera-module-with-
arduino
[2] https://www.youtube.com/watch?v=6bfY9JXOppI