pythonpushover503
Published © GPL3+

Crime Detecting Robot

A robot that uses a ultrasonic sensor to emit light and sound to protect something

IntermediateShowcase (no instructions)125
Crime Detecting Robot

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Arduino UNO
Arduino UNO
×1
LED (generic)
LED (generic)
×3
Jumper wires (generic)
Jumper wires (generic)
×1
9V battery (generic)
9V battery (generic)
×1
9V Battery Clip
9V Battery Clip
×1

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Scissors, Free Fall
Scissors, Free Fall

Story

Read more

Code

Ultrasonic sensor Code

Arduino
Runs the robot
/*

*/
const int trigpin = 9;
const int echopin = 10;
const int buzz = 5;
const int led = 7;

long duration;
int distance;

void setup() {
  pinMode(trigpin, OUTPUT);
  pinMode(echopin, INPUT);
  pinMode(buzz, OUTPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600); 
}

void loop() {
   digitalWrite(trigpin, LOW);
  delayMicroseconds(2);
  
  digitalWrite(trigpin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigpin, LOW);
  
   duration = pulseIn(echopin, HIGH);
   distance = duration*0.034/2;
   
   Serial.print("Distance: ");
   Serial.println(distance);
    
    if(distance <= 25){
  tone(buzz, 900);
  delay(200);
  noTone(buzz);
  delay(0);
} 

 if(distance <= 25){
  digitalWrite(led, HIGH);
  delay(50);
  digitalWrite(led, LOW);
  delay(50);
}
}  

Credits

pythonpushover503
4 projects • 2 followers

Comments