How to Make a Robot at Home (with Pictures)

Table of contents:

How to Make a Robot at Home (with Pictures)
How to Make a Robot at Home (with Pictures)

Video: How to Make a Robot at Home (with Pictures)

Video: How to Make a Robot at Home (with Pictures)
Video: 19 Ridiculous Ways to Use Map Art in Minecraft 2024, November
Anonim

Do you want to learn how to make your own robot? There are many different types of robots, which you can build yourself. Most people want to see a robot do the easy job of moving from point A to B. You can build a robot completely from analog components or buy a starter kit. Making your own robot is a great way to learn electronics and computer programming.

Step

Part 1 of 5: Assembling the Robot

1123333 1
1123333 1

Step 1. Assemble your components

To build a basic robot, you'll need a few simple components. You can find most or all of these components at your local electronics hobby store, or at some online retailers. Some kits include all of these components. This robot does not require any soldering:

  • Arduino Uno (or other microcontroller)
  • 2 servos 360 degree
  • 2 wheels matching servo
  • 1 free wheel
  • 1 test board (breadboard or project board) that has not been soldered (look for a test board that has two positive and negative rows on each side)
  • 1 proximity sensor (with four pin connector cable)
  • 1 push button switch
  • 1 resistor 10kΩ
  • 1 USB A to B cable
  • 1 set of breakable headers
  • 1 6 x AA battery holder with 9V DC. power socket
  • 1 pack of 22. jumper cables or single cable
  • Insulation back and forth (double tape) or glue gun
1123333 2
1123333 2

Step 2. Turn the battery compartment so that its flat back is facing up

You will build the robot body using the battery compartment as the base.

1123333 3
1123333 3

Step 3. Arrange two servos facing the same direction at the end of the battery bay

This end is the end where the cable comes out of the battery. The servos should touch the bottom, and the rotation mechanism of each servo should be facing out from the sides of the battery compartment. It is important that these servos are arranged correctly so that the wheels are straight. The cables for the servo must come out of the back of the battery compartment.

1123333 4
1123333 4

Step 4. Glue the servos with your insulation or glue

Make sure that the servo is firmly attached to the battery compartment. The back of the servo must be aligned with the back of the battery compartment.

Now, the servos should take up half the space in the back of the battery bay

1123333 5
1123333 5

Step 5. Adhere the test board perpendicular to the remaining space in the battery compartment

This test board will hang slightly over the front of the battery compartment, and will extend to both sides. Make sure that the test board is tight before proceeding. The “A” row should be closest to the servo.

1123333 6
1123333 6

Step 6. Attach the Arduino microcontroller to the top of the servo

If you attach the servo correctly, there should be a flat part of the two servos touching each other. Adhere the Arduino board to this flat spot so that the USB and Arduino power connectors are facing down (away from the test board). The front of the Arduino will overlap with the test board.

1123333 7
1123333 7

Step 7. Install the wheels on the servos

Firmly press the wheels onto the rotating servo mechanism. This may require considerable force as the wheels are designed to have holes that exactly match the shape of the servo tip.

1123333 8
1123333 8

Step 8. Install the free wheel on the bottom of the test board

If you turn the robot upside down, you'll see a little test board hanging from the battery compartment. Attach the free wheel to this hanging part. Use a wedge if needed. The free wheel serves as the front wheel which allows the robot to turn in any direction with ease.

If you purchased a kit, the free wheel may have some wedges you can use to ensure that the wheel is free to touch the ground

Part 2 of 5: Wiring the Robot

1123333 9
1123333 9

Step 1. Cut two 3-pin headers

You will use this to connect the servo to the test board. Push the pins down through the headers, so they come out an equal distance on both sides.

1123333 10
1123333 10

Step 2. Insert the two headers into pins 1-3 and 6-8 in row E on the test board

Make sure they are inserted firmly or firmly.

1123333 11
1123333 11

Step 3. Connect the servo wires with the header, with the black wire on the left side (pins 1 and 6)

This will connect the servo with the test board. Make sure the left servo is connected to the left header, and the right servo is connected to the right header.

1123333 12
1123333 12

Step 4. Connect the red jumper wire from pins C2 and C7 to the red rail pin (positive)

Make sure you use the red rail on the back of the test board (closer to the rest of the robot body).

1123333 13
1123333 13

Step 5. Connect the black jumper wire from pins B1 and B6 to the blue rail pin (ground)

Make sure you use the blue rail on the back of the test board. Do not attach the cable to the red rail pin.

1123333 14
1123333 14

Step 6. Connect the white jumper wires from pins 12 and 13 on the Arduino to A3 and A8

This will allow the Arduino to control the servo and turn the wheel.

1123333 15
1123333 15

Step 7. Attach the sensor to the front of the test board

