Arduino: Sensitive Robot

12,202

87

19

Posted

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
  • 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/

Share

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • First Time Author Contest 2018

    First Time Author Contest 2018
  • Paper Contest 2018

    Paper Contest 2018
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

19 Comments

گروه تولیدی بازرگانی ال ای دی پانل با دارا بودن سابقه درخشان در زمینه
واردات از کشور های مختلف و نیز تولید انواع تابلو روان و <a href="http://www.ledpanelco.com/">تلویزیون
شهری</a>تبلیغاتی ، با به کاری
گیری نیروی متعهد و متخصص با هدف ارائه خدمات بازرگانی و تولیدی فعالیت می نماید که
واحد بازرگانی ال ای دی پانل با دارا بودن
شرکای تجاری معتبر در کشورهای چین ، تایوان و کره جنوبی اقدام به واردات کالاهای الکترونیکی من جمله
قطعات تابلو روان ، <a href="http://www.ledpanelco.com/">قطعات
تلویزیون شهری</a>و تجهیزات نور پردازی با بهترین
کیفیت و مناسب ترین قیمت مینماید و نیز واحد تولید ال ای دی پانل فعالیت خود را در زمینه ساخت و تولید
انواع تابلو روان و نمایشگر شهری LED با مشخصات مختلف
و نیز تولید انواع قاب تابلو روان ، کابینت تابلو روان led و کابینت <a href="http://www.ledpanelco.com/">تلویزیون
شهری</a>می نماید.

great project and the code is perfectly working

Is there any mistake in the code it is written as

if(light>850)

{

digitalWrite(8, HIGH);

}

Yes, you need to add this:

light=  analogRead(A0);
  if(light>850){
    digitalWrite(10, HIGH);
  }
  else{
    digitalWrite(10, LOW);
  }
}

Write when you are done.

Hey what is the keyword czas;

Czas is time in polish language
:-) 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.



//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);
  }
}

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?

Yes but resistor must have 1,2k ohm