0% found this document useful (0 votes)
6 views2 pages

Arduino Robot Control Code

The code controls a robot by reading sensor input and controlling motors. It sets pin modes, reads analog sensors for left, right and forward inputs, and writes pin outputs to control motors based on sensor thresholds.

Uploaded by

tanvishethia2022
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Arduino Robot Control Code

The code controls a robot by reading sensor input and controlling motors. It sets pin modes, reads analog sensors for left, right and forward inputs, and writes pin outputs to control motors based on sensor thresholds.

Uploaded by

tanvishethia2022
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Solution:

If the circuit is attached as per the given circuit diagram, then the following code will control the
robot.

int L = 0;
int R = 0;
int F = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(7, OUTPUT);
}

void loop()
{
L = analogRead(A0);
R = analogRead(A1);
F = analogRead(A2);

if (F > 400)
{
digitalWrite(7, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
delay(100); // Wait for 100 millisecond(s)
}
else
{
digitalWrite(7, LOW);
delay(100);
if (L > 400 && R > 400)
{
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
delay(100); // Wait for 100 millisecond(s)
}

else if (L > 400 && R < 400)


{
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
delay(100); // Wait for 100 millisecond(s)

else if (L < 400 && R > 400)


{
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
delay(100); // Wait for 100 millisecond(s)

else {
digitalWrite(10, LOW);
digitalWrite(9, LOW);
delay(100); // Wait for 100 millisecond(s)
}
}

The Tinkercad circuit is available at:


[Link]

You might also like