Register your child for In-person Robotics Workshop on 25th May at AMN, Round Rock, TX. Reserve a Seat today!

tect-corner-img

Object Detection Using Arduino and Embedded Learner Board

Do you want to get an alert if someone breaches the boundary? or

Do you want to know if something is present in the near vicinity?

This project will let you do this. Users will get a red alert if someone comes closer than a set limit. 

This project requires Embedded Learner Board, Arduino UNO, Ultrasonic Sensor and Mount, Servo Motor, Jumpers and a breadboard.

Use the following code to create this project:

Connections

ELB v2 Arduino UNO

+5V

5V

GND

GND

D7

8

D6

9

D5

10

D4

11

EN

12

RS

13

LED8

4

 

Ultrasonic Sensor Arduino UNO
VCC 5V
GND GND
TRIG 6
ECHO 7

 

Servo Motor Arduino UNO
VCC(Red) 5V
GND(Brown) GND
Signal(Orange) 5

 

Code:

#include <LiquidCrystal.h>

#include <Servo.h>

int trigPin= 6;

int echoPin= 7;

LiquidCrystal lcd = LiquidCrystal(13,12,11,10,9,8); 

long duration, distance;

Servo myservo;

int pos=0;

void setup()

{

  Serial.begin(9600);

  lcd.begin(16,2);

  pinMode(trigPin, OUTPUT);

  pinMode(echoPin, INPUT);

  myservo.attach(5);

}

void loop()

{

  for (pos = 0; pos <= 180; pos += 10) {

    myservo.write(pos);

    digitalWrite(trigPin,LOW);

    delayMicroseconds(2);

    digitalWrite(trigPin,HIGH);

    delayMicroseconds(10);

    digitalWrite(trigPin, LOW);

    duration = pulseIn(echoPin,HIGH);

    distance =(duration*0.0343)/2;

    lcd.print(“Distance in CM”);

    lcd.setCursor(0,1);

    lcd.print(distance);

    lcd.setCursor(1,0);

    delay(800);

    lcd.clear();

    if (distance<15){

      digitalWrite(4, HIGH);

    }

    else{

      digitalWrite(4, LOW);

    }                      

  }

  for (pos = 180; pos >= 0; pos -= 10) {

    myservo.write(pos);              

    digitalWrite(trigPin,LOW);

    delayMicroseconds(2);

    digitalWrite(trigPin,HIGH);

    delayMicroseconds(10);

    digitalWrite(trigPin, LOW);

    duration = pulseIn(echoPin,HIGH);

    distance =(duration*0.0343)/2;

    lcd.print(“Distance in CM”);

    lcd.setCursor(0,1);

    lcd.print(distance);

    lcd.setCursor(1,0);

    delay(800);

    lcd.clear();

    if (distance<15){

      digitalWrite(4, HIGH);

    }

    else{

      digitalWrite(4, LOW);

    }                        

  }

}