/*Problem 2 : Design an Adaptive Cruise Control (ACC) system that maintains
a safe distance from the car in front while also providing basic
lane-keeping assistance. This project requires dynamic speed adjustments
based on the distance to other vehicles and simple lateral movement detection.
Ultrasonic/LIDAR Sensor: Measure the distance to the car in front.
Infrared or Camera Module (simulated): Detect Lane markings.
PWM Motor Control: Adjust throttle for speed control.
Servo Motor or LED: Provide simple steering adjustments for lane-keeping.
*/
#define PIN_TRIG 3
#define PIN_ECHO 2
#define ir 13
#define led 7
int ir_value=0;
void setup()
{
Serial.begin(9600);
pinMode(PIN_TRIG, OUTPUT);
pinMode(PIN_ECHO, INPUT);
pinMode(led, OUTPUT);
pinMode(ir, INPUT);
}
void loop()
{
digitalWrite(PIN_TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG, LOW);
int duration = pulseIn(PIN_ECHO, HIGH);
int distance=duration/58;
ir_value=digitalRead(ir);
if(ir_value==HIGH)
{
digitalWrite(led, HIGH);
Serial.println("Adjust throttle to drive on a lane");
}
if(ir_value==LOW)
{
digitalWrite(led, LOW);
Serial.println("Vehicle on the lane");
}
delay(1000);
}