loading

Hello.

I want to show you how you can build a robot with an Arduino and a few other parts. So what do we need?

  • Arduino. I have leonardo but it's not important
  • H bridge TB6612FNG or other
  • chassis for robot for example DAGU DG012-SV or hand-made
  • ultrasonic sensor
  • servo
  • 2 blue leds
  • buzzer
  • photoresistor
  • resistor 1,2 k Ω
  • breadboard
  • cables, tape, screws, batteries

Step 1: Build Chassis

If you are doing the chassis remember about motors. It's must have sufficient power to move your robot.

If you bought chassis you must submit it.

Now it's time to put batteries. I use box for 5 AA batteries but if you have larger motors you need more batteries.

Step 2: Connect All Things

If you have TB6612FNG H bridge you can connect it's to arduino as below if not you need slightly change it.

For connect it I use 170 holes breadboard because this breadboard it small and can be located on the arduino.

1. Ultrasonic sensor:

-Trig--> 2 pin Arduino

-Echo--> 1 pin Arduino

-VCC --> 5V Arduino

-GND --> GND Arduino

2. Servo:

-GND --> GND Arduino
-VCC --> 5V Arduino
-Data--> 9 pin Arduino

3.H bridge:

-all mass (GND) to mass in Arduino
-VCC -->5V Arduino
-A01 --> motor1 mass(-)
-A02 --> motor1 power(+)
-B02 --> motor2 mass(-)

-B01 --> motor2 mass(-)

-VMOT--> VIN Arduino

-PWMA--> 6 pin Arduino

-AIN1 --> 8 pin Arduino
-AIN2 --> 7 pin Arduino
-BIN2 --> 4 pin Arduino
-BIN1 --> 3 pin Arduino
-PWMB--> 5 pin Arduino

4.Buzzer:

-GND(-) --> GND Arduino

-VCC(+)--> 11 pin Arduino

5. Leds:

-Both VCC (+) from leds to 10 pin Arduino

-Both GND(-) from leds to GND Arduino

Long cables tied a piece of wire.

6.Photoresistor:

On image you can see how it's connect. Resistor have 1,2 k Ω

Step 3: Insert All Things

Now you must insert all things on chassis. I use 4 screws M3 to screws Arduino and chassis, between Arduino and chassis I gave a piece of straw. Breadboard located on arduino. I glued Ultrasonic sensor with double sided tape to servo and servo to chassis with black tape. Leds is on ultrasonic sensor on tape. Cables from leds and ping sensor need enough space because it moves.

Step 4: Program 1

Robot with this program after watch obstacles go back watch on left and right and drive to this site where it has more space and when it back make sound. When is dark leds turn on when is brightly leds turn off. Below I added the code, in the comments is an explanation of the code. After loading this code you can start robot.

Step 5: Program 2

Robot with this program can ride in maze. Construction it's the same only code is slightly other.

Step 6: Start Robot

Now you can start your robot. Below i added films with my robot. First one is test, second one is complete robot with first and second program.

If you come from Poland this is my website with instruction is in polish:

http://www.arduinopolska.cba.pl/

