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

Impact of Chatbots on Human Driven sectors of business

Chatbots are Machine Learning and Deep Learning powered programs that can conduct meaningful conversations. Most of them use technical attributes like Natural Language Processing and Context Analysis to converse with a human or another chatbot. The bot is programmed to self-learn as it is introduced to supplementary dialogues and words. In consequence, as a chatbot receives new voice or textual dialogues, the number of inquiries that it can reply and the accuracy of each response it gives increases. A Chabot can converse with the user through self-embedded messaging platforms like Facebook Messenger or through various flagship Assistants such as Google Assistant, Siri or Amazon Alexa. Nowadays, chatbots are being deployed in fields where their use clearly seemed to be obvious. Firms engaging in Financial Planning, Investment Management and Expense Tracking could reap a wide array of benefits when they make use of this technology. They can have a lasting impact on human-driven sec...

Data Visualisation with Python : My course on Skillshare

Recently, I launched a class on Skillshare called " Intro to Data Visualisation with Python : Create Comprehensive Plots with Matplotlib and Numpy ". It's a class I sought to create as my flagship project for the summer of 2019 This class is all you need to visualise data with Python. It aims to teach the essentials required to visualise data with Matplotlib, a library for plotting in python. The class also covers NumPy in a brief manner, a scientific computing library that goes hand-in-hand with the visualisation capabilities provided by Matplotlib. We'll also work with CSV files with pandas. You'll also be getting the essential coding practices required to create these types of programs. To make the most out of this class, it is beneficial to have some prior programming experience ( preferably python ) but however, it's not necessary. An up-to-date system running Windows, MacOs or Linux with an installed version of python is recommended ( I  will provi...

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...