Yun_Visser_ITTT_Robot_car

Introduction: Yun_Visser_ITTT_Robot_car

In deze Instructable zal ik je begeleiden bij het maken van een robot auto.

Supplies:

See step 1.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Collect Supplies

Robot onderdelen:

2 x DC 3V-6V reductiemotoren

2 x Wiel 65 x 26 mm

1 x Zwenkwiel

21* x Flexibele jumper Draden

1 x Servo SG90

1 x houder voor servomotor en sonar

1 x Acrylplaat

1 x USB kabel

1 x Arduino UNO R3

1 x L289N motor driver module H-Bridge

1 x Sonar

1 x Batterijhouder met 6 cellen (AA)

6 x AA batterijen

20* x Schroeven en moeren verschillend formaat

*minimaal aantal

Materiaal en gereedschap:

-Soldeerstation met houder en soldeerbout 220-240V/48W

-Tin 60% en lood 40%

-Soldeerboutreiniger vergulde krullen

-Desoldeerlint

-Desoldeerpomp

-Multimeter

-Schroevendraaier

-Afstriptang

-Tang

Step 2: Assembling

Een robot auto maken door gaten in de plaat te zagen voor de schroeven.

De DC 3V-6V reductiemotoren vastmaken aan de plaat en de wielen erop doen.

L289N motor driver module H-Bridge op de plaat vastschroeven.

SG90 Mini Analog servo op de plaat schroeven.

Sonar die obstakels herkent op de plaat schroeven.

Batterij houder waar zes AA’tjes in kunnen vastmaken met plakband.

Draden om de onderdelen aan elkaar te verbinden met plakband.

Een Arduino UNO R3 waar ik de kabels kan verbinden met de andere onderdelen op de plaat monteren.

Zie stap 3 voor de verbindingen van de draden.

Step 3: Software

// library servo
#include

//Define servo Pin #define servoPin 2

// Pins #define TRIG_PIN 8 #define ECHO_PIN A0

//Define all the connections maps to the L298N #define enA 11 #define in1 12 #define in2 13 #define in3 7 #define in4 6 #define enB 5

