Components and supplies
Arduino UNO
3G/GPRS/GSM Shield for Arduino with GPS - European version SIM5320E
MicroSD card breakout board+
TTL Serial JPEG Camera with NTSC Video
Commercial MLC microSD
Tools and machines
Soldering iron (generic)
Wires, etc.
Apps and platforms
Arduino IDE
Project description
Code
EmailCamera.ino
arduino
Make photo (VC0706). Write photo to microSD card. Send photo to Email.
1#include <VC0706_UART.h> 2#include <SPI.h> 3#include <SD.h> 4#include <XModem.h> 5// comment out this line if using Arduino V23 or earlier 6#include <SoftwareSerial.h> 7#define chipSelect 4 8SoftwareSerial cameraconnection = SoftwareSerial(2, 3); 9XModem xmodem(&Serial, ModeXModem); 10VC0706 cam = VC0706(&cameraconnection); 11const char smtp_server[ ] = "*****"; // SMTP server 12const char smtp_user_name[ ] = "*****"; // SMTP user name 13const char smtp_password[ ] = "*****"; // SMTP password 14const char smtp_port[ ] = "*****"; // SMTP server port 15//Write here you SIM card data 16const char apn[] = "*****"; 17const char user_name[] = "*****"; 18const char password[] = "*****"; 19//Write here your information about sender, direcctions and names 20const char sender_address[ ] = "*****"; // Sender address 21const char sender_name[ ] = "*****"; // Sender name 22const char to_address[ ] = "*****"; // Recipient address 23const char to_name[ ] = "*****"; // Recipient name 24char subject[ ] = "My First Email"; 25const char body[ ] = "Picture:"; 26#define chipSelect 4 // enable uSD card 27int8_t answer; 28int onModulePin = 8; 29char aux_str[64]; 30char filename[14]; 31void setup(void) 32{ 33 pinMode(onModulePin, OUTPUT); 34 Serial.begin(115200); 35 delay(5000); 36 power_on(); 37 while ((sendATcommand("AT+CREG?", "+CREG: 0,1", 500) || 38 sendATcommand("AT+CREG?", "+CREG: 0,5", 500)) == 0 ); 39 // see if the card is present and can be initialized: 40 if (!SD.begin(chipSelect)) { 41 // don't do anything more: 42 return; 43 } 44 if (true == cameraInit()) { 45 snapShot(); 46 sendEmail(); 47 } else { 48 } 49} 50void loop(void) 51{ 52} 53bool cameraInit(void) 54{ 55 cam.begin(BaudRate_38400); 56 char *reply = cam.getVersion(); 57 if (reply == 0) { 58 return false; 59 } else { 60 return true; 61 } 62} 63void snapShot(void) 64{ 65 if (!cam.takePicture()) { 66 } else { 67 } 68 // Create an image with the name IMAGExx.JPG 69 strcpy(filename, "IMAGE000.JPG"); 70 for (int i = 0; i < 1000; i++) { 71 filename[5] = '0' + i/100; 72 filename[6] = '0' + (i/10)%10; 73 filename[7] = '0' + i%10; 74 // create if does not exist, do not open existing, write, sync after write 75 if (! SD.exists(filename)) { 76 break; 77 } 78 } 79 // Open the file for writing 80 File imgFile = SD.open(filename, FILE_WRITE); 81 uint16_t jpglen = cam.getFrameLength(); 82 int32_t time = millis(); 83 cam.getPicture(jpglen); 84 uint8_t *buffer; 85 while(jpglen != 0) { 86 uint8_t bytesToRead = min(32, jpglen); 87 buffer = cam.readPicture(bytesToRead); 88 imgFile.write(buffer, bytesToRead); 89 //Serial.print("Read "); Serial.print(bytesToRead, DEC); Serial.println(" bytes"); 90 jpglen -= bytesToRead; 91 } 92 imgFile.close(); 93 time = millis() - time; 94 cam.resumeVideo(); 95} 96void sendEmail(void) 97{ 98 sprintf(aux_str, "AT+CRXFILE=\\"%s\\"", filename); 99 if (!sendATcommand(aux_str, "OK", 2000)) { 100 } 101 File dataFile = SD.open(filename); 102 // if the file is available, write to it: 103 if (dataFile) { 104 xmodem.sendFile(dataFile, filename); 105 } 106 // if the file isn't open, pop up an error: 107 else { 108 return; 109 } 110 dataFile.close(); 111 // sets the SMTP server and port 112 sprintf(aux_str, "AT+SMTPSRV=\\"%s\\",%s", smtp_server, smtp_port); 113 if (!sendATcommand(aux_str, "OK", 2000)) { 114 } 115 // sets user name and password 116 sprintf(aux_str, "AT+SMTPAUTH=1,\\"%s\\",\\"%s\\"", smtp_user_name, smtp_password); 117 if (!sendATcommand(aux_str, "OK", 2000)) { 118 } 119 // sets sender adress and name 120 sprintf(aux_str, "AT+SMTPFROM=\\"%s\\",\\"%s\\"", sender_address, sender_name); 121 if (!sendATcommand(aux_str, "OK", 2000)) { 122 } 123 // sets sender adress and name 124 sprintf(aux_str, "AT+SMTPRCPT=1,0,\\"%s\\",\\"%s\\"", to_address, to_name); 125 if (!sendATcommand(aux_str, "OK", 2000)) { 126 } 127 // subjet of the email 128 sprintf(aux_str, "AT+SMTPSUB=\\"%s\\"", filename); 129 if (!sendATcommand(aux_str, "OK", 2000)) { 130 } 131 // body of the email 132 sprintf(aux_str, "AT+SMTPBODY=\\"%s %s\\" ", body, filename); 133 if (!sendATcommand(aux_str, "OK", 2000)) { 134 } 135 sprintf(aux_str, "AT+SMTPFILE=1,\\"%s\\"", filename); 136 if (!sendATcommand(aux_str, "OK", 2000)) { 137 } 138 // sets APN, user name and password 139 sprintf(aux_str, "AT+CGSOCKCONT=1,\\"IP\\",\\"%s\\"", apn); 140 if (!sendATcommand(aux_str, "OK", 2000)) { 141 } 142 sprintf(aux_str, "AT+CSOCKAUTH=1,1,\\"%s\\",\\"%s\\"", user_name, password); 143 if (!sendATcommand(aux_str, "OK", 2000)) { 144 } 145 delay(2000); 146 // sends the email and waits the answer of the module 147 answer = sendATcommand("AT+SMTPSEND", "+SMTP: SUCCESS", 60000); 148 if (answer == 1) { 149 } else { 150 } 151} 152void power_on(void) 153{ 154 uint8_t answer=0; 155 // checks if the module is started 156 answer = sendATcommand("AT", "OK", 2000); 157 if (answer == 0) { 158 // power on pulse 159 digitalWrite(onModulePin,HIGH); 160 delay(3000); 161 digitalWrite(onModulePin,LOW); 162 // waits for an answer from the module 163 while(answer == 0) { // Send AT every two seconds and wait for the answer 164 answer = sendATcommand("AT", "OK", 10000); 165 } 166 } 167} 168int8_t sendATcommand(char* ATcommand, char* expected_answer1, unsigned int timeout) 169{ 170 uint8_t x=0, answer=0; 171 char response[100]; 172 unsigned long previous; 173 memset(response, '\\0', 100); // Initialize the string 174 delay(100); 175 while( Serial.available() > 0) Serial.read(); // Clean the input buffer 176 Serial.println(ATcommand); // Send the AT command 177 x = 0; 178 previous = millis(); 179 // this loop waits for the answer 180 do { 181 // if there are data in the UART input buffer, reads it and checks for the answer 182 if (Serial.available() != 0) { 183 response[x] = Serial.read(); 184 x++; 185 // check if the desired answer is in the response of the module 186 if (strstr(response, expected_answer1) != NULL) { 187 answer = 1; 188 } 189 } 190 // Waits for the answer with time out 191 } 192 while((answer == 0) && ((millis() - previous) < timeout)); 193 return answer; 194}
Downloadable files
VC0706 scheme
VC0706 scheme
VC0706 scheme
VC0706 scheme
VC0706 scheme
VC0706 scheme
Comments
Only logged in users can leave comments
Anonymous user
5 years ago
what simulator you used for circuit design?