<p>گروه تولیدی بازرگانی ال ای دی پانل با دارا بودن سابقه درخشان در زمینه<br>واردات از کشور های مختلف و نیز تولید انواع تابلو روان و &lt;a href=&quot;http://www.ledpanelco.com/&quot;&gt;تلویزیون<br>شهری&lt;/a&gt;تبلیغاتی ، با به کاری<br>گیری نیروی متعهد و متخصص با هدف ارائه خدمات بازرگانی و تولیدی فعالیت می نماید که<br>واحد بازرگانی ال ای دی پانل با دارا بودن<br>شرکای تجاری معتبر در کشورهای چین ، تایوان و کره جنوبی اقدام به واردات کالاهای الکترونیکی من جمله <br>قطعات تابلو روان ، &lt;a href=&quot;http://www.ledpanelco.com/&quot;&gt;قطعات<br>تلویزیون شهری&lt;/a&gt;و تجهیزات نور پردازی با بهترین<br>کیفیت و مناسب ترین قیمت مینماید و نیز واحد تولید ال ای دی پانل فعالیت خود را در زمینه ساخت و تولید<br>انواع تابلو روان و نمایشگر شهری LED با مشخصات مختلف<br>و نیز تولید انواع قاب تابلو روان ، کابینت تابلو روان led و کابینت &lt;a href=&quot;http://www.ledpanelco.com/&quot;&gt;تلویزیون<br>شهری&lt;/a&gt;می نماید.</p>
<p>great project and the code is perfectly working</p>
<p>Is there any mistake in the code it is written as</p><p> if(light&gt;850)</p><p> {</p><p> digitalWrite(8, HIGH);</p><p> }</p>
Yes, you need to add this:<br><br> light= &nbsp;analogRead(A0);<br>&nbsp; if(light&gt;850){<br>&nbsp; &nbsp; digitalWrite(10, HIGH);<br>&nbsp; }<br>&nbsp; else{<br>&nbsp; &nbsp; digitalWrite(10, LOW);<br>&nbsp; }<br>}<br><br>Write when you are done.
<p>Hey what is the keyword czas;</p>
Czas is time in polish language<br> :-) sory for the confusion. Lights work?
No the lights are still not working. And after using your program robot is stopping after every two to three seconds and scanning and moving and stopping for again two to three seconds and is not moving like you have shown in your video. And sorry for disturbing you on your holiday.
No problem, I'm curious why this is not working. Robot on my movie stops at 70 milliseconds because when engines works is not enough energy for ultrasonic sensor. Mayby you have the same problem. Below I add code I hope it's good. <br><br><br><br>//define trig and echo for ultrasonic sensor<br>#define trig 2<br>#define echo 1<br>//add library<br>#include &nbsp;<br>&nbsp;<br>&nbsp;//Servo definition<br>Servo myservo; &nbsp;<br>//Pin definition for H bridge<br>int pwmMotorA=6;<br>int pwmMotorB=5;<br>int ForwardA=8;<br>int BackA=7;<br>int ForwardB=3;<br>int BackB=4;<br>&nbsp;<br>/*ultrasonic sensor<br>dist1-left scan<br>dist2-roward scan<br>dist3-right scan<br>*/<br>int czas, dist2, dist1, dist3, light;<br>&nbsp;<br>void setup() { &nbsp; &nbsp;<br>&nbsp; //servo definition<br>&nbsp; myservo.attach(9);<br>&nbsp; //buzzer<br>&nbsp; pinMode(11, OUTPUT);<br>&nbsp; //photoresistor<br>&nbsp; pinMode(A0, INPUT);<br>&nbsp;&nbsp;<br>&nbsp; //leds<br>&nbsp; pinMode(10, OUTPUT);<br>&nbsp;&nbsp;<br>&nbsp; //ultrasonic sensor<br>&nbsp; pinMode(trig, OUTPUT);<br>&nbsp; pinMode(echo, INPUT); &nbsp;&nbsp;<br>&nbsp;&nbsp;<br>&nbsp; //PWM motor A<br>&nbsp; pinMode(pwmMotorA, OUTPUT);&nbsp;<br>&nbsp;&nbsp;<br>&nbsp;// Motor A move back<br>&nbsp; pinMode(ForwardA, OUTPUT);&nbsp;<br>// Motor A move back<br>&nbsp; pinMode(BackA, OUTPUT); &nbsp;&nbsp;<br>&nbsp;&nbsp;<br>&nbsp; //PWM motor B<br>&nbsp; pinMode(pwmMotorB, OUTPUT);<br>&nbsp;&nbsp;<br>&nbsp; // Motor B move forward<br>&nbsp; pinMode(ForwardB, OUTPUT);&nbsp;<br>&nbsp; // Motor B move back<br>&nbsp; pinMode(BackB, OUTPUT);&nbsp;<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;<br>&nbsp; //motors speed&nbsp;<br>&nbsp; analogWrite(pwmMotorA, 255);<br>&nbsp; analogWrite(pwmMotorB, 255);<br>&nbsp;<br>}<br>//robot turn left<br>void Left(){<br>&nbsp; digitalWrite(ForwardA, LOW);&nbsp;<br>&nbsp; digitalWrite(BackA, HIGH);<br>&nbsp;&nbsp;<br>&nbsp; //Ustawienie kierunku obrot&oacute;w B<br>&nbsp; digitalWrite(ForwardB, HIGH);&nbsp;<br>&nbsp; digitalWrite(BackB, LOW);<br>&nbsp; delay(1000);<br>}<br>&nbsp;<br>//robot turn right<br>void Right(){<br>&nbsp;&nbsp;<br>&nbsp; digitalWrite(ForwardA, HIGH);&nbsp;<br>&nbsp; digitalWrite(BackA, LOW);<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;<br>&nbsp; digitalWrite(ForwardB, LOW);&nbsp;<br>&nbsp; digitalWrite(BackB, HIGH);<br>&nbsp;&nbsp;<br>&nbsp; delay(1000);<br>}<br>&nbsp;<br>//robot move forward<br>void Forward(){<br>&nbsp;&nbsp;<br>&nbsp; digitalWrite(ForwardA, HIGH);&nbsp;<br>&nbsp; digitalWrite(BackA, LOW);<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;<br>&nbsp; digitalWrite(ForwardB, HIGH);&nbsp;<br>&nbsp; digitalWrite(BackB, LOW);<br>}<br>&nbsp;<br>//robot move back<br>void Back(){<br>&nbsp; digitalWrite(ForwardA, LOW);&nbsp;<br>&nbsp; digitalWrite(BackA, HIGH);<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;<br>&nbsp; digitalWrite(ForwardB, LOW);&nbsp;<br>&nbsp; digitalWrite(BackB, HIGH);<br>&nbsp;&nbsp;<br>}<br>&nbsp;<br>//ultrasonic sensor scan forward<br>void ScanForward(){<br>&nbsp;&nbsp;<br>&nbsp; delay(50);<br>&nbsp; &nbsp; digitalWrite(trig, HIGH);<br>&nbsp; &nbsp; delayMicroseconds(1000);<br>&nbsp; &nbsp; digitalWrite(trig, LOW);<br>&nbsp; &nbsp; czas = pulseIn(echo, HIGH);<br>&nbsp; &nbsp; dist2 = (czas/2) /29.1;<br>}<br>&nbsp;<br>//ultrasonic sensor scan left&nbsp;<br>void ScanLeft(){<br>&nbsp; myservo.write(160);<br>&nbsp; delay(1000);<br>&nbsp; delay(50);<br>&nbsp; &nbsp; digitalWrite(trig, HIGH);<br>&nbsp; &nbsp; delayMicroseconds(1000);<br>&nbsp; &nbsp; digitalWrite(trig, LOW);<br>&nbsp; &nbsp; czas = pulseIn(echo, HIGH);<br>&nbsp; &nbsp; dist1 = (czas/2) /29.1;<br>}<br>&nbsp;<br>//stop robot<br>void Stop(){<br>&nbsp;&nbsp;<br>&nbsp; digitalWrite(ForwardA, LOW);&nbsp;<br>&nbsp; digitalWrite(BackA, LOW);<br>&nbsp;&nbsp;<br>&nbsp; <br>&nbsp; digitalWrite(ForwardB, LOW);&nbsp;<br>&nbsp; digitalWrite(BackB, LOW);<br>}<br>&nbsp;<br>//ultrasonic sensor scan right<br>void ScanRight(){<br>&nbsp; myservo.write(20);<br>&nbsp; delay(1000);<br>&nbsp; delay(50);<br>&nbsp; &nbsp; digitalWrite(trig, HIGH);<br>&nbsp; &nbsp; delayMicroseconds(1000);<br>&nbsp; &nbsp; digitalWrite(trig, LOW);<br>&nbsp; &nbsp; czas = pulseIn(echo, HIGH);<br>&nbsp; &nbsp; dist3 = (czas/2) /29.1;<br>}<br>//led and photoresistor<br>void Led(){<br>&nbsp; light= &nbsp;analogRead(A0);<br>&nbsp; if(light&gt;850){<br>&nbsp; &nbsp; digitalWrite(10, HIGH);<br>&nbsp; }<br>&nbsp; else{<br>&nbsp; &nbsp; digitalWrite(10, LOW);<br>&nbsp; }<br>}<br>&nbsp;<br>void loop() {<br>&nbsp; Led();<br>&nbsp; Stop();<br>&nbsp; delay(20);<br>&nbsp; ScanForward();<br>&nbsp;<br>&nbsp; if(dist2&lt;=17){<br>&nbsp; &nbsp; //buzzer on<br>&nbsp; &nbsp; digitalWrite(11, HIGH);<br>&nbsp; &nbsp; Back();<br>&nbsp;delay(1000);<br>&nbsp;//buzzer off<br>&nbsp; &nbsp; digitalWrite(11, LOW);<br>&nbsp; &nbsp; Stop();<br>&nbsp; &nbsp; ScanRight();<br>&nbsp; &nbsp; ScanLeft();<br>&nbsp; &nbsp; myservo.write(90);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; if(dist1&gt;=dist3){<br>&nbsp;<br>&nbsp;Right();<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; else{<br>&nbsp; &nbsp; &nbsp; Left();<br>&nbsp; }<br>&nbsp; }<br>&nbsp; else{<br>&nbsp; &nbsp; Forward();<br>&nbsp; &nbsp; delay(400);<br>&nbsp; }<br>}
<p>Well I am actually using the same program. Well what ohm resistor we should use I think I am using 4K ohm resistor. Is it necessary to use a resistor?</p>
Yes but resistor must have 1,2k ohm
<p>I am also trying to make it but there is some error occurring. The Robot is not moving and the lights are on every time</p>
Mayby you have other H bridge or you have wrong connected. On fritzing image I wtong I'am sory. 5V change with mass and mass change with resistor. I hope you understand. You can write an e-mail if you want on nikodem.bartnik@gmail.com. Now I'm on holiday, I haven't Arduino and computer with software but if you have more problem ask me I'll try to help you.
<p>Hey the motor problem is solved but the led problem is still there. Is there any problem in program. </p>
<p>Hey how much did it cost you.</p>
<p>Hey!</p><p>All parts including arduino costs 100$ but i bought all things in Poland.</p>
<p>I love the title for this. Good luck in the Sensors Contest. </p>
<p>Thank you :)</p>
Hey Nikus what inspired u to make this robot and y did u make this robot??
<p>Hey.</p><p>I have arduino from month and I wanted to make robot so I bought chassis, ping sensor and some other parts needed and I did a robot. It's simple :)</p>

About This Instructable

11,228views

83favorites

License:

Bio: Hi, my name is Nikodem. I live in Poland, I'm 17 years old. I like to program and create robots, devices and things. In ... More »
More by Nikus:Live Instructables Followers Counter Arduino Drone | Quadcopter (3D Printed) Cheap 3D scanner 
Add instructable to: