Arduino Line Follower Uses a 4x4 Keypad
by Taufiq_Sobari in Circuits > Arduino
1093 Views, 2 Favorites, 0 Comments
Arduino Line Follower Uses a 4x4 Keypad
![editThumbnail.jpg](/proxy/?url=https://content.instructables.com/FAT/RDBN/LSQ39DRH/FATRDBNLSQ39DRH.jpg&filename=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](/proxy/?url=https://content.instructables.com/FFW/ZUOR/LSQ39DNB/FFWZUORLSQ39DNB.png&filename=image223.png)
![mega2560Pro.jpg](/proxy/?url=https://content.instructables.com/FL3/CDCH/LSQ39C25/FL3CDCHLSQ39C25.jpg&filename=mega2560Pro.jpg)
![5channelFront.png](/proxy/?url=https://content.instructables.com/FB3/FKOQ/LSQ39C2C/FB3FKOQLSQ39C2C.png&filename=5channelFront.png)
![tb6612fngFront.png](/proxy/?url=https://content.instructables.com/F7O/N999/LSQ39C2I/F7ON999LSQ39C2I.png&filename=tb6612fngFront.png)
![N20_600.png](/proxy/?url=https://content.instructables.com/FT2/IDWZ/LSQ39C2P/FT2IDWZLSQ39C2P.png&filename=N20_600.png)
![keypad4x4.png](/proxy/?url=https://content.instructables.com/FXW/BU88/LSQ39C3B/FXWBU88LSQ39C3B.png&filename=keypad4x4.png)
![DSC_1801.jpg](/proxy/?url=https://content.instructables.com/F8M/QW7O/LYBKD9JC/F8MQW7OLYBKD9JC.jpg&filename=DSC_1801.jpg)
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 Infrared obstacle sensor
- 1 Switch
- 2 Lithium 18650 battery 3.7v
- Toy
DIY Keypad Shield
![Keypad_Shield.png](/proxy/?url=https://content.instructables.com/FI4/ZHEQ/LSQ39D7B/FI4ZHEQLSQ39D7B.png&filename=Keypad_Shield.png)
![image8408.png](/proxy/?url=https://content.instructables.com/FQS/UFKK/LSQ39FBF/FQSUFKKLSQ39FBF.png&filename=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
![Diagram.png](/proxy/?url=https://content.instructables.com/FFJ/3J0Q/LYBKD9DX/FFJ3J0QLYBKD9DX.png&filename=Diagram.png)
![F42SGFVLSQ39F61.png](/proxy/?url=https://content.instructables.com/F67/HG0W/LYBKD9FH/F67HG0WLYBKD9FH.png&filename=F42SGFVLSQ39F61.png)
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](/proxy/?url=https://content.instructables.com/FPR/IUXM/LSSY5FD5/FPRIUXMLSSY5FD5.png&filename=Screenshot from 2024-02-20 19-04-31.png)
![track.png](/proxy/?url=https://content.instructables.com/FR8/JZDV/LT03D4LC/FR8JZDVLT03D4LC.png&filename=track.png)
![IMG20240225193514.jpg](/proxy/?url=https://content.instructables.com/FJT/I38O/LT1IRXRF/FJTI38OLT1IRXRF.jpg&filename=IMG20240225193514.jpg)
![IMG20240225193347.jpg](/proxy/?url=https://content.instructables.com/FWO/V3BP/LT1IRXS8/FWOV3BPLT1IRXS8.jpg&filename=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);