Skip to main content

Ultrasonic pulse emitting bot that detects Obstacle Collision using Ultrasonic Sensor


Using an Arduino I created a bot that detects obstacles in a 25 cm radius. The code rotates the geared DC motor using the Motor Driver Shield anti-clockwise. This allows the chassis to rotate and move away from the obstacle. This project may drastically change the way we look at Car automation. 






#include <AFMotor.h> //import your motor shield library
#define trigPin 12 // define the pins of your sensor
#define echoPin 13 
AF_DCMotor motor1(1,MOTOR12_64KHZ); // set up motors.
AF_DCMotor motor2(2, MOTOR12_8KHZ);

void setup() {
  Serial.begin(9600); // begin serial communitication  
  Serial.println("Motor test!");
   pinMode(trigPin, OUTPUT);// set the trig pin to output (Send sound waves)
  pinMode(echoPin, INPUT);// set the echo pin to input (recieve sound waves)
  motor1.setSpeed(105); //set the speed of the motors, between 0-255
motor2.setSpeed (105);  
}

void loop() {

   long duration, distance; // start the scan

  digitalWrite(trigPin, LOW);  
  delayMicroseconds(2); // delays are required for a succesful sensor operation.
  digitalWrite(trigPin, HIGH);

  delayMicroseconds(10); //this delay is required as well!

  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;// convert the distance to centimeters.
  if (distance < 25)/*if there's an obstacle 25 centimers, ahead, do the following: */ {   
   Serial.println ("Close Obstacle detected!" );
Serial.println ("Obstacle Details:");
Serial.print ("Distance From Robot is " );
Serial.print ( distance);
Serial.print ( " CM!");// print out the distance in centimeters.

Serial.println (" The obstacle is declared a threat due to close distance. ");

Serial.println (" Turning !");
    motor1.run(FORWARD);  // Turn as long as there's an obstacle ahead.
    motor2.run (BACKWARD);

}

  else {
   Serial.println ("No obstacle detected. going forward");
   delay (15);
   motor1.run(FORWARD); //if there's no obstacle ahead, Go Forward! 
    motor2.run(FORWARD);  
  }  
  }

Comments

Post a Comment

Popular posts from this blog

Recommender System using Python

Recommender systems are everywhere. Amazon recommends buys we like, google recommends searches, Youtube recommends systems and Facebook recommends people. All of these implementations describe Recommender Systems. There are 2 types of Recommender Systems. Collaborative Systems - Systems that recommend information based on what you like and what the others like. Content Based Systems- Based on what you have viewed This is a simple ML based recommender System in python. It uses the LightFM library as the dataset import numpy as np from lightfm import LightFM from fetch_lastfm import fetch_lastfm data = fetch_lastfm() model = LightFM( loss = ' warp ' ) model.fit(data[ ' matrix ' ], epochs = 30 , num_threads = 2 ) # Get recommendationns function def get_recommendations ( model , coo_mtrx , users_ids ): n_items = coo_mtrx.shape[ 1 ] for user in users_ids: # TODO create known positives # Artists the model pred...

Why online learning needs AI augmentation

With a large portion of schools having moved to online based learning through platforms like Zoom and Microsoft Teams, students are required to grasp concepts in a one-dimensional online medium as opposed to a constructive and collaborative class environment. Being a student during the pandemic, I have first hand experience with the mundane manner of teaching- and why we need to augment this with Artificial Intelligence algorithms. In a classroom, teachers can somehow manage to personalise some parts of learning or pay attention to weak students. However, in an online medium, with all the latency issues and network constraints, also moving in a general pace can be tough. Therefore for online learning,AI can be key, by providing a personalised learning path for the students. Using algorithms like NLP ( Natural Language Processing ), the online class can be transcribed according to the student's intellectual levels. AI, in this case, can make a specific-tailored learning path ...

Making AI Play Games

The Artificial Intelligence era has started only a while ago and it is drastically augmenting and amplifying our lives But in this sphere of development, the developers have had a big problem to test their AI. This is where great minds like Elon Musk step in and create adroit and efficient resources to test the Intelligence that we create. His vision and aspiration led to the start of OpenAI, a free open source library and a company specializing in research. They create toolkits for Deep Learning developers like us to deploy models and make AI play games. This helps us to analyze the power of the intelligence by simulating game environments.  OpenAI provides enthusiasts with 2 toolkits to work with Gym - Toolkit for comparing and developing deep reinforcement learning algorithms... Universe - A collection of gym environments to train and measure an AI's general intelligence... Today we are going to write a simple script in python to help build a ...