taznmagic
Published © CC BY

Fabrizzio and Casey Arduino Car

We designed a car that was able to sense objects and turn to avoid them.

IntermediateShowcase (no instructions)3,558
Fabrizzio and Casey Arduino Car

Things used in this project

Hardware components

Constantly rotating servo motors
×2
Arduino UNO
Arduino UNO
×1
Wheels
×2
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
The amount you will need will vary depending on your design
×50
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LED (generic)
LED (generic)
×1

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

The Schematic

Code

Full car photo

C/C++
It is the car we built and it works using ultrasonic sensors and motors
No preview (download only).

Robot Code

C/C++
This is the code for the robot
#define trigPin 12
#define echoPin 13

int n; 
int duration, distance;

int lightPin = 0;  //define a pin for Photo resistor
int threshold = 250;

String readString;

#include <Servo.h> 
Servo myservo1;  // create servo object to control servo 
Servo myservo2;

void setup() {
  Serial.begin(9600);
  myservo1.attach(8); // assigns the servo to a pin
  myservo2.attach(9);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(3, OUTPUT);
    Serial.begin(9600);  //Begin serial communcation
    pinMode(11, OUTPUT);
   
}

void loop() {
  digitalWrite(trigPin, HIGH);
  _delay_ms(500);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
        
  if (distance < 40) { // this is the distance which the rover has to stop
   digitalWrite(3,HIGH);
    myservo1.write(n); // controls the direction of the motors
    myservo2.write(180-n);
   delay(1000);  // how long the wheels spin
   myservo1.write(n);
   myservo2.write(90-n);
   delay(500);
}
  else { // what the rover will do if it doen't sense anything
   digitalWrite(3,LOW );
    myservo1.write(180-n);
    myservo2.write(n);

     if(analogRead(lightPin) > threshold ){    
        digitalWrite(11, HIGH);
        Serial.println("high");
            digitalWrite(11, HIGH); 
delay(500);                   
digitalWrite(11, LOW);    
delay(50);                    
}
         
    else{
        digitalWrite(11, LOW);
        Serial.println("low"); 
    }

    delay(100);
    ;
}
}  

Credits

taznmagic
0 projects • 1 follower

Comments