The sensor is not mounted to the external power rail on the test board, but to the first two rows of pins lettered (J). Make sure you place it right in the middle with an equal number of empty pins on each side.

1123333 16
1123333 16

Step 8. Connect the black jumper wire from pin I14 to the first blue rail pin on the left of the sensor

This will ground the sensor.

1123333 17
1123333 17

Step 9. Connect the red jumper wire from pin I17 to the first red rail pin on the right of the sensor

This will provide power to the sensor.

1123333 18
1123333 18

Step 10. Connect the white jumper wires from pin I15 to pin 9 on Arduino, and from I16 to pin 8

This will provide information from the sensor to the microcontroller.

Part 3 of 5: Installing the Power Cable

1123333 19
1123333 19

Step 1. Turn the robot over so you can see the battery compartment inside

Arrange the battery compartment so that the cable exits through the bottom left.

1123333 20
1123333 20

Step 2. Connect the red wire with the second spring from the left at the bottom

Make sure that the battery compartment is aligned correctly or is facing the correct direction.

1123333 21
1123333 21

Step 3. Connect the black wire with the last spring on the bottom right

These two wires will help provide proper voltage to the Arduino.

1123333 22
1123333 22

Step 4. Connect the red and black wires to the red and blue pins that are on the right side on the back of the test board

The black wire should go to the blue rail pin on pin 30. The red wire should go to the red rail pin on pin 30.

1123333 23
1123333 23

Step 5. Connect the black wire from the GND pin on the Arduino to the back of the blue rail

Connect the wire to pin 28 on the blue rail.

1123333 24
1123333 24

Step 6. Connect the black wire from the back of the blue rail to the front of the blue rail on pin 29 for both rails

Do not connect the red rail as you may damage the Arduino.

1123333 25
1123333 25

Step 7. Connect the red wire from the front of the red rail on pin 30 to the 5V pin on Arduino

This will provide power to the Arduino.

1123333 26
1123333 26

Step 8. Insert the pushbutton switch in the space between pins 24-26

This switch will allow you to turn off the robot without having to turn off the power.

1123333 27
1123333 27

Step 9. Connect the red wire from H24 to the red rail on the next empty pin to the right of the sensor

This will provide power to the button.

1123333 28
1123333 28

Step 10. Use a resistor to connect H26 to the blue rail

Connect it to the pin directly next to the black wire you just connected in the previous steps.

1123333 29
1123333 29

Step 11. Connect the white wire from G26 to pin 2 on Arduino

This will allow Arduino to detect pushbuttons.

Part 4 of 5: Installing the Arduino Software

1123333 30
1123333 30

Step 1. Download and extract Arduino IDE

This is where Arduino is developed and allows you to program instructions which you can then upload to your Arduino microcontroller. You can download it for free from arduino.cc/en/main/software. Unzip the downloaded file by double-clicking on the file and moving the folder it contains to an easy-to-access location. You won't actually install the program, instead you'll just run it from the folder that was extracted by double-clicking on arduino.exe.

1123333 31
1123333 31

Step 2. Connect the battery compartment to the Arduino

Insert the back socket of the battery into the connector on the Arduino to power it.

1123333 32
1123333 32

Step 3. Insert Arduino into your computer via USB

Chances are, Windows won't recognize the device.

1123333 33
1123333 33

Step 4. Press

Win+R and type devmgmt.msc.

This command will open the Device Manager.

1123333 34
1123333 34

Step 5. Right-click on Unknown device under Other devices and select Update Driver Software

If you don't see this option, click Properties, select the Driver tab, and then click Update Driver.

1123333 35
1123333 35

Step 6. Select Browse my computer for driver software

This will allow you to select the built-in drivers that came with the Arduino IDE.

1123333 36
1123333 36

Step 7. Click Browse, then open the folder you extracted earlier

You will find the drivers folder in it.

1123333 37
1123333 37

Step 8. Select the drivers folder and click OK

Confirm that you want to continue if you are warned about unknown software.

Part 5 of 5: Programming Robots

1123333 38
1123333 38

Step 1. Open ARDUINO IDE by double-clicking on the arduino.exe file in the IDE folder

You will be greeted with a blank project.

1123333 39
1123333 39

Step 2. Paste or paste the following code to make your robot advanced

The code below will keep your Arduino going.

#include // this adds the “Servo” library to the program // the following command creates two servo objects Servo leftMotor; Servo rightMotor; void setup() { leftMotor.attach(12); // if you accidentally swapped the pin numbers for your servo, you can swap the numbers here rightMotor.attach(13); } void loop() { leftMotor.write(180); // with 360 degree rotation (continuous rotation), the number 180 instructs the servo to move “forward” at full speed. rightMotor.write(0); // if both values are 180, the robot will rotate in a circle because the servo is reversed. “0” tells the robot to move “backwards” at full speed. }

