Joking Tank

This is a project that I did at my school the HKU, that required for us to make something with a Arduino Uno. I wanted to make something that would do my favorite thing, make people laugh. So decided to make a joke box that would throw you a joke, but what joke it gave you would depend on what a couple of sensor modules were measuring at that certain moment in time. To make it more personal I decided to make it a tank.

Step 1: Getting the Parts.

The parts that you would be needed to recreate this project would be

  • 1x computer capable of running Arduino IDE
  • 1x Arduino Uno
  • 1x usb connector cable for Arduino Uno
  • 1x Sonar sensor
  • 1x Speaker( preferable one of decent quality(, I used one I pulled out of a bluetooth speaker)).
  • 1x LM386 Amplifier module( it is possible to make this yourself but I used a module).
  • 1x LM393 Microphone
  • 1x LDR
  • 1x LED( any colour will do but I used blue).
  • 4x 1kΩ resistor
  • 1x 2,7kΩ resistor
  • 1x Breadboard
  • 1x micro SD card( preferably small (1 or 2 gb)).
  • 1x Power drill.
  • 1x 16mm drillhead( preferably made for drilling metal).
  • 1x 9mm drillhead( also preferably made for drilling metal).
  • 1x 1mm drillhead( again preferably made for drilling metal).
  • 1x Model tank( I used a 1:35 scale leopard 2 but other cases should be fine aswell).
  • Superglue / hotglue
  • and quite some wires preferably in different colours.
  • cable ties( optional).

Step 2: Wiring

We need to start with the wiring, the image is a technical drawing of how it should all be wired up.
This should serve as your blueprint.
Note: All the Arduino ports are named AP# for each port.
So the 4th port on the Arduino is AP4, port A0 is APA0 and port 6~ is AP6~, etc
All the other ports are named as they appear on the modules themselves.

Step 3: Pre Code Things

Now before we can start using code we need some stuf.
I recomend you now follow this mans tutorial from step 2 to 4

http://www.electronoobs.com/eng_arduino_tut8.php

However we are not going to use his code as we are going to be using our own
Please note that some speaker use different frequencys.
My speaker used 16-bit 32kHz audio files. So if your speak is making some kind of noise but not playing your files then try playing with your frequency.

Step 4: Code

Now we are going to upload the code to the arduino.
Copy all of this and past it into the Arduino IDE and upload it to your Arduino.

//includes the library for the SD card reader.<br>#include "Wtv020sd16p.h"
//includes the library needed for the sonar sensor.
#include < NewPing.h >
//Sets the pins for the Arduino.
int resetPin = 4;
int clockPin = 5;
int dataPin = 6;
int busyPin = 7;
int soundDetectedPin = 12;
int lightDetectedPin = A0; 

//Sets the pins for the SD card library.
Wtv020sd16p wtv020sd16p(resetPin, clockPin, dataPin, busyPin);
//Sets the pins for the Sonar sensor library.
NewPing sonar(11, 10);

//Sets up the other inputs and sets the bitrate of the program.
void setup() {
  wtv020sd16p.reset();
  pinMode(lightDetectedPin, INPUT);
  pinMode(soundDetectedPin, INPUT);
  Serial.begin(9600);
}

