previous_I=I; previous_error=error; } void motor_control() { // Calculating the effective motor speed: int left_motor_speed = initial_motor_speed-PID_value; int right_motor_speed = initial_motor_speed+PID_value;
// The motor speed should not exceed the max PWM value constrain(left_motor_speed,0,255); constrain(right_motor_speed,0,255);
analogWrite(9,initial_motor_speed-PID_value); //Left Motor Speed analogWrite(10,initial_motor_speed+PID_value); //Right Motor Speed //following lines of code are to make the bot move forward /*The pin numbers and high, low values might be different depending on your connections */ digitalWrite(4,HIGH); digitalWrite(5,LOW); digitalWrite(6,LOW); digitalWrite(7,HIGH); }
The code is fine though there is a small mistake in the code. The integral portion of the PID controller will give always 0 value even if you change the Ki value as it is written "I=I+previous_I" and "previous_I =I " the initial value of I is 0 so this value never change, Unless this would be I= I + error or previous_I=error; make this modification and run the robot will be working fine. Read further about PID controller and tuning of PID controller, it will help you to understand what is going on inside. Also try to modify the robot with auto tuning facility that will give this robot a new dimension. Nice work indeed.
previous_I=I; previous_error=error; } void motor_control() { // Calculating the effective motor speed: int left_motor_speed = initial_motor_speed-PID_value; int right_motor_speed = initial_motor_speed+PID_value;
// The motor speed should not exceed the max PWM value constrain(left_motor_speed,0,255); constrain(right_motor_speed,0,255);
analogWrite(9,initial_motor_speed-PID_value); //Left Motor Speed analogWrite(10,initial_motor_speed+PID_value); //Right Motor Speed //following lines of code are to make the bot move forward /*The pin numbers and high, low values might be different depending on your connections */ digitalWrite(4,HIGH); digitalWrite(5,LOW); digitalWrite(6,LOW); digitalWrite(7,HIGH); }
Here is the code as text. Copy paste and create a text file in MS Notepad. Rename *.txt. extension to *.ino and try to open with Arduino 1.0 (will not work for latest ver). No guarantee it will work but this should be a start. Note the setup part of the code gives the Arduino board pin assignment as it goes to the motor controller. float Kp=0,Ki=0,Kd=0; float error=0, P=0, I=0, D=0, PID_value=0; float previous_error=0, previous_I=0; int sensor[5]={0, 0, 0, 0, 0}; int initial_motor_speed=100; void read_sensor_values(void); void calculate_pid(void); void motor_control(void); void setup() { pinMode(9,OUTPUT); //PWM Pin 1 pinMode(10,OUTPUT); //PWM Pin 2 pinMode(4,OUTPUT); //Left Motor Pin 1 pinMode(5,OUTPUT); //Left Motor Pin 2 pinMode(6,OUTPUT); //Right Motor Pin 1 pinMode(7,OUTPUT); //Right Motor Pin 2 Serial.begin(9600); //Enable Serial Communications } void loop() { read_sensor_values(); calculate_pid(); motor_control(); } void read_sensor_values() { sensor[0]=digitalRead(A0); sensor[1]=digitalRead(A1); sensor[2]=digitalRead(A2); sensor[3]=digitalRead(A3); sensor[4]=digitalRead(A4);
previous_I=I; previous_error=error; } void motor_control() { // Calculating the effective motor speed: int left_motor_speed = initial_motor_speed-PID_value; int right_motor_speed = initial_motor_speed+PID_value;
// The motor speed should not exceed the max PWM value constrain(left_motor_speed,0,255); constrain(right_motor_speed,0,255);
analogWrite(9,initial_motor_speed-PID_value); //Left Motor Speed analogWrite(10,initial_motor_speed+PID_value); //Right Motor Speed //following lines of code are to make the bot move forward /*The pin numbers and high, low values might be different depending on your connections */ digitalWrite(4,HIGH); digitalWrite(5,LOW); digitalWrite(6,LOW); digitalWrite(7,HIGH); }
@@hiepinhhoai7628 Open the code in Arduino and type in values starting at 0.1 for all three values until the unit begins to "shake" from over control. At that point, go back one or two values. Document your inputs and observed behavior if in case you have to reload the code from scratch.
+Matthew Buckler ... Try to make one .. the parts are inexpensive and the sense of accomplishment is rewarding. There are a lot of people who will help ... including me.
+Matthew Buckler ... Not really, the chassis itself you can DIY or get a chassis kit with geared motors for less than $15 shipped ... www.ebay.com/itm/New-Smart-Motor-Robot-Car-Battery-Box-Chassis-Kit-Speed-Encoder-For-Arduino-/371160130577?hash=item566ade2411:g:bHUAAOSwU9xUNOeF and sensors are about $10 @ $1.00 per. www.ebay.com/itm/10pcs-IR-Infrared-Obstacle-Avoidance-Sensor-Module-for-Arduino-Smart-Car-Robot-/121448818182?hash=item1c46e9e606:g:MW8AAOSwgQ9VrfV6 .. Ebay is your friend. I'm working on a 8x8 RGB LED matrix at the moment ... the wiring is a spaghetti monster but it's getting there.
Very sorry ... I did not record the last P I D values used for the final upload. Not sure of max values either since I started from 0.0 and incrementally went up by 0.1 until I observed oscillations and backed out until the oscillations stopped.
If you just followed this suggestion in the video description ... you would have found the PID tutorial ...PLEASE READ THE VIDEO DESCRIPTION. LINK TO CODE AND TUTORIAL PROVIDED BELOW
That was really interesting Sir !! I have a question ! I am planning to make a robot that rus on football ground ! So there can v use this same sensors to make a robot that follows the white line in green field ?? Your help would be much appreciated ! Thank you !
+AKHIL AJAY ... if you can make the football line a solid color (no patches of green in between) and the sensors wide enough from each other so both edges of the line are covered, there should be no reason why your project will not work.
Wiring depends on the controller to use suggest you use the same type of controller installed under the robot chassis. Wiring logic in the Arduino code. ID your motor controller Left and Right motor pins. ID also the PWM pins. Wiring to the Arduino board (Output pin) also in the sketch snippet below. pinMode(9,OUTPUT); //PWM Pin 1 pinMode(10,OUTPUT); //PWM Pin 2 pinMode(4,OUTPUT); //Left Motor Pin 1 pinMode(5,OUTPUT); //Left Motor Pin 2 pinMode(6,OUTPUT); //Right Motor Pin 1 pinMode(7,OUTPUT); //Right Motor Pin 2
@@tsisapik I wanted to know the connections of motor driver of section 'power' which includes 12v, gnd, and 5v. Is there a way I can get the schematics of your line follower?
@@tsisapik I have made all connections using the code, IR sensors and the motor driver pins. I just wanted to know how you connected the power source to both arduino and motor driver. You have used jack to connect power source to arduino, but, from which pin does the motor driver receive power(5v or 12v) and how? Are the motor driver and arduino's gnd and 5v pin interconnected?
The P I D tuning starts from all zeros. Increase P I D incrementally until you get the performance you like ... I need to check but I think it is P I first then increase D until oscillation is observed then back out. Write down all your adjustments and observations then pick the best combination. You's get a lazy robot at first, then it starts to behave properly then oscillates ... that's the point you back out.
hi there, your video is very interesting, i have some troubles understanding the code; in the function read_sensor_values(), you haven't used sensor[3], and what does 0 represent (black or white)? Thank you so much .
Open the code in Arduino and type in values starting at 0.1 for all three values until the unit begins to "shake" from over control. At that point, go back one or two values. Document your inputs and observed behavior if in case you have to reload the code from scratch.
Go to the program download link > download the temp file > change the extension from *.tmp to .pde or *.ino so it can be opened by Arduino or to *.txt so you can view the sketch. Now you know ...
Open the code in Arduino and type in values starting at 0.1 for all three values until the unit begins to "shake" from over control. At that point, go back one or two values. Document your inputs and observed behavior if in case you have to reload the code from scratch.
+Simon Tilsted Hansen ... Why - is there something you like to accomplish? You can use stepper motors - but that's more involved. You can make one without the geared motors but I am not sure if it would work properly. Reason for geared motors is that the robot needs a lot of torque to change directions to keep it on track and do the correction quickly because the robot is in constant motion.
Because like you they did not first read the video description in CAPS ... "PLEASE READ THE VIDEO DESCRIPTION. WEBSITE URL HAS BEEN TAKEN DOWN. ARDUINO SKETCH POSTED IN MY COMMENT.'
i just need some help....in your code u wrote (sensor[0]=digitalRead(A0);)...can u explain this to me ....because as far as i know it should be analogRead.....thanks
The analog input pins can be used as digital pins, referred to as A0, A1, etc. The exception is the Arduino Nano, Pro Mini, and Mini’s A6 and A7 pins, which can only be used as analog inputs.
Hmmmm - I do not think 9v pile is okay. First the voltage is too high and the power rating is too low. Use 6v from AA's or 6V Lipo through a Battery Eliminator Circuit (BEC). Good luck. Got to the tutorial link in the video description.
Clink on "Code link here" ... copy / paste the text file to Word or any word processor program and save the file as a *.pde to be opened by Arduino IDE 1.0 or later. P I D starts at 0,0,0 and increase incrementally. Best of luck!
It's a simple bus bar that allows the sensor positive and negative leads to be connected together. Only the signal leads, one positive and one negative wires goes to the Arduino board. This simplifies the wiring a lot.
If you plan to use these types of motors and this code - yes you need a motor controller. If you modify the code so you can power smaller power consuming motors directly - then you do not need motor controllers - but the code needs to be modified as DC motors do not understand PWM signals.
can you send the code if you got it,...jayanthasaranga@gmail.com...please send.....link was not working ...i don't know why...................Email- jayanthasaranga@gmail.com
I have not looked at the code for a while but I am certain the speed can be changed .. if I remember right, it is set at max speed so this is the fastest line follower I have made. Did you build one for yourself? If you plan to make one, this would probably be the best one to make. This is what I used hope this helps ...www.instructables.com/id/Control-DC-and-stepper-motors-with-L298N-Dual-Moto/
Sir... PID_Line_Follower.pde >> Is this the complete & 100% full coding for this line following robot... I thought this code is just for the PID... so how the sensor gives signals to motor via this code... Sir.. i didn't get this idea.. hope you will make me clear :D if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==1)) error=4; else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==1)) error=3; else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==0)) error=2; else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==1)&&(sensor[4]==0)) error=1; else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0)) error=0; else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0)) error=-1; else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0)) error=-2; else if((sensor[0]==1)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0)) error=-3; else if((sensor[0]==1)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0)) error=-4; else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0)) if(error==-4) error=-5; else error=5; i believe sensor[4] is repeated twice.. but it doesn't matter.. instead let us put sensor[3] ... but i didn't get the error thing.. hope i will understand it through you... really looking forward to it sir.. You are amazing!!! :D
Go to this URL for a PID tutorial. The P I D logic allows the robot to keep "following the line" even when the sensors are no longer bounded by the line. There are other more simpler code but this version is the most efficient in making the robot perform as it should. samvrit.tk/tutorials/pid-contr...
Go here to find out what the motor controller PWM inputs are www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/. Look carefully at your Arduino board and look for two pins called 9 and 10 on the Arduino board ... you can't miss them.
hi please i would like to know what component between the 5 sensors and the arduino card is it a clculator which solve operation and send it to arduino card!!!
Hello ... the five sensors are directly connected to the Arduino board. The signals sent by the sensors determine the behavior of the robot - turn left, turn right or go straight.
Assuming you have the same sensors. Dollar store plastic cutting board cut into strips (I used a metal snips) with holes bored at the center to center distance of the sensor (laid side by side). 1/2 inch alum angle bars to hole the plastic strip. Necklace beads (I raided the kid's junk drawer) as spacers to hold the sensors in place. I used 3mm screws, nuts and washers to hold everything together. You can also you a plastic ruler or even wood in lieu of the dollar store cutting board strips. Look around your house ... I'm sure something will come up. Have fun!
Get hold of the sensors and measure center to center. I do not know if the sensors you get are the same ones I used - be off 1 mm and they will not fit properly. FYI ... I have several strips used for line following robots. A strip with the sensor in the middle (like this one) and strips with sensors to the side of the line - for two sensor line followers - experiment. Use narrow lines, wide lines. Vary the angle of the curve. Use different geared motors for different speeds. When testing on a table, be prepared to catch the robot in case it jumps the line while calibrating.
That is a Battery Eliminator Circuit or BEC for short. It converts the Lipo voltage of 7.4V (2S) or 11.3V (3S) to a regulated 5V that powers both the Arduino shield and motor controller. Using a BEC makes sure your power supply is constant and steady.
For this robot, the P, I and D values are inputted on three separate lines on the sketch. Put a table together. Starting with all zeros, input the values, save compile and upload then record the robot behavior. At some combination of values, your robot will transform from a lazy drunk hunk of metal and plastic to a very intelligent predicable piece of engineering.
Can you please provide the code. The link given in description is not working. If you can share the code then it will be very helpful. Hoping to hearing from you soon.
wat to do if we want to make dis robo move at a faster speed??....coz it works pretty ...how to change d constants???like varying d constants w.r.t speed??
Easiest would to change the code to increase the speed .... but even then, it will not be a lot faster. Second is to use a different motor with less gear reduction - reduce by half and the speed is twice - maybe even fabricate your own using DIY gear sets. Third is to use larger diameter wheels - twice the circumference twice the speed.
+SAYAK BHAR ... The frame is one of two plastic pieces for the IR avoidance robots. I bought this kit from Ebay but the kit is available in online stores where Arduino robotic kits are sold.
From the video links ...Connections Connect the 5 digital IR sensors to the analog inputs (you can still read digital values from analog inputs). Connect the Left motor pins to digital pins 4 and 5 Connect the Right motor pins to digital pins 6 and 7 Connect the PWM pins to pins 9 and 10 Look closely at the code itself to confirm the connections. Power would be 5V to the Arduino input and motor controller input. For the motor controller, make sure the jumper is set for the correct voltage. If the motors move in the wrong direction interchange the motor polarity and not the code.
"The L293D is a 16-pin Motor Driver IC which can control up to two DC motors simultaneously, in any direction." ... so yes it can drive DC motors. dzone.com/articles/driving-a-dc-motor-with-an-arduino-and-the-l293d-m
Simple - I do not need a serial interphase to look at the data from the sensors. The sensors I use allow me to adjust sensitivity for proper performance. That makes tuning 100x easier don't you think?
ok ...i have a question..please help me in this..... which value we are getting for which color.....the sensor i have it's giving 1 for white and 0 for black........is it ok to use this code ?
I also have a question ... did you try using the sensors you described? There are so many things that can go wrong with robots. Sensors would definitely be one, You'll never know unless you experiment true robot maker dude. This is part of the fun of robot making. If it does not work initially, step away and review the steps you made making sure each step was done correctly.
That is a DIY bus bar ... simplifies the signal wire connections to the Arduino board. Positive and negative to all five sensors via two wires from the Arduino.
Sorry, I do not have the sensor you mentioned. If it can provide the correct input signals to the board as it crosses the black line, then it should work without changing the code.
This only works for motor speed of 90/100(pwm)..... 6v motors...... above this value the motors gets out of line with hard left and right..... motors used here has very low torque. Thats why it doesnot follow tracks while moving at higher speeds.
Would be nice if you had videos to illustrate your point. The motors used for these and other projects I have made are geared motor set ups meaning, while the actual motor may be low torque, the gearing increases the torque at the expense of speed. FYI ... this is the fastest speed I could make the code to produce I can't go higher unless i use less reduction. While the sensors do exceed the lines, the robot gets back on track. If you notice carefully, both sides of the curve are not the same - one side has a more acute initial curve than the other - this is intentional specifically to test performance - but does not seem to adversely affect tracking capabilities.
i make a line follower of 5 ir sensor withe L293 motor driver and put this code but my robot not work . i truble in connection of motor driver, ,,,,, my motor driver is different from your but l293 and not present there are in pw pins so where me connect pw pins 9 and 10 please help me
Research the pin outs for the L293 and how they would normally be connected to an Arduino. I have looked at this once and the connections are the same even if the unit's layout differs. Else, use the same controller.
Good catch ... first "4" in the sensor read routing should be "3" - code still works because of the last "4" sensor read. but could be more accurate with the "3".
tsisapik sir, can you tell me how the robot will turn, I mean if (error =5 and kp=0.2) then (pid value=5×0.2=1). Now left motor=100+1 and right motor =100-1. With such small value, i dont think that it can make a turn? Correct me if I'm wrong
Sorry for the delayed response ... try reducing your voltage to 5V ... I used a dropping resistor made of nichrome wire which I later took out. You could also vary speed by changing the PWM from 256 to whatever you want in the code itself.
Maybe, maybe not ... check the specs, make the correct holder and make sure you are able to calibrate the sensor unit properly ... you're on your own! Good Luck!
@@tsisapik can you send the code if you got it,...jayanthasaranga@gmail.com...please send.....link was not working ...i don't know why...................Email- jayanthasaranga@gmail.com
can you send the code if you got it,...jayanthasaranga@gmail.com...please send.....link was not working ...i don't know why...................Email- jayanthasaranga@gmail.com
Great ! Thanks !!!
And I appreciate your patient replies, please continue !!!
ALL THE BEST
With 5 sensors you have nice smooth turning, not like with only 2 sensors. Some people are cheap!
With 5 sensors you have nice smooth turning, not like with only 2 sensors. Some people are cheap!!
i found the code 😁
float Kp=0,Ki=0,Kd=0;
float error=0, P=0, I=0, D=0, PID_value=0;
float previous_error=0, previous_I=0;
int sensor[5]={0, 0, 0, 0, 0};
int initial_motor_speed=100;
void read_sensor_values(void);
void calculate_pid(void);
void motor_control(void);
void setup()
{
pinMode(9,OUTPUT); //PWM Pin 1
pinMode(10,OUTPUT); //PWM Pin 2
pinMode(4,OUTPUT); //Left Motor Pin 1
pinMode(5,OUTPUT); //Left Motor Pin 2
pinMode(6,OUTPUT); //Right Motor Pin 1
pinMode(7,OUTPUT); //Right Motor Pin 2
Serial.begin(9600); //Enable Serial Communications
}
void loop()
{
read_sensor_values();
calculate_pid();
motor_control();
}
void read_sensor_values()
{
sensor[0]=digitalRead(A0);
sensor[1]=digitalRead(A1);
sensor[2]=digitalRead(A2);
sensor[3]=digitalRead(A3);
sensor[4]=digitalRead(A4);
if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==1))
error=4;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==1))
error=3;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==0))
error=2;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==1)&&(sensor[4]==0))
error=1;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0))
error=0;
else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0))
error=-1;
else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
error=-2;
else if((sensor[0]==1)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
error=-3;
else if((sensor[0]==1)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
error=-4;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
if(error==-4) error=-5;
else error=5;
}
void calculate_pid()
{
P = error;
I = I + previous_I;
D = error-previous_error;
PID_value = (Kp*P) + (Ki*I) + (Kd*D);
previous_I=I;
previous_error=error;
}
void motor_control()
{
// Calculating the effective motor speed:
int left_motor_speed = initial_motor_speed-PID_value;
int right_motor_speed = initial_motor_speed+PID_value;
// The motor speed should not exceed the max PWM value
constrain(left_motor_speed,0,255);
constrain(right_motor_speed,0,255);
analogWrite(9,initial_motor_speed-PID_value); //Left Motor Speed
analogWrite(10,initial_motor_speed+PID_value); //Right Motor Speed
//following lines of code are to make the bot move forward
/*The pin numbers and high, low values might be different
depending on your connections */
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
}
did this code work for you?
Does it works
The code is fine though there is a small mistake in the code. The integral portion of the PID controller will give always 0 value even if you change the Ki value as it is written "I=I+previous_I" and "previous_I =I " the initial value of I is 0 so this value never change, Unless this would be I= I + error or previous_I=error; make this modification and run the robot will be working fine.
Read further about PID controller and tuning of PID controller, it will help you to understand what is going on inside. Also try to modify the robot with auto tuning facility that will give this robot a new dimension.
Nice work indeed.
Great job !
after changing no progress show
Kindly send me the code . the link is not opening
how to change that code sir ?
Send me the code link please
This is his code. note that constrain is not the correct for constrain(). check arduino references
float Kp=0,Ki=0,Kd=0;
float error=0, P=0, I=0, D=0, PID_value=0;
float previous_error=0, previous_I=0;
int sensor[5]={0, 0, 0, 0, 0};
int initial_motor_speed=100;
void read_sensor_values(void);
void calculate_pid(void);
void motor_control(void);
void setup()
{
pinMode(9,OUTPUT); //PWM Pin 1
pinMode(10,OUTPUT); //PWM Pin 2
pinMode(4,OUTPUT); //Left Motor Pin 1
pinMode(5,OUTPUT); //Left Motor Pin 2
pinMode(6,OUTPUT); //Right Motor Pin 1
pinMode(7,OUTPUT); //Right Motor Pin 2
Serial.begin(9600); //Enable Serial Communications
}
void loop()
{
read_sensor_values();
calculate_pid();
motor_control();
}
void read_sensor_values()
{
sensor[0]=digitalRead(A0);
sensor[1]=digitalRead(A1);
sensor[2]=digitalRead(A2);
sensor[3]=digitalRead(A3);
sensor[4]=digitalRead(A4);
if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==1))
error=4;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==1))
error=3;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==0))
error=2;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==1)&&(sensor[4]==0))
error=1;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0))
error=0;
else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0))
error=-1;
else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
error=-2;
else if((sensor[0]==1)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
error=-3;
else if((sensor[0]==1)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
error=-4;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
if(error==-4) error=-5;
else error=5;
}
void calculate_pid()
{
P = error;
I = I + previous_I;
D = error-previous_error;
PID_value = (Kp*P) + (Ki*I) + (Kd*D);
previous_I=I;
previous_error=error;
}
void motor_control()
{
// Calculating the effective motor speed:
int left_motor_speed = initial_motor_speed-PID_value;
int right_motor_speed = initial_motor_speed+PID_value;
// The motor speed should not exceed the max PWM value
constrain(left_motor_speed,0,255);
constrain(right_motor_speed,0,255);
analogWrite(9,initial_motor_speed-PID_value); //Left Motor Speed
analogWrite(10,initial_motor_speed+PID_value); //Right Motor Speed
//following lines of code are to make the bot move forward
/*The pin numbers and high, low values might be different
depending on your connections */
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
}
You're the man bro !! Thanks a lot
Can you send me the tutorial please
With 5 sensors you have nice smooth turning, not like with only 2 sensors. Some epeople are cheap!!
Very good!!! Thank you for help.
I am from Brasil.
=)
The code is awesome! Is everything I was searching for.
Can u share the code link the link provide by sir is not working now
Hey. Can you share the code pls
very nice, informative and soothing music makes it easy to watch :-)
+p kalia ... Thank you !
Hmmm, that looks really smooth. I guess it is worth putting five sensors on then.
Yes ... yes it does ...
Here is the code as text. Copy paste and create a text file in MS Notepad. Rename *.txt. extension to *.ino and try to open with Arduino 1.0 (will not work for latest ver). No guarantee it will work but this should be a start. Note the setup part of the code gives the Arduino board pin assignment as it goes to the motor controller.
float Kp=0,Ki=0,Kd=0;
float error=0, P=0, I=0, D=0, PID_value=0;
float previous_error=0, previous_I=0;
int sensor[5]={0, 0, 0, 0, 0};
int initial_motor_speed=100;
void read_sensor_values(void);
void calculate_pid(void);
void motor_control(void);
void setup()
{
pinMode(9,OUTPUT); //PWM Pin 1
pinMode(10,OUTPUT); //PWM Pin 2
pinMode(4,OUTPUT); //Left Motor Pin 1
pinMode(5,OUTPUT); //Left Motor Pin 2
pinMode(6,OUTPUT); //Right Motor Pin 1
pinMode(7,OUTPUT); //Right Motor Pin 2
Serial.begin(9600); //Enable Serial Communications
}
void loop()
{
read_sensor_values();
calculate_pid();
motor_control();
}
void read_sensor_values()
{
sensor[0]=digitalRead(A0);
sensor[1]=digitalRead(A1);
sensor[2]=digitalRead(A2);
sensor[3]=digitalRead(A3);
sensor[4]=digitalRead(A4);
if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==1))
error=4;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==1))
error=3;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==0))
error=2;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==1)&&(sensor[4]==0))
error=1;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0))
error=0;
else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0))
error=-1;
else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
error=-2;
else if((sensor[0]==1)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
error=-3;
else if((sensor[0]==1)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
error=-4;
else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0))
if(error==-4) error=-5;
else error=5;
}
void calculate_pid()
{
P = error;
I = I + previous_I;
D = error-previous_error;
PID_value = (Kp*P) + (Ki*I) + (Kd*D);
previous_I=I;
previous_error=error;
}
void motor_control()
{
// Calculating the effective motor speed:
int left_motor_speed = initial_motor_speed-PID_value;
int right_motor_speed = initial_motor_speed+PID_value;
// The motor speed should not exceed the max PWM value
constrain(left_motor_speed,0,255);
constrain(right_motor_speed,0,255);
analogWrite(9,initial_motor_speed-PID_value); //Left Motor Speed
analogWrite(10,initial_motor_speed+PID_value); //Right Motor Speed
//following lines of code are to make the bot move forward
/*The pin numbers and high, low values might be different
depending on your connections */
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
}
sir, can you show me how to get Kp, Ki and Kd values? I've tried your code multiple times but I'm still fail.
@@hiepinhhoai7628 Open the code in Arduino and type in values starting at 0.1 for all three values until the unit begins to "shake" from over control. At that point, go back one or two values. Document your inputs and observed behavior if in case you have to reload the code from scratch.
@@tsisapik thank you ^^
.
@Leoga dada
This is comment with the code
Very cool code works!
Great job!
+Matthew Buckler ... Thank you ... not my code .. although I did some minor improvements to make it work better.
+tsisapik it is so though because I don't think I will ever make it...
+Matthew Buckler ... Try to make one .. the parts are inexpensive and the sense of accomplishment is rewarding. There are a lot of people who will help ... including me.
+tsisapik thanks but that means i have to buy a chassis and 5 sensors...
+Matthew Buckler ... Not really, the chassis itself you can DIY or get a chassis kit with geared motors for less than $15 shipped ... www.ebay.com/itm/New-Smart-Motor-Robot-Car-Battery-Box-Chassis-Kit-Speed-Encoder-For-Arduino-/371160130577?hash=item566ade2411:g:bHUAAOSwU9xUNOeF and sensors are about $10 @ $1.00 per. www.ebay.com/itm/10pcs-IR-Infrared-Obstacle-Avoidance-Sensor-Module-for-Arduino-Smart-Car-Robot-/121448818182?hash=item1c46e9e606:g:MW8AAOSwgQ9VrfV6 .. Ebay is your friend. I'm working on a 8x8 RGB LED matrix at the moment ... the wiring is a spaghetti monster but it's getting there.
great job sir but i have a question please
what are the values that you have used for Kp Kd and Ki ?
what's the maximum of each one ?
Very sorry ... I did not record the last P I D values used for the final upload. Not sure of max values either since I started from 0.0 and incrementally went up by 0.1 until I observed oscillations and backed out until the oscillations stopped.
Thank you sir for answering , but i want to know which instruction or command allows me to observe oscillations so i can tune the PID ?
?
If you just followed this suggestion in the video description ... you would have found the PID tutorial ...PLEASE READ THE VIDEO DESCRIPTION. LINK TO CODE AND TUTORIAL PROVIDED BELOW
That was really interesting Sir !!
I have a question ! I am planning to make a robot that rus on football ground !
So there can v use this same sensors to make a robot that follows the white line in green field ??
Your help would be much appreciated ! Thank you !
+AKHIL AJAY ... if you can make the football line a solid color (no patches of green in between) and the sensors wide enough from each other so both edges of the line are covered, there should be no reason why your project will not work.
Ha ha! That's Cool! My favorite mad scientist is still at it I see.
+RonALampman ... Had three versions to work on - this is the best so far ... regards!
can u do the full video please..How to make and everything
Hello. Does the code works with 4 sensors ? What value does Kp has ?
Have not tried for four - probably can disable the center sensor and use only four. Kp value has to be arrived at by trial and error.
Hi very nice project, could I please know the connections of motor driver's 'power' section? Waiting for your answer.
Wiring depends on the controller to use suggest you use the same type of controller installed under the robot chassis. Wiring logic in the Arduino code. ID your motor controller Left and Right motor pins. ID also the PWM pins. Wiring to the Arduino board (Output pin) also in the sketch snippet below.
pinMode(9,OUTPUT); //PWM Pin 1
pinMode(10,OUTPUT); //PWM Pin 2
pinMode(4,OUTPUT); //Left Motor Pin 1
pinMode(5,OUTPUT); //Left Motor Pin 2
pinMode(6,OUTPUT); //Right Motor Pin 1
pinMode(7,OUTPUT); //Right Motor Pin 2
@@tsisapik I am using an arduino uno and the same motor driver you are using
@@tsisapik I wanted to know the connections of motor driver of section 'power' which includes 12v, gnd, and 5v. Is there a way I can get the schematics of your line follower?
I really need your help to finish this project. I have a deadline of sept 5. Pls help
@@tsisapik I have made all connections using the code, IR sensors and the motor driver pins. I just wanted to know how you connected the power source to both arduino and motor driver. You have used jack to connect power source to arduino, but, from which pin does the motor driver receive power(5v or 12v) and how? Are the motor driver and arduino's gnd and 5v pin interconnected?
Your PID line follower robot code was not there in your website 🤷🏻♂️
Watch the video to figure what out
Where did you get that yellow geared motor on the wheels?
Search on Ebay ... Arduino Geared Motor ... be sure you get identical types so they move at the same rate.
Ok Thank you!
What are the preferrable values of kp, ki and kd? And also the P, I, D? Thanks man.. I'm waiting for your answer..
Start from zero and increase incrementally in small amounts.
Can you tell me what's the running speed of that motors? Are you supplying motors with 5 volts ?
Running speed? I really do not know. The Arduino shield and motor controller get fed with 5V from a BEC.
tsisapik: I have a question for you! In your code, PID_value = 0 because Kp=Kd=KI=0.For adjust motor speed, Kp,KI,Kd is not equal 0; Thanks
The P I D tuning starts from all zeros. Increase P I D incrementally until you get the performance you like ... I need to check but I think it is P I first then increase D until oscillation is observed then back out. Write down all your adjustments and observations then pick the best combination. You's get a lazy robot at first, then it starts to behave properly then oscillates ... that's the point you back out.
ok. Thanks you
hi there, your video is very interesting, i have some troubles understanding the code; in the function read_sensor_values(), you haven't used sensor[3], and what does 0 represent (black or white)? Thank you so much .
0 = low, 1 = high
Thank you sir
I use l298n, can you tell me how much power use the 2 dc motors work normally? please ...
Super sar , sar can u tell me the circuit diagram if possible I say the code but didnt understand how to connect the components
Awesome work bro
Thank you !
You are welcome and good luck!
Super sar,sar if possible can u please send me the circuit diagram, the link for the tutorial you have give is not opening
unable to open your description link hoping to receive update on tutorial thank you i want to make 1 of this :)
Open the code in Arduino and type in values starting at 0.1 for all three values until the unit begins to "shake" from over control. At that point, go back one or two values. Document your inputs and observed behavior if in case you have to reload the code from scratch.
do you have a diagram of the wiring or can u post a picture because I wanna know wat is sensor one two and so on pinned in
I also was unable to open your description link.
Did you read the video description?
links in the description are not working. Please send me the details. Thank you
Go to the program download link > download the temp file > change the extension from *.tmp to .pde or *.ino so it can be opened by Arduino or to *.txt so you can view the sketch. Now you know ...
@@tsisapik where's the program download link, dear Sir?
Is there any change te code can be uploaded somewhere else (another site maybe)??
Did you read the video description on where to find the code?
in your code I remains zero
you have written I =I+prev_I and both are initialised to zero
Open the code in Arduino and type in values starting at 0.1 for all three values until the unit begins to "shake" from over control. At that point, go back one or two values. Document your inputs and observed behavior if in case you have to reload the code from scratch.
How did you make it go that slow? When I try PMW value around 50 on my BO Motors, they stop moving at all :|
Try reducing the voltage of the power supply you are using or use a dropping resistor for the same purpose.
Can I make a line follower without geared motors? Please answer.
+Simon Tilsted Hansen ... Why - is there something you like to accomplish? You can use stepper motors - but that's more involved. You can make one without the geared motors but I am not sure if it would work properly. Reason for geared motors is that the robot needs a lot of torque to change directions to keep it on track and do the correction quickly because the robot is in constant motion.
Okay thank you
Have you tried a thinner black line?
This is the width of the tape so it was easier to use untouched.
Sir, may you provide the code please?
Website given in description is not working.I want to get code for 5 sensors.....please
Read the video description please.
can a plollu be used instead of the 5 digit IR sensor and if yes what modification should be done on the code thank you so much
+Lamiae adam .. The Pololu sensors can definitely be used but I do not have one so I cannot comment.
then why number of people are asking about code??? there is no link in description
Because like you they did not first read the video description in CAPS ... "PLEASE READ THE VIDEO DESCRIPTION. WEBSITE URL HAS BEEN TAKEN DOWN. ARDUINO SKETCH POSTED IN MY COMMENT.'
@@tsisapik There is no website url. It is not showing often people. share link here
Can You Explain The PID_value? Thanks!
ruclips.net/video/g7apd9a7Jxs/видео.html
sir which device you used to connect ir sensor to arduino board? please relpy as soon as possible
That's just a bus bar - you can connect the sensors directly to the Arduino board.
i just need some help....in your code u wrote (sensor[0]=digitalRead(A0);)...can u explain this to me ....because as far as i know it should be analogRead.....thanks
Explain to me - when does a Hi or Lo signal from the IR sensor become analog?
when we convert them into analog using DAC right??....but my question is why u used the (A0,A1....)pins...thanks.
The analog input pins can be used as digital pins, referred to as A0, A1, etc. The exception is the Arduino Nano, Pro Mini, and Mini’s A6 and A7 pins, which can only be used as analog inputs.
Friend excuse my ignorance because when I leave the pure pile of 9 VOLT. the square the cart pulls different k when I have it connected to my computer
Hmmmm - I do not think 9v pile is okay. First the voltage is too high and the power rating is too low. Use 6v from AA's or 6V Lipo through a Battery Eliminator Circuit (BEC). Good luck. Got to the tutorial link in the video description.
your website is not working, please share another link or file of code and pid
Clink on "Code link here" ... copy / paste the text file to Word or any word processor program and save the file as a *.pde to be opened by Arduino IDE 1.0 or later. P I D starts at 0,0,0 and increase incrementally. Best of luck!
what do you connect the sensors to before the arduino what is the board used for it
It's a simple bus bar that allows the sensor positive and negative leads to be connected together. Only the signal leads, one positive and one negative wires goes to the Arduino board. This simplifies the wiring a lot.
Hi again i was just wndering if you need a motor driver if your using an arduino
If you plan to use these types of motors and this code - yes you need a motor controller. If you modify the code so you can power smaller power consuming motors directly - then you do not need motor controllers - but the code needs to be modified as DC motors do not understand PWM signals.
Program and schematics are note available in your website
Did you read the video description?
It would be able to take 90 degree and 45 degree turns??
The answer would depend on what setting you put the PWM signal to ...
If im using this bot on white line so what will change
Like that any chnges on coding or wiring
I do not know ... have not tried it.
one's with zeroes common sense
can you send the code if you got it,...jayanthasaranga@gmail.com...please send.....link was not working ...i don't know why...................Email- jayanthasaranga@gmail.com
How do you use a motor speed (.... rpm.) In the video running full speed 255 (PWM)?
I have not looked at the code for a while but I am certain the speed can be changed .. if I remember right, it is set at max speed so this is the fastest line follower I have made. Did you build one for yourself? If you plan to make one, this would probably be the best one to make. This is what I used hope this helps ...www.instructables.com/id/Control-DC-and-stepper-motors-with-L298N-Dual-Moto/
Thank you for your advise
Good luck robot builder !
tracks the best even if the sensors go beyond the black line
where can i get the code sir?
Hello, can you explain me why do you use previous_I=I and previous_error=error in void calculate_pid()??? Thank you, i'm waiting your answer!
This is part of the P I D algorithm that cycles depending on sensor data ... hard to visualize but it works.
Can i get the complete code for this 5 sensor line following robot sir!!..
Sure ... go to the video description.
Sir... PID_Line_Follower.pde >> Is this the complete & 100% full coding for this line following robot... I thought this code is just for the PID... so how the sensor gives signals to motor via this code...
Sir.. i didn't get this idea.. hope you will make me clear :D
if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==1)) error=4; else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==1)) error=3; else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==1)&&(sensor[4]==0)) error=2; else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==1)&&(sensor[4]==0)) error=1; else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0)) error=0; else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==1)&&(sensor[4]==0)&&(sensor[4]==0)) error=-1; else if((sensor[0]==0)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0)) error=-2; else if((sensor[0]==1)&&(sensor[1]==1)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0)) error=-3; else if((sensor[0]==1)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0)) error=-4; else if((sensor[0]==0)&&(sensor[1]==0)&&(sensor[2]==0)&&(sensor[4]==0)&&(sensor[4]==0)) if(error==-4) error=-5; else error=5;
i believe sensor[4] is repeated twice.. but it doesn't matter.. instead let us put sensor[3] ... but i didn't get the error thing.. hope i will understand it through you... really looking forward to it sir.. You are amazing!!! :D
Go to this URL for a PID tutorial. The P I D logic allows the robot to keep "following the line" even when the sensors are no longer bounded by the line. There are other more simpler code but this version is the most efficient in making the robot perform as it should. samvrit.tk/tutorials/pid-contr...
Thanks .. :D
if i have 5 optical sensors (OPB742WZ), will that work?
am i to use analog ir sensors
cant i complete it with digital ones
Where is code
Hello,
The link is not working anymore, can you please send me the link of the code again?
Thank you in advance, appreciated.
Please read the video description. The code has been posted as text.
@@tsisapik please there is no code in the description so please if you may send me the code on my email waelwbouazizi@gmail.com
@@tsisapik no code is looking there
what are the PWM pins and how are you supposed to connect them to pins 9 and 10?
Go here to find out what the motor controller PWM inputs are www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/. Look carefully at your Arduino board and look for two pins called 9 and 10 on the Arduino board ... you can't miss them.
tsisapik Thx. athat makes much more sense!
The links in description are not working
Yes ... those are NOT my links.
hi please i would like to know what component between the 5 sensors and the arduino card is it a clculator which solve operation and send it to arduino card!!!
Hello ... the five sensors are directly connected to the Arduino board. The signals sent by the sensors determine the behavior of the robot - turn left, turn right or go straight.
Links dont work, maybe can you repost them?
Please read video description. Code is posted as text in one of my comments.
components list please..specially name the componnet u used for holding the sensor
Assuming you have the same sensors. Dollar store plastic cutting board cut into strips (I used a metal snips) with holes bored at the center to center distance of the sensor (laid side by side). 1/2 inch alum angle bars to hole the plastic strip. Necklace beads (I raided the kid's junk drawer) as spacers to hold the sensors in place. I used 3mm screws, nuts and washers to hold everything together. You can also you a plastic ruler or even wood in lieu of the dollar store cutting board strips. Look around your house ... I'm sure something will come up. Have fun!
wht wud b distance between each sensors ??
i means each sensor module
Get hold of the sensors and measure center to center. I do not know if the sensors you get are the same ones I used - be off 1 mm and they will not fit properly. FYI ... I have several strips used for line following robots. A strip with the sensor in the middle (like this one) and strips with sensors to the side of the line - for two sensor line followers - experiment. Use narrow lines, wide lines. Vary the angle of the curve. Use different geared motors for different speeds. When testing on a table, be prepared to catch the robot in case it jumps the line while calibrating.
Search Ebay for Arduino IR sensor ... get the ones that look like the ones in the video.
what is the black component in the bottom of your car ??.Thank you :)
That is a Battery Eliminator Circuit or BEC for short. It converts the Lipo voltage of 7.4V (2S) or 11.3V (3S) to a regulated 5V that powers both the Arduino shield and motor controller. Using a BEC makes sure your power supply is constant and steady.
Do you use the Lipo voltage of 7.4V to power the motor controller L298N or just use 5v ?
Lipo provides 7.4V power to the BEC. BEC provides 5V power to the Arduino shield and motor controller.
i have a others question about the code, how can i tune the kp kd ki in arduino code ??, thank you :))
For this robot, the P, I and D values are inputted on three separate lines on the sketch. Put a table together. Starting with all zeros, input the values, save compile and upload then record the robot behavior. At some combination of values, your robot will transform from a lazy drunk hunk of metal and plastic to a very intelligent predicable piece of engineering.
Can you please provide the code.
The link given in description is not working.
If you can share the code then it will be very helpful.
Hoping to hearing from you soon.
I hope you read the video description saying the link is down? The code in text should in one of my posts - for me is one down from your post.
I want the connections of the robot
I am not able to open your link
Yes ... those are NOT my links.
excelente proyecto
Thank you!
Tendras el codigo ?
which battery did you use?
Battery is a 2S Lipo 7.2V
where in the code do i change values of p i and d
wat to do if we want to make dis robo move at a faster speed??....coz it works pretty ...how to change d constants???like varying d constants w.r.t speed??
Easiest would to change the code to increase the speed .... but even then, it will not be a lot faster. Second is to use a different motor with less gear reduction - reduce by half and the speed is twice - maybe even fabricate your own using DIY gear sets. Third is to use larger diameter wheels - twice the circumference twice the speed.
tsisapik thanks man
Code please
From where did you get the chasis
+SAYAK BHAR ... The frame is one of two plastic pieces for the IR avoidance robots. I bought this kit from Ebay but the kit is available in online stores where Arduino robotic kits are sold.
Can u help me how to conect wire between L298, arduino and source power, thanks!!
From the video links ...Connections
Connect the 5 digital IR sensors to the analog inputs (you can still read digital values from analog inputs).
Connect the Left motor pins to digital pins 4 and 5
Connect the Right motor pins to digital pins 6 and 7
Connect the PWM pins to pins 9 and 10
Look closely at the code itself to confirm the connections. Power would be 5V to the Arduino input and motor controller input. For the motor controller, make sure the jumper is set for the correct voltage.
If the motors move in the wrong direction interchange the motor polarity and not the code.
Why do you have this line of code in your setup?
int sensor[5]={0, 0, 0, 0, 0};
Can you send me the code ? I don't knwo why i can't access the website
Here's my e-mail maeh5.contact@gmail.com
Thank you soo much !
@Boma Worst It's called an array, and it is used to store the sensor values here.
Did you read the video description on where to find the code?
Can you please tell me..where's the PWM pins ???
Xtrm Proloy pwm pins are marked with ~ symbol on your arduino board
The wires don’t clear in video
Where is the code?
Can I use L293D for motors ?
"The L293D is a 16-pin Motor Driver IC which can control up to two DC motors simultaneously, in any direction." ... so yes it can drive DC motors. dzone.com/articles/driving-a-dc-motor-with-an-arduino-and-the-l293d-m
why didn't you use value of sensor[3]????
u used sensor[4] two times....
can you please explain me why?
Simple - I do not need a serial interphase to look at the data from the sensors. The sensors I use allow me to adjust sensitivity for proper performance. That makes tuning 100x easier don't you think?
ok ...i have a question..please help me in this.....
which value we are getting for which color.....the sensor i have it's giving 1 for white and 0 for black........is it ok to use this code ?
I also have a question ... did you try using the sensors you described? There are so many things that can go wrong with robots. Sensors would definitely be one, You'll never know unless you experiment true robot maker dude. This is part of the fun of robot making. If it does not work initially, step away and review the steps you made making sure each step was done correctly.
What is the name of the yellow module conected with 5 sensor ???
That is a DIY bus bar ... simplifies the signal wire connections to the Arduino board. Positive and negative to all five sensors via two wires from the Arduino.
How the battery get connected
Good day! :) How to change code if I'll use CNY70 Optical sensor and l293d motor driver? Thank you.
Sorry, I do not have the sensor you mentioned. If it can provide the correct input signals to the board as it crosses the black line, then it should work without changing the code.
This only works for motor speed of 90/100(pwm)..... 6v motors...... above this value the motors gets out of line with hard left and right..... motors used here has very low torque. Thats why it doesnot follow tracks while moving at higher speeds.
Would be nice if you had videos to illustrate your point. The motors used for these and other projects I have made are geared motor set ups meaning, while the actual motor may be low torque, the gearing increases the torque at the expense of speed. FYI ... this is the fastest speed I could make the code to produce I can't go higher unless i use less reduction. While the sensors do exceed the lines, the robot gets back on track. If you notice carefully, both sides of the curve are not the same - one side has a more acute initial curve than the other - this is intentional specifically to test performance - but does not seem to adversely affect tracking capabilities.
tsisapik i have used the same plastic gear motors you had used....
I have a lot of RC model flying buddies on RUclips ... we have a saying ... if there ain't a vid, it didn't fly.
Can you share the code this one.. I’m going to download .. but couldn’t download it
Did you read the video description on where to find the code?
i make a line follower of 5 ir sensor withe L293 motor driver and put this code but my robot not work . i truble in connection of motor driver, ,,,,, my motor driver is different from your but l293 and not present there are in pw pins so where me connect pw pins 9 and 10 please help me
Research the pin outs for the L293 and how they would normally be connected to an Arduino. I have looked at this once and the connections are the same even if the unit's layout differs. Else, use the same controller.
i just have four sensor sir, Please share just with 4 sensor and schematic, Please
Apologies ... the code was written for five sensors. Get a fifth sensor ASAP!
you did not use sensor 3 and 5 in your code?
Did you read the code?
tsisapik yes sir i did
Good catch ... first "4" in the sensor read routing should be "3" - code still works because of the last "4" sensor read. but could be more accurate with the "3".
tsisapik sir, can you tell me how the robot will turn, I mean if (error =5 and kp=0.2) then (pid value=5×0.2=1). Now left motor=100+1 and right motor =100-1. With such small value, i dont think that it can make a turn? Correct me if I'm wrong
Robot does turn ... how is that possible?
Wonderful
Here i m giving it 24 V 15000mAh to ckt.. bt i have put voltagee regulator to aurdino so dat it wil supply 9 v to aurdino
I m using geared motors
Sorry for the delayed response ... try reducing your voltage to 5V ... I used a dropping resistor made of nichrome wire which I later took out. You could also vary speed by changing the PWM from 256 to whatever you want in the code itself.
Apart from kp ,kd, ki do I need to change any value?
Hmmm I think I tweaked the PW section to make the robot run faster ... but has nothing to do with making the robot work.
Will this code work for tcrt5000 sensor ?
Maybe, maybe not ... check the specs, make the correct holder and make sure you are able to calibrate the sensor unit properly ... you're on your own! Good Luck!
Please where is the program code?
Code posted as text in my sticky post. Follow instructions and good luck!!!
Link you provided have problem
Yes ... those are NOT my links.
@@tsisapik can you send the code if you got it,...jayanthasaranga@gmail.com...please send.....link was not working ...i don't know why...................Email- jayanthasaranga@gmail.com
can you send the code if you got it,...jayanthasaranga@gmail.com...please send.....link was not working ...i don't know why...................Email- jayanthasaranga@gmail.com
Code link not working
Did you read the video description on where to find the code?
Hello, the website can't be opened. Can you send me the code?please
my Email is 3113931778@qq.com thank you very much.
Read the video description please.
Hi! Can you show me circuit schematic and Printed circuit with 6 IR array sensor?
Sure thing ... read the video description until you get to the links and go to the links.
i needs schematic circuit 6 IR array sensor. I access the link but i don't see circuict.
There are only five sensors. Where did you see six?
now i want to use 6 sensors line not 5 sensors, can you give me the schematic diagram of the 6 sensors line follower?