1123333 40
1123333 40

Step 3. Create and upload the program

Click the right arrow button in the top left corner to create and upload a program to the connected Arduino.

You may want to lift the robot off the surface as the robot will continue to walk forward after the program is uploaded

1123333 41
1123333 41

Step 4. Add a stop switch function (kill switch)

Add the following code to the "void loop()" section of your code to add a stop switch function on top of the "write()" function.

if(digitalRead(2) == HIGH) // this command runs when the button is pressed on pin 2 Arduino { while(1) { leftMotor.write(90); // "90" is the neutral position for the servo, which tells the servo to stop turning rightMotor.write(90); } }

1123333 42
1123333 42

Step 5. Upload and check your code

With the stop switch code already added, you can upload the code and test the robot. The robot should continue forward until you press the stop switch button which will cause the robot to stop. The full code will look like this:

#include // the following command creates two Servo leftMotor servo objects; Servo rightMotor; void setup() { leftMotor.attach(12); rightMotor.attach(13); } void loop() { if(digitalRead(2) == HIGH) { while(1) { leftMotor.write(90); rightMotor.write(90); } } leftMotor.write(180); rightMotor.write(0); }

Example

The following code will use sensors installed on the robot to make it turn left whenever the robot encounters an obstacle. Look at the comments in the code for details on how to use each part. The code below is the whole program.

#include Servo leftMotor; Servo rightMotor; const int serialPeriod = 250; // this code gives the console output time lag to be every 1/4 second (250 ms) unsigned long timeSerialDelay = 0; const int loopPeriod = 20; // this code sets the sensor reading frequency to 20 ms, which is 50 Hz unsigned long timeLoopDelay = 0; // this code assigns the TRIG and ECHO functions to the pins on the Arduino. Adjust the numbers here if you connect them in a different way const int ultrasonic2TrigPin = 8; const int ultrasonic2EchoPin = 9; int ultrasonic2Distance; int ultrasonic2Duration; // this code defines two possible robot states: continue forward or turn left #define DRIVE_FORWARD 0 #define TURN_LEFT 1 int state = DRIVE_FORWARD; // 0 = continue forward (DEFAULT), 1 = turn left void setup() { Serial.begin(9600); // this sensor determines the pin configuration pinMode(ultrasonic2TrigPin, OUTPUT); pinMode(ultrasonic2EchoPin, INPUT); // this assigns the motor to the Arduino pins leftMotor.attach(12); rightMotor.attach(13); } void loop() { if(digitalRead(2) == HIGH) // this code detects a ''stop'' { while(1) { leftMotor.write(90); rightMotor.write(90); } } debugOutput(); // this code prints debug messages to serial console if(millis() - timeLoopDelay >= loopPeriod) { readUltrasonicSensors(); // this code instructs the sensor to read and store data about the measured distance stateMachine(); timeLoopDelay = millis(); } } void stateMachine() { if(state == DRIVE_FORWARD) // if no obstacle is detected { if(ultrasonic2Distance > 6 || ultrasonic2Distance < 0) // if nothing is in front of the robot. ultrasonicDistance will be negative for some ultrasonics if there are no obstacles { // drive forward rightMotor.write(180); leftMotor.write(0); } else // if there is an object in front of us { state = TURN_LEFT; } } else if(state == TURN_LEFT) // if an obstacle is detected, turn left { unsigned long timeToTurnLeft = 500; // takes about 0.5 seconds to turn 90 degrees. You may need to adjust this value if your wheels differ in size from the size in the example unsigned long turnStartTime = millis(); // save the state when the robot starts to turn while((millis()-turnStartTime) < timeToTurnLeft) // keep this cycle until timeToTurnLeft (500) has passed { // turn left, remember that when both are "180", the robot will turn. rightMotor.write(180); leftMotor.write(180); } state = DRIVE_FORWARD; } } void readUltrasonicSensors() { // this is for ultrasonic 2. You may need to change this command if you are using a different sensor. digitalWrite(ultrasonic2TrigPin, HIGH); delayMicroseconds(10); // pull the TRIG pin high for at least 10 microseconds digitalWrite(ultrasonic2TrigPin, LOW); ultrasonic2Duration = pulseIn(ultrasonic2EchoPin, HIGH); ultrasonic2Distance = (ultrasonic2Duration/2)/29; } // the following is for debugging errors in the console. void debugOutput() { if((millis() - timeSerialDelay) > serialPeriod) { Serial.print("ultrasonic2Distance: "); Serial.print(ultrasonic2Distance); Serial.print("cm"); Serial.println(); timeSerialDelay = millis(); } }

Recommended: