Project tutorial
Autonomous Car

Autonomous Car

This project is a self-driving car that is programmed to avoid obstacles and activate LED's while doing so.

  • 9,215 views
  • 0 comments
  • 14 respects

Components and supplies

Apps and online services

About this project

This is an autonomous car that we built for a robotics class. It is designed to avoid obstacles with an ultrasonic sensor and activate LED lights when the obstacles are detected and avoided.

Code

Autonomous CarArduino
This is the code used to make the car detect obstacles. There is another LED light that activates when lights are off. To make the front lights blink and have the reverse lights activate when backing up, uncomment the commented sections, however this may break something else in the code.
#define trigPin 12
#define echoPin 13
int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LightPin = 0;
int threshold = 980;
unsigned long previousMillis = 0;
const long interval = 1000;
int ledState = LOW;


int n;
long duration, distance;
String readString;

#include <Servo.h>
Servo myservo1;
Servo myservo2;

void setup() {
  Serial.begin(9600);
  myservo1.attach(8);
  myservo2.attach(9);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(LED5, OUTPUT);
}

void loop() {
  Serial.println(analogRead(LightPin));

  digitalWrite(trigPin, HIGH);
  _delay_ms(500);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1;

  unsigned long currentMillis = millis();

  if (analogRead(LightPin) > threshold && currentMillis - previousMillis > interval) {
    if (ledState == HIGH) {
      ledState = LOW;
      Serial.println("low");
    } else {
      ledState = HIGH;
      Serial.println("high");
    }
    digitalWrite(LED5 , ledState);

  }
    if (distance < 30) {
      //  digitalWrite(LED1,LOW);
      //  digitalWrite(LED2,LOW);
      //  digitalWrite(LED3,HIGH);
      //  digitalWrite(LED4,HIGH);
      myservo1.write(n);
      myservo2.write(180 - n);
      delay(1000);
      myservo1.write(n);
      myservo2.write(90 - n);
      delay(500);
    }
    else {
      // digitalWrite(LED1, HIGH);
      // digitalWrite(LED2, HIGH);
      // digitalWrite(LED3, LOW);
      // digitalWrite(LED4,LOW);
      myservo1.write(180 - n);
      myservo2.write(n);

    }
  }

Schematics

autonomouscar_X4t9VfPx5A.fzz
autonomouscar_X4t9VfPx5A.fzz

Comments

Author

Default
ByronSpars
  • 1 project
  • 1 follower

Additional contributors

  • Basic design of car and code by Nicki Godoff

Published on

December 5, 2017

Members who respect this project

Untitled 1 copy xrzurtxfgo34462862 3bfc 4a26 ac5a 56a52fd132636e549836 e4b3 414f b0f7 a7be4cba9f68 xrwrkpxxpw15319084 10207567903782576 5078654559332907709 nImage tzoufrlm9oMe logo hd6qv9z839PhotoPhoto

and 6 others

See similar projects
you might like

Similar projects you might like

Arduino Uno Autonomous Car

Project tutorial by hannahmcneelyy

  • 20,034 views
  • 2 comments
  • 28 respects

Biometric Car Entry - True Keyless Car

Project showcase by Rajeev Velikkal

  • 9,389 views
  • 9 comments
  • 44 respects

Fabrizzio and Casey Arduino Car

Project showcase by Team Fabrizzio and Casey's Robot Cars

  • 1,946 views
  • 0 comments
  • 2 respects

Turn your RC Car to Bluetooth RC car

Project tutorial by Prajjwal Nag

  • 20,675 views
  • 2 comments
  • 25 respects

Arduino 4WD RC Car

Project tutorial by Andriy Baranov

  • 34,275 views
  • 9 comments
  • 74 respects

Auto Ultrasonic Car

by Ishaq Yang

  • 27,225 views
  • 2 comments
  • 19 respects
Add projectSign up / Login