Monday, February 6, 2017

Hach-a-Toy Assignment

I name my creation: "Forward/Reverse LDR Tank"

Picture Goes Here:)
Video Goes Here Too :))



A Description of Project:

     Okay, originally I wanted my tank to have two H-Bridge components, so that I could also program a LEFT and RIGHT turn protocol.  But, I soldered a wrong transistor on my H-Bridge circuit and that took me a couple of stressful days to figure it out.  The lesson I learned was; Test your components functionality before any assembly!!!  I had to settle for the FORWARD and REVERSE protocol instead, so what a huge bummer :(

Front View
     My first idea was to do something that included a Tamiya gear box, because they are so cool and interesting.  I bought the Double Gear Box Kit, because it gives you four gear ratios: 12.7:1, 38:1, 115:1, or 344:1.  I chose 344:1, because the full set of yellow and glue gears looks supper cool.  The Twin-Motor Kit only allows two gear ratios and is slimmer in width.  I also bought the Universal Frame Kit and the Track and Wheel Kit separately to make a tank-like frame chassis. 
Rubber Track Assembly
Gear Ratio Set-Up

Motor Case Assembly
     The only Draw back to my chose was due to the wider gear box, I had to cut chunks out of my frame out on both sides to allow the mounting bar connect on the frame securing the gear box.  Also, it took me what seemed forever to connect four or five strands of rubber tracks to interlock.  It was like a Chinese puzzle, where you need to think out of the box.
Motor Case Mounting
Okay, I bought a battery holder that holds four AA batteries, which gives me enough juice to power the Arduino, H-Bridge, the two motors, and the LDR sensor.  The battery holder had one of those two button-like 9V male terminals, and I happen to have the female terminal connectors wired to a power jack that fits the Arduino.  I used a super small breadboard for small prototyping, and it has no power busses.  What a bummer :(  Mr. Denny gave me out of the kindness of his heart a working H-Bridge.  I also stole a 100K LDR and a 10K resistor, and a few solderless leads.  I cut off the ends of four leads and soldered them to the two DC motors that came with the Double Gear Kit :)
Side Shot of Battery Holder and DC Motor

Side Shot of Power Jack and Battery Holder

Track and Wheel Assembly
It turns out that you only need to output pins to make the darn thing go forwards and backwards, and an analog input pin as well.  I also used the 5V output to power everything besides the Arduino.  On the H-Bridge circuit we have 8 pins to use three of which are grounds.  From top to bottom these are the pins: Input 1, Input 2, Motor +, Motor -, Vcc, and the three grounds.  They way I have the DC motors configured Motor + is forward and Motor - is reverse.  Determining which input was forward or reverse in the Arduino Developer Environment, because it matters which terminal on the DC motors really does turn CW or CCW in relation to assigning the pin Motor 1 or 2 the correct command of HIGH or LOW.  When typing out your C++ code, figured out a few ways to make the motors actually do what I want (F/R).  It bothers me tremendously, when you assign a pin a specific function, only to figure that it really does the opposite of what you labeled it to do.  I fixed those bugs, even though there are many ways to do the same thing. 
Rear View
H-Bridge and Small Breadboard

     



I had PIN 13 connected to Input 1, PIN 12 to Input 2, Ground(Arduino) to Ground(H-Bridge), 5V output to Vcc, and DC motor terminals to there corresponding inputs Motor +/-.  The analog PIN A0 went to the LDR and resistor and all grounds from the sensor and H-bridge to a common row going all the way back to the Arduino ground next to PIN 13.  I uploaded the program to the Arduino chip, so my little creation can be free of its USB plug.  I will show the code later.  When the battery holder is plugged into the Arduino it powers on and goes into reverse when the LDR senses low light level (Below 850) and goes forward when the LDR senses light(Above 850).  And that is pretty much all it can do and this is what I spent days and days tinkering with.  This is why I have no gf :'(

BUT IT WORKS!!!!! :0 (Forever Alone face                 


    Copy and Paste Code Goes Here!!!!

Hack-a-Toy file

#define forwardAB 13  // Input 1 goes forward (CW)
#define reverseAB 12  // Input 2 goes reverse (CCW)

#define sensorPin A0  // Sensor  LDR
int sensorValue = 0;   //

void setup()
{
  Serial.begin(9600);  // Analog Input monitor

  pinMode(forwardAB,OUTPUT);
  pinMode(reverseAB,OUTPUT);

  pinMode(sensorPin,INPUT);
}

void loop()
{
  sensorValue = analogRead(sensorPin);  //  Sends input value data to serial monitor

    if(sensorValue > 850)
    {
     digitalWrite(forwardAB,HIGH);  // Motor A & B turns CW
     digitalWrite(reverseAB,LOW);    //
    }
    else if(sensorValue < 850)
    {
      digitalWrite(reverseAB,HIGH);  // Motor A & B turns CCW
      digitalWrite(forwardAB,LOW);
    }
   
    Serial.println(sensorValue);  //  Prints the value of the LDR input to serial monitor
    delay(300);
}




     I would have initialized forwardA/reverseA and forwardB/reverseB if I had two H-Bridges to assign each motor its own function to go forward or reverse independently; giving my hack-a-Toy to also turn left and right.
I noticed that the tank doesn't maintain a straight line because I tightened the gear box case differently for the two motors; not on purpose though and giving them roughly the same tolerance still did not fix the problem.  One motor just so happens to be fast than the other.
To fix this I will figure out Duty Cycle for the analogWrite() function for both motors if  I had an extra H-bridge.
I have another battery holder of the same voltage that I dedicate fully to the DC motors and increase the speed a bit, so that the battery hold for the Arduino is not carrying all the load.


This is the Tamiya website to chick out all there products:

http://www.tamiya.com/english/products/list/gearboxes/kit700P01.htm

The Pololu website has some decent prices:

https://www.pololu.com/category/34/tamiya-motors-and-gearboxes