Posted by : TheRouteFinder
Friday, May 24, 2013
සිංහලෙන් කියනවට වඩා මේක හොඳයි නේද? නැත්තම් මෙලෝ දෙයක් තේරෙන්නේ නැති වෙයි..
First of all I'm going to list what we need to do this.
1. An Aruino
2. 2 gear motors with wheels (6V to 12V)
3. 16x2 LCD
4. Rechargeable battery
5. Connector wires
6. Copper Boards
7. Plastic sheet (5x5 inch)
8. A computer with Ardunio IDE
9. IR sensor array (like Pololu OR hand made )
10. LM293 dual H bridge IC
11. 10k preset
This is the PCB design I used to connect LCD and dual H bridge motor driver. For motor driver IC connections, refer the LM293 datasheet. then you can understand the connections. Same thing to do for the LCD also. That is only for the above PCB. It can be downloaded from here. Make a PCB and solder the components to it.
First take the Arduino and IR sensor array, connect IR output pins to ANALOG pins on Arduino board. It should have same order on IR sensor array and Analog pin order. If not you will be in trouble when identifying inputs from sensor to Arduino. If it is finished then connect LCD pins RS,E,D4D5,D6,D6 and D7 to Arduino's 2nd-7th pins. There are six pins remaining on Arduino except 0 and 0 (Tx & Rx). So connect those 6 pins to motor controller. You can find what are the pins connected to PWM and directions in the code I provided.
By using the battery, power up the assembled parts. Then you can check the parts if they are working properly, else you may want to debug or troubleshoot all connections again. Make sure you have done it properly. Then assemble all the parts together as bellow.
Use Arduino IDE to upload the code after your modifications. It is easy to make, but tune it properly and it is not much easy work. PID controlled line follower will be the next one. Good Luck!
////////////////////////////////////////////////////////////////////////////////////
// //
// //////////////////////////////////////////////////////////////////////////// //
// //////////////////////////////////////////////////////////////////////////// //
// /// //
// /// SAITM 2013 ROBOTIC COMPETITION //
// /// UVA WELLASSA UNIVERSITY //
// /// MECHATRONICS //
// /// AIO_L ROBOT (LINE FOLLOWER) //
// /// //
// //////////////////////////////////////////////////////////////////////////// //
// /// /// //
// /// HASITHA B. RATHNAYAKE H.G. /// //
// /// TheRouteFinder PROJECTS (TRF) /// //
// /// www.trf.usa.cc /// //
// /// admin@trf.usa.cc /// //
// /// /// //
// //////////////////////////////////////////////////////////////////////////// //
// //////////////////////////////////////////////////////////////////////////// //
// //
////////////////////////////////////////////////////////////////////////////////////
/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*\
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|| ||
|| YOU MUST KNOW HOW TO DEBUG, CODE BUGS OCCURED & TROUBLESHOOT THE ENCOUNTERED CIRCUIT ERRORS ||
|| ||
|| DEFINED: TurnOFF() For 50mS ||
|| TurnRIGHT() with TurnOFF ||
|| TurnLEFT() with TurnOFF ||
|| FindLINE() Define Black OR White according to analogRead() values ||
|| GoFOWARD() with PWM ||
|| GoBACKWARD() with PWM ||
|| ||
|| ||
|| LMF as Left Morot Front ||
|| RMF as Right Morot Front ||
|| LMB as Left Morot Back ||
|| RMB as Right Morot Back ||
|| ||
|| LCD 16x2 7 6 5 4 3 2 Arduino PIN ||
|| RW E D4 D5 D6 D7 LCD PIN ||
|| ||
|| SLL as MOST LEFT SENSOR ||
|| SL as LEFT SENSOR ||
|| SM as AVERAGE VALUE OF TWO MIDDLE SENSORS (sen[2]+sen[3])/2 ||
|| SR as RIGHT SENSOR ||
|| SRR as MOST RIGHT SENSOR ||
|| ||
|| ||
|| ||
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
#include <avr/sleep.h>
#include <LiquidCrystal.h>
int LMB = 13;
int LMF = 12;
int RMB = 8;
int RMF = 9;
LiquidCrystal lcd(7,6,5,4,3,2);
int sen[] = {0, 0, 0, 0, 0, 0};
char SL=0,SR=0,SM=0,SLL=0,SRR=0;
/////////////////////////////////////////////////////////////////////////////////////////////////////
// SETUP FUNCTION //
/////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
lcd.begin(16, 2); // Print a message to the LCD.
pinMode(LMF, OUTPUT);
pinMode(LMB, OUTPUT);
pinMode(RMF, OUTPUT);
pinMode(RMB, OUTPUT);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
//TURN OFF FUNCTION //
/////////////////////////////////////////////
int TurnOFF(){
analogWrite(10, 0);
analogWrite(11, 0);
lcd.print("OFF");
lcd.clear();
delay (30);
}
/////////////////////////////////////////////
//TURN LEFT FUNCTION //
/////////////////////////////////////////////
int TurnLEFT(int time,int PWM1, int PWM2){
TurnOFF();
analogWrite(10, PWM1);
analogWrite(11, PWM2);
digitalWrite(LMB, HIGH);
digitalWrite(RMF, HIGH);
lcd.print("Turning LEFT");
lcd.clear();
delay(time);
}
/////////////////////////////////////////////
//TURN RIGHT FUNCTION //
/////////////////////////////////////////////
int TurnRIGHT(int time,int PWM1, int PWM2){
TurnOFF();
analogWrite(10, PWM1);
analogWrite(11, PWM2);
digitalWrite(RMB, HIGH);
digitalWrite(LMF, HIGH);
lcd.print("Turning RIGHT");
lcd.clear();
delay(time);
}
/////////////////////////////////////////////
//GO FOWARD FUNCTION //
/////////////////////////////////////////////
int GoFOWARD(int time,int PWM1, int PWM2){
TurnOFF();
analogWrite(10, PWM1);
analogWrite(11, PWM2);
digitalWrite(RMF, HIGH);
digitalWrite(LMF, HIGH);
lcd.print("Go STRAIGHT");
lcd.clear();
delay(time);
}
/////////////////////////////////////////////
//GO BACKWARD FUNCTION // NEVER USED HERE
/////////////////////////////////////////////
int GoBACKWARD(int time,int PWM1, int PWM2){
TurnOFF();
analogWrite(10, PWM1);
analogWrite(11, PWM2);
digitalWrite(RMB, HIGH);
digitalWrite(LMB, HIGH);
lcd.print("Go Back");
lcd.clear();
delay(time);
}
/////////////////////////////////////////////
// FIND LINE FUNCTION //
/////////////////////////////////////////////
int FindLINE(){
for(int s=0;s<=5;s++){
sen[s]=analogRead(s);
}
if (sen[0]>915){ SLL='B';}
else {SLL='W';}
if (sen[1]>840){ SL='B';}
else {SL='W';}
if (((sen[2]+sen[3])/2)>915){ SM='B';}
else {SM='W';}
if (sen[4]>850){ SR='B';}
else {SR='W';}
if (sen[5]>915){ SRR='B';}
else{ SRR='W';}
}
////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// INFINITE RUN FUNCTION //
////////////////////////////////////////////////////////////////////////////////
void loop(){
lcd.setCursor(0, 1);
lcd.print("TRF MECHATRONICS");
lcd.setCursor(11, 0);
lcd.print("AIO_L");
FindLINE();
if(SM=='B' && SL=='W' && SR=='W'){
GoFOWARD(8, 200, 200);
}
else if(SM=='B' && SL=='B' && SR=='W'){
GoFOWARD(8, 200, 160);
}
else if(SM=='B' && SL=='W' && SR=='B'){
GoFOWARD(8, 160, 200);
}
else if(SM=='B' && SL=='B' && SR=='B'){
GoFOWARD(20, 200, 200);
if(SLL=='B' && SRR=='B'){
GoFOWARD(8, 200, 200);
}
else if(SL=='W' && SLL=='W' && SRR=='B'){
TurnRIGHT(50, 100, 100);
}
else if(SLL=='B' && SRR=='W' && SR=='W'){
TurnLEFT(50, 100, 100);
}
}
else if(SM=='B' && SL=='B' && SLL=='B' && SRR=='W'){
TurnLEFT(50, 100, 100);
}
else if(SM=='B' && SR=='B' && SRR=='B' && SLL=='W'){
TurnRIGHT(50, 100, 100);
}
else if(SLL=='W' && SL=='W' && SM=='W' && SR=='W' && SRR=='W'){
GoFOWARD(80, 200, 200); //ADJUST DELAY
}
else if(SLL=='B' && SL=='B' && SM=='B' && SR=='B' && SRR=='B'){
GoFOWARD(80, 200, 200);
FindLINE();
if(SLL=='B' && SL=='B' && SM=='B' && SR=='B' && SRR=='B'){
TurnOFF();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_mode(); // STOP THE BOT
}
else{
GoFOWARD(8, 200, 200);
}
}
}
////////////////////////////////////////////////////////////////////////////////////
// THE END //