MisterBotBreak
Published

How to Make an Anti-Collision System

This project will show you how to make an anti-collision system.

BeginnerFull instructions provided12 minutes499
How to Make an Anti-Collision System

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Collision

Arduino
int trig = 12; 
int echo = 11; 

void setup() 
{ 
  pinMode(trig, OUTPUT); 
  pinMode(echo, INPUT); 
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);  
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  
  Serial.begin(9600); 
}
void loop() 
{ 
  digitalWrite(trig, HIGH); 
  delayMicroseconds(10); 
  digitalWrite(trig, LOW);
   
  
  int receiver = pulseIn(echo, HIGH); 
  int cm = receiver / 58; 
  
  if(cm<28){
    digitalWrite(2,1);
  }
  else{
    digitalWrite(2,0);
  }
  
  if(cm<22){
    digitalWrite(3,1);
  }
  else{
    digitalWrite(3,0);
  }
  
  if(cm<18){
    digitalWrite(4,1);
  }
  else{
    digitalWrite(4,0);
  }
  
  if(cm<12){
    digitalWrite(5,1);
  }
  else{
    digitalWrite(5,0);
  }
  
  if(cm<6){
    digitalWrite(6,1);
  }
  else{
    digitalWrite(6,0);
  }

  delay(200); 
}

Credits

MisterBotBreak

MisterBotBreak

37 projects • 66 followers
I love electronic and I make explanatory project on how to control sensors.

Comments