0% found this document useful (0 votes)
13 views1 page

Maze

This code controls a robot with 4 motors using an ultrasonic distance sensor on analog pin A4. It drives all motors forward at 80% speed by default, but reduces speed to 50% if the sensor reads 240. It then performs left and right spins depending on the sensor reading.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

Maze

This code controls a robot with 4 motors using an ultrasonic distance sensor on analog pin A4. It drives all motors forward at 80% speed by default, but reduces speed to 50% if the sensor reads 240. It then performs left and right spins depending on the sensor reading.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <ATX2.

h>

void setup()
{
OK(); // ATX2 initialize
delay(2000); //wait for 5 seconds
}

void loop()
{
int dis=analogRead(A4); //Define A4 sensor as Distance sensor
motor(1,80);
motor(2,80);
motor(3,80);
motor(4,80);

if(dis =analogRead(A4) == 240) //Read and check the sensor value analog 4
{

motor(1,50);
motor(2,50);
motor(3,50);
motor(4,50);
delay(100);

motor(1,50);
motor(2,50);
motor(3,-50); //Spin Right
motor(4,-50);
delay(600);

motor(1,50);
motor(2,50);
motor(3,-50); //Spin Right
motor(4,-50);
delay(600);
}
else ()
motor(1,-50);
motor(2,-50);
motor(3,50); //Spin Right
motor(4,50);
delay(600);

}
}

You might also like