Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
i am doing a line follower robot using an arduino atmega328 micro controller and a motor shield.
i am using h bridge dc motor,5 line following sensors,1 angular servo
it is a actuated steering controlled by angular servo.
can someone plz help me with the writing of the code.
I've attached a basic copy of the line following program i've been working on. So far, i've tested the motor speed functionality and the operation of the servo with the sensors. It seems to be working, but will definitely need to be calibrated for steering and motor speed. I have not attached an interrupt or something yet that will detect when it hits the line and needs to transfer over to the next lane.
plz reply with comments and any help with further improvements would be really appreciated.!!!
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define SERVO1 8
#define MAX_PERIOD 40000 //20ms
#define SERVO_UPPER_LIMIT 4800 // 90 deg right (1850 from middle to right) 20.55 per degree
#define SERVO_LOWER_LIMIT 1100 // 90 deg left (1850 from middle to left)
void ext0_handler( void );
void setup_timer1( void );
void set_timer1( unsigned int val );
volatile int t1_state = 0;
volatile int S1 = 2950; // 0 degrees is 2950
volatile int S2 = 40000; // 20ms low pulse
int direct = 0; // direction of servo
int speedlow = 0; // speed for hard turn
int speedmed = 125; // speed for med turn
int speedhigh = 250; // speed for straight away
int counter = 0; // testing counter
int binary = 0; // variable for line sensors
int leftouter = LOW; // sensor inputs
int leftinner = LOW;
int middle = LOW;
int rightinner = LOW;
int rightouter = LOW;
int pinleftouter = 2;
int pinleftinner = 3;
int pinmiddle = 4;
int pinrightinner = 5;
int pinrightouter = 6;
int pinmotor = 10;
You can do it with an at89c51 uC the sensors can be photo transistors l14f1 nad there must be a comperator (pref: lm 324) for the out put monitoring and amplification
do you need ckt dia?
$MOD
ORG 0000H
LJMP MAIN
ORG 0030H
MAIN: SETB P3.0
SETB P3.1
AGAIN:JB P3.0,NEXT
JB P3.1,GO
CLR P2.0
SETB P2.1
CLR P2.2
SETB P2.3
SJMP AGAIN
GO: CLR P2.0
SETB P2.1
CLR P2.2
CLR P2.3
SJMP AGAIN
NEXT: JB P3.1,GO1
CLR P2.0
CLR P2.1
CLR P2.2
SETB P2.3
SJMP AGAIN
GO1: JB
CLR P2.0
CLR P2.1
CLR P2.2
CLR P2.3
SJMP AGAIN
HERE: SJMP HERE
END
thanks mahn..but i have already got the atmega328 and all the other parts...i would have loved to use the assemply language code but have to deal with it the "c" way...
thanks a lot for the help though...
can u comment on my coding as to how u think i can improve it?
can i suggest one thing..?
there is no need for the servo motor... a simple anticlock-clockwise turn of the DC motor are enough for the steering of the robot.
can i ask you something..? you are using an 'arduino' compiler eh? What version of arduino are you using? if you are using arduino what's with the headers..?
didi you copied and pasted the code from the examples library (frankly)..?
i think you have copied this from the arduino folder in documents folder if you are using windows OS.Kindly paste the orginal code from the compiler itself.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.