Auto Car

  • Nick Demmer, Joe Bechard, Allison McCarthy
  • Our project was to design a car that would be able to drive around and take pictures upon contact with something in front of it.
  • The program was designed so that the car would continue in a forward direction until contact with an object, where a picture would be taken, the car would back up, turn, and drive off. Each motion has a specific code written so that it will follow this pattern indefinitely.
  • Pictures of your device
  • Short video of your device working (post to YouTube or Google Video). You must describe the operation of the device and a brief overview of the code in your video.
  • Circuit diagram or Fritzing Picture 
  • int motor1 = 4;           //declares the first pin for the motor
    int motor2 = 5;           //declares the other pin for the motor
    int motorpmw = 9;     // this is the pmw that will set how much battery power the motor is getting (speed)
    int motorpmw2 = 8;
    int motor3 = 7;
    int motor4 =3;
    int pushbutton = 6;

    #include <Adafruit_VC0706.h>
    #include <SD.h>
    #include <SoftwareSerial.h>        
    #define chipSelect 10
    #if ARDUINO >= 100
    SoftwareSerial cameraconnection = SoftwareSerial(2, 3);
    NewSoftSerial cameraconnection = NewSoftSerial(2, 3);

    Adafruit_VC0706 cam = Adafruit_VC0706(&cameraconnection);

    void setup()
      pinMode(motor1, OUTPUT);           //
      pinMode(motor2, OUTPUT);           // these simply are declaring them as outputs
      pinMode(motorpmw, OUTPUT);     //
      pinMode(motor3, OUTPUT);
      pinMode(motor4, OUTPUT);
      pinMode(motorpmw2, OUTPUT);
      pinMode(pushbutton, INPUT);

     // When using hardware SPI, the SS pin MUST be set to an
      // output (even if not connected or used).  If left as a
      // floating input w/SPI on, this can cause lockuppage.
    #if !defined(SOFTWARE_SPI)
    #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
      if(chipSelect != 53) pinMode(53, OUTPUT); // SS on Mega
      if(chipSelect != 10) pinMode(10, OUTPUT); // SS on Uno, etc.

      Serial.println("VC0706 Camera snapshot test");
      // see if the card is present and can be initialized:
      if (!SD.begin(chipSelect)) {
        Serial.println("Card failed, or not present");
        // don't do anything more:
      // Try to locate the camera
      if (cam.begin()) {
        Serial.println("Camera Found:");
      } else {
        Serial.println("No camera found?");
      // Print out the camera version information (optional)
      char *reply = cam.getVersion();
      if (reply == 0) {
        Serial.print("Failed to get version");
      } else {

      // Set the picture size - you can choose one of 640x480, 320x240 or 160x120
      // Remember that bigger pictures take longer to transmit!
      cam.setImageSize(VC0706_640x480);        // biggest
      //cam.setImageSize(VC0706_320x240);        // medium
      //cam.setImageSize(VC0706_160x120);          // small

      // You can read the size back from the camera (optional, but maybe useful?)
      uint8_t imgsize = cam.getImageSize();
      Serial.print("Image size: ");
      if (imgsize == VC0706_640x480) Serial.println("640x480");
      if (imgsize == VC0706_320x240) Serial.println("320x240");
      if (imgsize == VC0706_160x120) Serial.println("160x120");

      Serial.println("Snap in 3 secs...");

      if (! cam.takePicture())
        Serial.println("Failed to snap!");
        Serial.println("Picture taken!");
      // Create an image with the name IMAGExx.JPG
      char filename[13];
      strcpy(filename, "IMAGE00.JPG");
      for (int i = 0; i < 100; i++) {
        filename[5] = '0' + i/10;
        filename[6] = '0' + i%10;
        // create if does not exist, do not open existing, write, sync after write
        if (! SD.exists(filename)) {
      // Open the file for writing
      File imgFile =, FILE_WRITE);

      // Get the size of the image (frame) taken 
      uint16_t jpglen = cam.frameLength();
      Serial.print("Storing ");
      Serial.print(jpglen, DEC);
      Serial.print(" byte image.");

      int32_t time = millis();
      pinMode(8, OUTPUT);
      // Read all the data up to # bytes!
      byte wCount = 0; // For counting # of writes
      while (jpglen > 0) {
        // read 32 bytes at a time;
        uint8_t *buffer;
        uint8_t bytesToRead = min(32, jpglen); // change 32 to 64 for a speedup but may not work with all setups!
        buffer = cam.readPicture(bytesToRead);
        imgFile.write(buffer, bytesToRead);
        if(++wCount >= 64) { // Every 2K, give a little feedback so it doesn't appear locked up
          wCount = 0;
        //Serial.print("Read ");  Serial.print(bytesToRead, DEC); Serial.println(" bytes");
        jpglen -= bytesToRead;

      time = millis() - time;
      Serial.print(time); Serial.println(" ms elapsed");

    void loop()
      analogWrite(motorpmw, 255);      // this is the analog speed value for the arduino (0-255)
      analogWrite(motorpmw2, 255);
      digitalWrite(motor1, LOW);        
      digitalWrite(motor2, HIGH);          //turns the motors on - forwards
      digitalWrite(motor3, HIGH);
      digitalWrite(motor4, LOW);


    if (digitalRead(pushbutton)==HIGH){

                                   //summons demons to influence the creation of man into waiting for exactly 1 second.

    void forward(int time)
      digitalWrite(motor1, LOW);        
      digitalWrite(motor2, HIGH);          //turns the motors on - forwards
      digitalWrite(motor4, HIGH);
      digitalWrite(motor3, LOW);

    void backward(int time)
      digitalWrite(motor1, HIGH);
      digitalWrite(motor2, LOW);      //makes motor go backwards
      digitalWrite(motor3, LOW);
      digitalWrite(motor4, HIGH);
      delay (time);
      void right(int time)
       digitalWrite(motor1, HIGH);
       digitalWrite(motor2, LOW);
       digitalWrite(motor3, HIGH);
       digitalWrite(motor4, LOW);

    void left (int time)
  • We have had problems involving the H bridge and memory card, which we overcame with help from our fantastically awesome teacher, Professor Dickie. We also can't get the right wheel or the camera to work. Joe's working on that now.
  • We would use blue tooth technology to control the car with a wii remote, and attach a laser pointer to the car. With enough donations, we may be able to create an Artificial intelligence to operate the car instead. It would be like terminator, except without the terminators.