Hello and help!
I am trying to use my new TTL serial camera for a project that is due on Thursday. I want to use the motion detect function to activate a servo. I checked the camera and adjusted the settings using the CommTool, and wired the camera to the Arduino, but I keep getting "no camera found." I checked and redid all my connections; I also checked to make sure I had imported all of the libraries I need. I'm not sure what else to try. A photo of the wiring is attached (the violet wire is TX) and the code is below. Please help! Thanks, Alix
/////////////////////////////
//VARS
#include <Servo.h>
#include <Adafruit_VC0706.h>
#include <SD.h>
#include <SoftwareSerial.h>
//int LDR_Pin = A1; //light detector to pin A0
//int LDRValue = 0; // int to store LDR value
//int light_sensitivity = 0; // value of light surrounding sensor
int ledPin = 13;
// Using SoftwareSerial (Arduino 1.0+) or NewSoftSerial (Arduino 0023 & prior):
#if ARDUINO >= 100
// On Uno: camera TX connected to pin 2, camera RX to pin 3:
SoftwareSerial cameraconnection = SoftwareSerial(2, 3);
// On Mega: camera TX connected to pin 69 (A15), camera RX to pin 3:
//SoftwareSerial cameraconnection = SoftwareSerial(69, 3);
#else
NewSoftSerial cameraconnection = NewSoftSerial(2, 3);
#endif
Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);
//int timerValue = 0;
//int minuteValue = 1;
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
boolean lockLow = true;
boolean takeLowTime;
int pos = 0; // variable to store the servo position
int r = 0; // variable to store random number
/////////////////////////////
//SETUP
void setup(){
Serial.begin(9600);
Serial.println("VC0706 Camera test"); //test for camera
if (cam.begin()) {
Serial.println("Camera Found:");
} else {
Serial.println("No camera found?");
return;
cam.setMotionDetect(true); // turn it on motion detected = true
Serial.print("Motion detection is ");
if (cam.getMotionDetect())
Serial.println("ON");
else
Serial.println("OFF");
}
pinMode(ledPin, OUTPUT);
//calibrateLight();
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
////////////////////////////
//LOOP
void loop()
{
// LDRValue = analogRead(LDR_Pin); //read the analogue value of the light sensor
// Serial.println(LDRValue);
// delay(10);
//if(LDRValue < light_sensitivity)
if (cam.motionDetected()) {
Serial.println("Motion!");
digitalWrite(13, HIGH);
r = int(random (0,180));
Serial.println(r);
if (r > pos)
{
for(pos; pos <= r; pos += 10) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
}
if (r < pos){
for(pos; pos >= r; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
}
}
else
{
digitalWrite(13, LOW);
}
//the led visualizes the sensors output pin state
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
cam.setMotionDetect(false);
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(15);
}
// timerValue += 10;
//
// if(timerValue >= 1800000){
// calibrateLight();
// timerValue =0;
// }
//
// }
//
//void calibrateLight(){ //calibration function defined
// float brightness = 0; //initial value = 0
// for(int i = 0; i<250; i++){
// brightness += analogRead(LDR_Pin);
// float divideRate = 10000/250; //10 seconds divided by 250 samples
// delay(divideRate); // evenly space time between samples
// }
//
// brightness = brightness/250; //average brightness
// light_sensitivity = brightness; //calibrated value
// light_sensitivity -= 20; //amount of interruption to activate servo
// Serial.print("sensor calibrated at");
// Serial.println(light_sensitivity);
Serial.println("...Done!");
cam.resumeVideo();
cam.setMotionDetect(true);
}