Ardutank v1.1

0

 

Ardutank is an obstacle avoiding robot, it will rotate if it detected a 10CM object in front of it. Below is the required hardware to develop it:

  • Arduino Uno development board
  • SR04 ultrasonic sensor
  • L298 motor driver
  • Tamiya twin motor gearbox
  • Tamiya truck and wheel set
  • Acrylic sheet
  • Jumper
  • 2600mah power bank

Code

	/*
 * created by BlvckJvck
 * 
 * Ardutank v1.0
 *
    Ultrasonic sensor Pins:
        VCC: +5VDC
        Trig : Trigger (INPUT) - Pin11
        Echo: Echo (OUTPUT) - Pin 12
        GND: GND
 */
 //L293D
//Motor A
const int motorPin1  = 9;  // Pin 14 of L293
const int motorPin2  = 10;  // Pin 10 of L293
//Motor B
const int motorPin3  = 6; // Pin  7 of L293
const int motorPin4  = 5;  // Pin  2 of L293
int trigPin = 11;    //Trig - green Jumper
int echoPin = 12;    //Echo - yellow Jumper
long duration, cm, inches;
 
void setup() {
  //Serial Port begin
  Serial.begin (9600);
  //Define inputs and outputs
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);
}
 
void loop()
{
 
 
  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
 
  // convert the time into a distance
  cm = (duration/2) / 29.1;
  inches = (duration/2) / 74; 
  
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  
  delay(250);

if(cm < 10 ){
  
  Serial.print("below 5 \n");
  analogWrite(motorPin2, 0);
  analogWrite(motorPin4, 0);
  
  analogWrite(motorPin2, 250);
  
  }else{
        analogWrite(motorPin2, 250);
    analogWrite(motorPin4, 250);
    //analogWrite(motorPin2, 180);
    //analogWrite(motorPin3, 180);
    //analogWrite(motorPin4, 180);

    }
  
}
  
	

 

Previous articleHackafruit
Next articlePortable Fabrication Machine (Etching)
Life but a walking shadow, love to explore everything that related to hardware and system, Keep living the impossible and just want to keep moving and improving.
SHARE

LEAVE A REPLY

Please enter your comment!
Please enter your name here