Introduction: Arduino: Sensitive Robot
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
- Robot Chassis 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.
Attachments
Step 5: Program 2
Robot with this program can ride in maze. Construction it's the same only code is slightly other.
Attachments
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.

Participated in the
Sensors Contest
18 Comments
5 years ago
گروه تولیدی بازرگانی ال ای دی پانل با دارا بودن سابقه درخشان در زمینه
واردات از کشور های مختلف و نیز تولید انواع تابلو روان و <a href="http://www.ledpanelco.com/">تلویزیون
شهری</a>تبلیغاتی ، با به کاری
گیری نیروی متعهد و متخصص با هدف ارائه خدمات بازرگانی و تولیدی فعالیت می نماید که
واحد بازرگانی ال ای دی پانل با دارا بودن
شرکای تجاری معتبر در کشورهای چین ، تایوان و کره جنوبی اقدام به واردات کالاهای الکترونیکی من جمله
قطعات تابلو روان ، <a href="http://www.ledpanelco.com/">قطعات
تلویزیون شهری</a>و تجهیزات نور پردازی با بهترین
کیفیت و مناسب ترین قیمت مینماید و نیز واحد تولید ال ای دی پانل فعالیت خود را در زمینه ساخت و تولید
انواع تابلو روان و نمایشگر شهری LED با مشخصات مختلف
و نیز تولید انواع قاب تابلو روان ، کابینت تابلو روان led و کابینت <a href="http://www.ledpanelco.com/">تلویزیون
شهری</a>می نماید.
8 years ago on Introduction
Is there any mistake in the code it is written as
if(light>850)
{
digitalWrite(8, HIGH);
}
Reply 8 years ago
Yes, you need to add this:
light= analogRead(A0);
if(light>850){
digitalWrite(10, HIGH);
}
else{
digitalWrite(10, LOW);
}
}
Write when you are done.
Reply 8 years ago on Introduction
Hey what is the keyword czas;
Reply 8 years ago
Czas is time in polish language
:-) sory for the confusion. Lights work?
Reply 8 years ago
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.
Reply 8 years ago
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.
//define trig and echo for ultrasonic sensor
#define trig 2
#define echo 1
//add library
#include
//Servo definition
Servo myservo;
//Pin definition for H bridge
int pwmMotorA=6;
int pwmMotorB=5;
int ForwardA=8;
int BackA=7;
int ForwardB=3;
int BackB=4;
/*ultrasonic sensor
dist1-left scan
dist2-roward scan
dist3-right scan
*/
int czas, dist2, dist1, dist3, light;
void setup() {
//servo definition
myservo.attach(9);
//buzzer
pinMode(11, OUTPUT);
//photoresistor
pinMode(A0, INPUT);
//leds
pinMode(10, OUTPUT);
//ultrasonic sensor
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
//PWM motor A
pinMode(pwmMotorA, OUTPUT);
// Motor A move back
pinMode(ForwardA, OUTPUT);
// Motor A move back
pinMode(BackA, OUTPUT);
//PWM motor B
pinMode(pwmMotorB, OUTPUT);
// Motor B move forward
pinMode(ForwardB, OUTPUT);
// Motor B move back
pinMode(BackB, OUTPUT);
//motors speed
analogWrite(pwmMotorA, 255);
analogWrite(pwmMotorB, 255);
}
//robot turn left
void Left(){
digitalWrite(ForwardA, LOW);
digitalWrite(BackA, HIGH);
//Ustawienie kierunku obrotów B
digitalWrite(ForwardB, HIGH);
digitalWrite(BackB, LOW);
delay(1000);
}
//robot turn right
void Right(){
digitalWrite(ForwardA, HIGH);
digitalWrite(BackA, LOW);
digitalWrite(ForwardB, LOW);
digitalWrite(BackB, HIGH);
delay(1000);
}
//robot move forward
void Forward(){
digitalWrite(ForwardA, HIGH);
digitalWrite(BackA, LOW);
digitalWrite(ForwardB, HIGH);
digitalWrite(BackB, LOW);
}
//robot move back
void Back(){
digitalWrite(ForwardA, LOW);
digitalWrite(BackA, HIGH);
digitalWrite(ForwardB, LOW);
digitalWrite(BackB, HIGH);
}
//ultrasonic sensor scan forward
void ScanForward(){
delay(50);
digitalWrite(trig, HIGH);
delayMicroseconds(1000);
digitalWrite(trig, LOW);
czas = pulseIn(echo, HIGH);
dist2 = (czas/2) /29.1;
}
//ultrasonic sensor scan left
void ScanLeft(){
myservo.write(160);
delay(1000);
delay(50);
digitalWrite(trig, HIGH);
delayMicroseconds(1000);
digitalWrite(trig, LOW);
czas = pulseIn(echo, HIGH);
dist1 = (czas/2) /29.1;
}
//stop robot
void Stop(){
digitalWrite(ForwardA, LOW);
digitalWrite(BackA, LOW);
digitalWrite(ForwardB, LOW);
digitalWrite(BackB, LOW);
}
//ultrasonic sensor scan right
void ScanRight(){
myservo.write(20);
delay(1000);
delay(50);
digitalWrite(trig, HIGH);
delayMicroseconds(1000);
digitalWrite(trig, LOW);
czas = pulseIn(echo, HIGH);
dist3 = (czas/2) /29.1;
}
//led and photoresistor
void Led(){
light= analogRead(A0);
if(light>850){
digitalWrite(10, HIGH);
}
else{
digitalWrite(10, LOW);
}
}
void loop() {
Led();
Stop();
delay(20);
ScanForward();
if(dist2<=17){
//buzzer on
digitalWrite(11, HIGH);
Back();
delay(1000);
//buzzer off
digitalWrite(11, LOW);
Stop();
ScanRight();
ScanLeft();
myservo.write(90);
if(dist1>=dist3){
Right();
}
else{
Left();
}
}
else{
Forward();
delay(400);
}
}
Reply 8 years ago on Introduction
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?
Reply 8 years ago
Yes but resistor must have 1,2k ohm
8 years ago on Introduction
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
Reply 8 years ago
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.
Reply 8 years ago on Introduction
Hey the motor problem is solved but the led problem is still there. Is there any problem in program.
8 years ago
Hey how much did it cost you.
Reply 8 years ago on Introduction
Hey!
All parts including arduino costs 100$ but i bought all things in Poland.
8 years ago on Introduction
I love the title for this. Good luck in the Sensors Contest.
Reply 8 years ago on Introduction
Thank you :)
8 years ago
Hey Nikus what inspired u to make this robot and y did u make this robot??
Reply 8 years ago on Introduction
Hey.
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 :)