Hello guys!
I have this project on my school I'm working on and it's a line following robot. I already have the materials and base, what's missing is the code.
Please help me for a code on my project using Arduino Uno with 2 TCRT5000 sensors and 2 modified servo motors.
Thanks!
Search the forum for "line follower", you'll get a lot of threads on that topic.
If this doesn't help, come back with a more precise description of your project and problems.
I have already built a robot.
These are the parts I've used.
- Arduino UNO
- 2 TCRT5000 IR Sensors
- 2 Modified Servos
The Problems is the code, pls help.
We help here. However we do not do it for you.
You post what you have and we will point out where you have gone wrong.
If this is a school assignment you are supposed to do it yourself are you not?
Here is my code. Pls check is something is wrong
// 2 continuous rotation servos
// 2 TCRT5000 sensors connected to analog inputs = line following sensor
#include <Servo.h>
Servo leftservo; // create servo object to control a servo
Servo rightservo; // create servo object to control a servo
int rawtcrt[2]; //these are the raw ADC values from the line follow sensor
/*
rawtcrt[0] = left sensor
rawtcrt[4] = right sensor
*/
int bwtcrt[2]; //these are basically booleans we will use 0 for white and 1 for black
int i;
int colorThreshold = 400; // < 400 = white / > 400 = black
void setup()
{
leftservo.attach(2); // attaches the servo on pin 2 to the servo object
leftservo.write(90); // stop servo
rightservo.attach(3); // attaches the servo on pin 3 to the servo object
rightservo.write(90); // stop servo
}
void loop()
{
checkLineSensor(); //1 = seeing black 0 = seeing white
forward();
if (bwtcrt[1]==1)
{
forwardleft();
}
if (bwtcrt[3]==1)
{
forwardright();
}
if (bwtcrt[4]==1)
{
right();
}
if (bwtcrt[0]==1)
{
left();
}
}
void checkLineSensor()
{
for (i=0;i<5;i++)
{
rawtcrt*=analogRead(i);*
_ if (rawtcrt*<colorThreshold)_
_ {_
_ bwtcrt=0;
}
else{
bwtcrt=1;
}
}
}
void forward(){
leftservo.write(70); // go straight forward*
* rightservo.write(110);
}
void forwardleft(){
leftservo.write(85); // go forward left*
* rightservo.write(102);
}
void forwardright(){
leftservo.write(78); // go forward right*
* rightservo.write(95);
}
void left(){
leftservo.write(110); // go left*
* rightservo.write(110);
}
void right(){
leftservo.write(70); // go right*
* rightservo.write(70);
}*_
Oh dear you haven't read the rules about posting code.
Read the how to use this forum post at the top of this list and edit you last post to include the code tags ( </> )
Also we need to see all your code not just part of it.