Arduino Line Follower Uses a 4x4 Keypad

by Taufiq_Sobari in Circuits > Arduino

411 Views, 0 Favorites, 0 Comments

Arduino Line Follower Uses a 4x4 Keypad

editThumbnail.jpg

The line follower robot moves along a line using 5 digital line sensors. The robot moves to a place according to the button pressed on the keypad. To reach the destination and return to the starting point, the robot counts the number of intersections. https://youtu.be/OM27ro_l7Vw?si=t_K-tjHP-uffRQCF

Bill of Material

image223.png
mega2560Pro.jpg
5channelFront.png
tb6612fngFront.png
N20_600.png
keypad4x4.png

The parts required to build:

  • 1 Arduino Mega 2560 Pro
  • 1 Line sensor module (5 digital line sensor)
  • 1 TB6612FNG driver motor
  • 2 DC motor 600rpm and bracket
  • 1 4x4 Membrane Switch Keypad
  • 1 Switch
  • 2 Lithium 18650 battery 3.7v
  • Toy



DIY Keypad Shield

Keypad_Shield.png
image8408.png

To make keypad shield I found this tutorial "How to read a 4x4 keypad using just one Arduino pin!" https://shorturl.at/ciN07

Bill of material:

  • 1 Double side prototype PCB
  • 3 Resistor 1.5K ohm
  • 4 Resistor 390 ohm
  • 1 Resistor 4.7K ohm
  • 1 Capacitor 0.01 uF

Here is a short video of me using the keypad shield https://shorturl.at/zAV01 and https://shorturl.at/itKPS

Schema

Schema_LF_Keypad.png
g8002.png
IMG_20240218_160448.jpg

In this schematic you will find the "DIY Terminal". Made of multiple male header pins and a double sided PCB prototype. Used to supply 5V power for line sensors, keypads, driver motor and infrared obstacle avoidance sensor.

Arduino Sketches

Screenshot from 2024-02-20 19-04-31.png
track.png
IMG20240225193514.jpg
IMG20240225193347.jpg

About line sensors, PID and more, you can find it in my first instructable https://www.instructables.com/Arduino-Color-Sorter/

Count intersection:

This is a code update for calculating intersections, left junction and right junction:


//Count intersection
int intersection(){
  readSensor();
  if(sensor[4]==0 && sensor[0]==0){
    countIntersec++;
    stopDrive();
  }
  return countIntersec;
}


//Count left junction
int leftJunction(){
  readSensor();
  if(sensor[0]==0 && sensor[1]==0 && sensor[3]==1 && sensor[4]==1){
    countLeftJunc++;
  }
  return countLeftJunc;
}


//Count right junction
int rightJunction(){
  readSensor();
  if(sensor[4]==0 && sensor[3]==0 && sensor[2]==0 && sensor[0]==1){
    countRightJunc++;
  }
  return countRightJunc;
}


Read keypad:

Look at the picture, when button 2 of the keypad is pressed the value 151 appears.

int readKeypad(){
  int value = analogRead(A10);
  Serial.println(value);
  if(value == 208){ //Button value 1
    mode = 1; //The robot moves to the first place
  }
  if(value == 151){ //Button value 2
    mode = 2; //The robot moves to the second place
  }
  if(value == 84){ //Button value 3
    mode = 3; //The robot moves to the third place
  }
  if(value == 5){ //Button value A
    mode  = 4; //Back to base
  }
    return mode;
}


Robot movement;


void mission(){
  goDrive();
  if(sensor[4] == 0 && sensor[0] == 0){ 
  stopDrive(); 
  mode = readKeypad();

  switch(mode){
    case 1: 
      table_1(); //First place
      break;
    case 2:
      table_2(); //Second place
      break;
    case 3:
      table_3(); //Third place
      break;
    case 4:
      goHome(); //Back to base
    case 0:
      stopDrive();
      break;
    }
  }
}


Robot standby:

The robot stops at the destination until the infrared obstacle avoidance sensor enters a low state and then moves back to the base.

void standBy(){
 while (digitalRead(irPin) == HIGH){
  stopDrive(); 
 }
}

  defaults();
  while(next){ 
    goDrive();
    if(intersection() == 1){ //Finish intersection
    next=0; 
    }    
  }
      stopDrive();
      standBy();
      backward(100, 100);
      turnBack(100, 100);


Obstacle robot:

The robot stops if there are obstacles on the specified path.

  stright1(100, 100);
  goDrive();

  while(next){ 
    irValue = digitalRead(irPin);
    if(irValue == HIGH){              
      goDrive();
      if(leftJunction() == 1){ //Found left junction turn left
      next=0; 
      }     
    }
    if(irValue == LOW){      
      stopDrive();
    }
  }
  turnLeft(200, 0); 


https://github.com/PC07-TS/Line-Follower-Keypad