Saturday, December 14, 2013

Coding is so fun.

SO for Mr. Marvin I was able to get both components working.

 Unfortunately I was not able to get them to work together.
 So I was able to get the trigger and sound fx working, and the motors to work with code, but couldn't get them in unison.

 Here is the very simple code that was used to move Marvin. (note: a separate Adafruit library has to be installed in order for it to work.)


#include <AFMotor.h>

AF_DCMotor motor3(3, MOTOR34_64KHZ); // create motor #3, 64KHz pwm

AF_DCMotor motor4(4, MOTOR34_64KHZ); // create motor #3, 64KHz pwm


void setup()
{
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
 
  motor3.setSpeed(200);     // set the speed to 200/255
  motor4.setSpeed(200);     // set the speed to 200/255
}

void loop()
{
  Serial.print("tick");
 
  motor3.run(FORWARD);      // turn it on going forward
  motor4.run(FORWARD);      // turn it on going forward
  delay(1100);

 Serial.print("tack");
  motor3.run(RELEASE);      // stopped
  motor4.run(RELEASE);      // stopped
  delay(1000);

  Serial.print("tock");
  motor3.run(BACKWARD);     // the other way
  motor4.run(BACKWARD);     // the other way
  delay(1000);
 
  Serial.print("tack");
  motor3.run(RELEASE);      // stopped
  motor4.run(RELEASE);      // stopped
  delay(1000);
}





 This is the code that was written for 'everything' and it was very quickly garbage because the motor controller that we used didnt follow the Arduino format at all. And thats OK, you win some and lose others.



int valm=0;
int valm1=0;
int trigger=0;
int triggerlock=0;
const int pwmA=3;
const int pwmB=11;
const int brakeA=9;
const int brakeB=8;
const int dirA=12;
const int dirB=13;
const int relay=2;




void setup()

{
pinMode(relay, OUTPUT);

digitalWrite(relay, HIGH);

delay(500);//leave relay on .5 second--makes "eek" sound
digitalWrite(relay, LOW);
}


void loop()

{

    trigger=analogRead(3);
    if(trigger<500 or triggerlock>0) {//light shining on sensor now or previously
   
      triggerlock=100;//don't check light again
   
   
  pinMode(dirA, OUTPUT);
  pinMode(brakeA, OUTPUT);
 
  pinMode(dirB, OUTPUT);
  pinMode(brakeB, OUTPUT);
 
  digitalWrite(dirA, HIGH);//forward A
  digitalWrite(brakeA, LOW);//release brake A
  analogWrite(pwmA, 150);//set speed A
 
  digitalWrite(dirB, HIGH);//forward B motor
  digitalWrite(brakeB, LOW);
  analogWrite(pwmB, 150);//set speed B
 


valm=analogRead(0);
valm1=analogRead(1);
if(valm>520 or valm1>520)

{

      digitalWrite(relay, HIGH);//turn on "eek" sound
      delay(100);
      digitalWrite(relay, LOW);
      digitalWrite(brakeA, HIGH);//stop motor A
      digitalWrite(brakeB, HIGH);//stop Motor B
     
      digitalWrite(dirA, LOW);//reverse A
      digitalWrite(brakeA, LOW);//release brake A
      analogWrite(pwmA, 150);//set speed A
     
      digitalWrite(dirB, LOW);//reverse B
      digitalWrite(brakeB, LOW);
      analogWrite(pwmB, 150);//set speed B
     
      delay(300);
     
      digitalWrite(brakeA, HIGH);//stop one wheel
     
      delay(400);
      digitalWrite(brakeB, HIGH);//stop other wheel



    //start both wheels forward
    digitalWrite(dirA, HIGH);//forward A
    digitalWrite(brakeA, LOW);//release brake A
    analogWrite(pwmA, 150);//set speed A
   
    digitalWrite(dirB, HIGH);//forward B
    digitalWrite(brakeB, LOW);
    analogWrite(pwmB, 150);//set speed B
   
    delay(700);//get past startup current

}
}
}

Friday, December 13, 2013

12/13/2013 Update

After trying several different ways to get our mechanism to start running properly, we realized that we couldn't using the materials that we had. The 6V battery that we have was not enough to power the circuit. Given more time, we would trade that for a higher voltage battery. Also, the motor shield that we got did not have the sensing capabilities that we wished for, so if we were to do this again, we would have gotten a better motor shield. Under these circumstances, we were only able to get one part of our circuit running at a time. For our project, we were hoping to get a light sensor to turn on the recording module and to turn on the motor to get the RC car running. With the battery we had, we were unable to get both parts running. In other words, we could have gotten the photosensor to turn on the recording module, or we could have used the power to get the car moving, but not both at the same time.

However, here are some photos of the assembled project and a video of the car moving:






Wednesday, December 11, 2013

Almost There..

On Monday, the build began. We finished all sub-assemblies by soldering the batteries and needed wires to control sensors, motors, and recording module. After many attempts, we finalized the segment of song that will play when the box begins to move. The motor shield is attached to the Arduino board and the schematic for the motor shield is followed when wiring the project together. The frame that was 3D printed was attached to the R/C car with screws. The outside “Christmas present” was designed and manufactured then wrapped with Christmas paper.  This was made out of an old poster board and will rest on top of the laser printed part to be able to cover the whole R/C car. The whole project has been set up and functions. We still run into a problem with the sensor not stopping the program on the board. We have started the paper for our project. 

Friday, December 6, 2013

PARTs, parts, partS.

So as from the title you can see that some parts have come in.

Here's how they came out.


These are all the parts.


This is used to keep the battery in place.


This in the 3-D Printed superstructure. Looks awesome btw.

And this is the base plate that all the electronics are going on, 
But it also serves as the top of the box.