//Main part of the program.
void loop() {
  //Sets the intergers    
  int lightDetectedVal = analogRead(lightDetectedPin);
  int distanceVal = sonar.ping_cm();
  int soundDetectedVal = digitalRead(soundDetectedPin);
  
  //Delay so that the project the project won't infinitly keep using the speaker.    
  delay(30000);
  //Serial print and print lines so that you can easly see what values are taken by the sensor modules.    
  Serial.print("Sound Value: ");
  //Multiple if statements so that the program plays different audio files depending on the values are measured by the sensor modules.    
  if (soundDetectedVal == 0) {
    Serial.println(soundDetectedVal);
    Serial.print("Distance: ");
    if (distanceVal == 0) {
      Serial.println(distanceVal);
      Serial.print("Light Value: ");
      if (lightDetectedVal >= 1000) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(1);
        //Another serial print so that you can see what exact audio file was played.                
        Serial.println("1--------");
        //Another delay to let the audio file play it's full lenght.
        delay(5000);
      } else if (lightDetectedVal >= 900) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(2);
        Serial.println("2--------");
        delay(5000);
      } else if (lightDetectedVal >= 800) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(3);
        Serial.println("3--------");
        delay(5000);
      } else if (lightDetectedVal >= 700) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(4);
        Serial.println("4--------");
        delay(5000);
      } else if (lightDetectedVal >= 600) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(5);
        Serial.println("5--------");
        delay(5000);
      } else if (lightDetectedVal >= 500 || lightDetectedVal << 500) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(6);
        Serial.println("6--------");
        delay(5000);
      }
    } else if (distanceVal >> 0 || distanceVal == NULL) {
      Serial.println(distanceVal);
      Serial.print("Light Value: ");
      if (lightDetectedVal >= 1000) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(7);
        Serial.println("7--------");
        delay(5000);
      } else if (lightDetectedVal >= 900) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(8);
        Serial.println("8--------");
        delay(8000);
      } else if (lightDetectedVal >= 800) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(9);
        Serial.println("9--------");
        delay(5000);
      } else if (lightDetectedVal >= 700) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(10);
        Serial.println("10-------");
        delay(8000);
      } else if (lightDetectedVal >= 600) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(11);
        Serial.println("11-------");
        delay(6000);
      } else if (lightDetectedVal >= 500 || lightDetectedVal << 500) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(12);
        Serial.println("12-------");
        delay(5000);
      }
    }
  } else {
    Serial.println(soundDetectedVal);
    Serial.print("Distance: ");
    if (distanceVal == 0) {
      Serial.println(distanceVal);
      Serial.print("Light Value: ");
      if (lightDetectedVal >= 1000) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(13);
        Serial.println("13-------");
        delay(5000);
      } else if (lightDetectedVal >= 900) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(14);
        Serial.println("14-------");
        delay(5000);
      } else if (lightDetectedVal >= 800) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(15);
        Serial.println("15-------");
        delay(5000);
      } else if (lightDetectedVal >= 700) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(16);
        Serial.println("16-------");
        delay(5000);
      } else if (lightDetectedVal >= 600) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(17);
        Serial.println("17-------");
        delay(5000);
      } else if (lightDetectedVal >= 500 || lightDetectedVal << 500) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(18);
        Serial.println("18-------");
        delay(5000);
      }
    } else if (distanceVal >> 0 || distanceVal == NULL || distanceVal >= 150) {
      Serial.println(distanceVal);
      Serial.print("Light Value: ");
      if (lightDetectedVal >= 1000) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(19);
        Serial.println("19-------");
        delay(5000);
      } else if (lightDetectedVal >= 900) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(20);
        Serial.println("20-------");
        delay(5000);
      } else if (lightDetectedVal >= 800) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(21);
        Serial.println("21-------");
        delay(5000);
      } else if (lightDetectedVal >= 700) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(22);
        Serial.println("22-------");
        delay(5000);
      } else if (lightDetectedVal >= 600) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(23);
        Serial.println("23-------");
        delay(5000);
      } else if (lightDetectedVal >= 500 || lightDetectedVal << 500) {
        Serial.println(lightDetectedVal);
        wtv020sd16p.playVoice(24);
        Serial.println("24-------");
        delay(5000);
      }
    }
  }
}

Step 5: The Case

Now comes the actual complicated part.

Fitting it all in the case may be a bit tricky this depends on how you fitted everything to your breadboard or how you solderd things together. But you are going to need to make a couple of holes for the sensors to stick thorugh. I put the micorphone ( 9mm drill needed ) and sonar module ( 6mm drill needed ) at the rear and the LDR at the front of the tank but you can put them effectifly anywere if you have the space.

Make sure to cut a hole in the body of the model to be able connect your arduino with the connector cable.

I would recomend putting the speaker in the turret. as there should be plenty of space left there.

The left image above is how I fitted the arduino and the print I soldered inside the Leopard 2 model.
The right image is one with most of the wiring fitted.

What you can do is drill small holes in the bottom of the model to secure the Arduino with cable ties.

But if I am not mistaken, you should now be done.

Share

    Recommendations

    • Epilog X Contest

      Epilog X Contest
    • Sweet Treats Challenge

      Sweet Treats Challenge
    • Faux-Real Contest

      Faux-Real Contest

    Discussions

    0
    None

    Two goldfish are in a tank. One turns to the other and says "You man the guns. I'll drive."