Robotics ArduinoJLCPCB
Published © GPL3+

Mobile Robot with 2 Wheels

Build your first low cost 2-wheel mobile robot and understand how to design each robot structure with laser cutting technology.

BeginnerFull instructions provided5 hours4,849
Mobile Robot with 2 Wheels

Things used in this project

Hardware components

JLCPCB Customized PCB
JLCPCB Customized PCB
×1
Arduino UNO
Arduino UNO
×1
Ultrasonic Sensor - HC-SR04
SparkFun Ultrasonic Sensor - HC-SR04
×1
SparkFun RedBot Sensor - Line Follower
SparkFun RedBot Sensor - Line Follower
×2
Battery Holder, 18650 x 2
Battery Holder, 18650 x 2
×1
18650 Battery Li-ion
×2
Rocker Switch, Non Illuminated
Rocker Switch, Non Illuminated
×1
Dual H-Bridge motor drivers L293D
Texas Instruments Dual H-Bridge motor drivers L293D
×1
DC Motor, 12 V
DC Motor, 12 V
×2

Software apps and online services

Arduino IDE
Arduino IDE
Fusion
Autodesk Fusion

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)

Story

Read more

Code

Source Code

Arduino
#define Motor1A 2
#define Motor1B 3
#define Motor2A 4
#define Motor2B 5

#define echoPin 10
#define trigPin 11

long tempo = 0;
byte distancia = 0;

void setup() 
{
  
  pinMode(Motor1A, OUTPUT);
  pinMode(Motor1B, OUTPUT);
  pinMode(Motor2A, OUTPUT);
  pinMode(Motor2B, OUTPUT);

  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);
}

void loop() 
{
  
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  tempo = pulseIn(echoPin, HIGH);

    delay(300);

  distancia = tempo * (0.034/2);
  
  if(distancia >= 10)
  {
    frente();
  }

    else
    
  
  {
    parar();
    delay(500);
    direita();
    delay(1000);
    parar();
  }
  
}

void frente()
{
  digitalWrite(Motor1B, LOW);
  digitalWrite(Motor2B, LOW);
  
  digitalWrite(Motor1A, HIGH);
  digitalWrite(Motor2A, HIGH);
}

void re()
{
  digitalWrite(Motor1A, LOW);
  digitalWrite(Motor2A, LOW);
  
  digitalWrite(Motor1B, HIGH);
  digitalWrite(Motor2B, HIGH);
}

void parar()
{
  digitalWrite(Motor1A, HIGH);
  digitalWrite(Motor2A, HIGH);
  
  digitalWrite(Motor1B, HIGH);
  digitalWrite(Motor2B, HIGH); 
}

void direita()
{ 
  digitalWrite(Motor1B, LOW);  
  digitalWrite(Motor2A, LOW);  
  
  digitalWrite(Motor1A, HIGH);  
  digitalWrite(Motor2B, HIGH);
}

Credits

Robotics Arduino
42 projects • 66 followers
Contact
JLCPCB
74 projects • 49 followers
JLCPCB, is the largest PCB and PCB Assembly prototype enterprise in Asia. Coupon code "JLCPCBcom" for all and permanantly available.
Contact

Comments

Please log in or sign up to comment.