class Motor{

int enablePin; int directionPin1; int directionPin2;

public:

//Method to define the motor pins Motor(int ENPin,int dPin1,int dPin2){ enablePin = ENPin; directionPin1 = dPin1; directionPin2 = dPin2; };

//Method to drive the motor 0~255 driving forward. -1~-255 driving backward void Drive(int speed){ if(speed>=0){ digitalWrite(directionPin1, LOW); digitalWrite(directionPin2, HIGH); } else{ digitalWrite(directionPin1, HIGH); digitalWrite(directionPin2, LOW); speed = - speed; } analogWrite(enablePin, speed); } };

Motor leftMotor = Motor(enA, in1, in2); Motor rightMotor = Motor(enB, in3, in4);

Servo myservo; // create servo object to control a servo

void motorInitiation(){ pinMode(enA, OUTPUT); pinMode(in1, OUTPUT); pinMode(in2, OUTPUT); pinMode(enB, OUTPUT); pinMode(in3, OUTPUT); pinMode(in4, OUTPUT); // Set initial direction and speed digitalWrite(enA, LOW); digitalWrite(enB, LOW); digitalWrite(in1, LOW); digitalWrite(in2, HIGH); digitalWrite(in3, LOW); digitalWrite(in4, HIGH); }

//Variables-------------------------------------------------------------------------- // Anything over 400 cm (23200 us pulse) is "out of range" const unsigned int MAX_DIST = 23200; bool ObsticalAhead = false; int servoPos = 90;

enum Directions { Forward, TurnLeft, TurnRight, TurnAround,Brake};

Directions nextStep = Forward;

unsigned long t1; unsigned long t2; unsigned long pulse_width; float cm; float inches;

//SETUP-------------------------------------------------------------------------- void setup() {

// The Trigger pin will tell the sensor to range find pinMode(TRIG_PIN, OUTPUT); digitalWrite(TRIG_PIN, LOW);

// We'll use the serial monitor to view the sensor output Serial.begin(9600); myservo.attach(servoPin); motorInitiation(); Directions nextStep = Forward; }

void loop() {

checkDistance(); checkDirection(); drive(); }

void checkDistance(){

// Hold the trigger pin high for at least 10 us digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW);

// Wait for pulse on echo pin while ( digitalRead(ECHO_PIN) == 0 );

// Measure how long the echo pin was held high (pulse width) // Note: the micros() counter will overflow after ~70 min t1 = micros(); while ( digitalRead(ECHO_PIN) == 1); t2 = micros(); pulse_width = t2 - t1;

// Calculate distance in centimeters and inches. The constants // are found in the datasheet, and calculated from the assumed speed //of sound in air at sea level (~340 m/s). cm = pulse_width / 58.0; inches = pulse_width / 148.0;

// Print out results if ( pulse_width > MAX_DIST ) { //Serial.println("Out of range"); } else { //Serial.print(cm); //Serial.print(" cm \t"); //Serial.print(inches); //Serial.println(" in"); }

// Wait at least 60ms before next measurement delay(60);

if(cm<= 20){ ObsticalAhead = true; Serial.println("Problem Ahead");

} else{ ObsticalAhead = false;}

} void checkDirection(){ Serial.println("checking direction"); if(ObsticalAhead ==true){ nextStep = Brake; drive(); myservo.write(180); // tell servo to go to position in variable 'pos' delay(400); // waits 15ms for the servo to reach the position checkDistance(); if(ObsticalAhead ==false){//if left side is open nextStep = TurnLeft; Serial.println("Next step is TurnLeft"); myservo.write(90);//reset servo position delay(400); } else{// left is blocked, now need to look at right myservo.write(0); // tell servo to go to position in variable 'pos' delay(800); // waits 15ms for the servo to reach the position checkDistance(); if(ObsticalAhead ==false){//if right side is open nextStep = TurnRight; Serial.println("Next step is TurnRight"); myservo.write(90);//reset servo position delay(400); } else{//right is blocked as well, need to turn around nextStep = TurnAround; myservo.write(90);//reset servo position delay(300); Serial.println("Next step is TurnAround"); } }

} else{nextStep = Forward;}//No obstical ahead }

void drive(){ switch (nextStep){ case Forward: leftMotor.Drive(255); rightMotor.Drive(255); Serial.println("Forward");

break; case TurnLeft: leftMotor.Drive(-255); rightMotor.Drive(255); Serial.println(" TurnLeft"); delay(400);

break; case TurnRight: leftMotor.Drive(255); rightMotor.Drive(-255); Serial.println(" TurnRight"); delay(400); break; case TurnAround: leftMotor.Drive(255); rightMotor.Drive(-255); Serial.println(" TurnAround"); delay(600); break;

case Brake: leftMotor.Drive(0); rightMotor.Drive(0); Serial.println(" stopped"); } }

Download code link: https://github.com/YunVisser/VisserYun_ITTT_Robot_...

Step 4: Robot Car Protection and Decoration

1. In Adobe Illustrator de zijkanten, bovenkant voorkant en achterkant tekenen.

2. De tekening lasersnijder uit een MDF plaat 3 mm dik.

3. De uitgelaserde platen verstek zagen met een tafelcirkelzaag.

4. De platen aan elkaar vastplakken met plakband.

5. Aan de voorkant zit nog een openinging. Daar plak je een flexibel plastic ervoor met een klein snee erdoorheen, zodat de bedrading erdoorheen kan.

6. Versieren zoals jij dat wilt.

Be the First to Share

    Recommendations

    • Trash to Treasure Contest

      Trash to Treasure Contest
    • Rope & String Speed Challenge

      Rope & String Speed Challenge
    • Wearables Contest

      Wearables Contest

    Discussions