Buzz Away

by 704597 in Circuits > Arduino

109 Views, 0 Favorites, 0 Comments

Buzz Away

IMG_3418.jpg

This project is a sensor that detects people or anything in front of it

Supplies

IMG_3410.jpg
  • Arduino
  • Wires
  • Two different colour LEDs
  • Switch
  • Distance sensor
  • Buzzer
  • Two 330 resistors
  • Breadboard

Leds

IMG_3411.jpg
IMG_3412.jpg

Plug in the two LEDs to the side and plug in the resistors to the negative sides of the LEDs. Then plug the LEDs into pin 2 and 3

Distance Sensor

IMG_3414.jpg
IMG_3415.jpg

Then have the distance sensor on the other side of the LEDs and plug it in the positive on Vcc and negative is Gnd. then plug in trig into 10 and echo into 9

Buzzer

IMG_3416.jpg

plug in the negative sides of the buzzer to the breadboard than the positive side into pin 13

Switch/power

IMG_3417.jpg

use the switch as the positive charge and use another wire for the negative

Code

Capture.PNG

const int trigPin = 10;

const int echoPin = 9;

int soundPin =13;


float duration, distance;


void setup() {

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);


Serial.begin(9600);

Serial.println("setup is complete");


pinMode (2,INPUT);

pinMode (3,INPUT);

pinMode (4,INPUT);

pinMode (soundPin, OUTPUT);

}


void loop() {

 // put your main code here, to run repeatedly:

digitalWrite(trigPin, LOW);

delayMicroseconds(2);


digitalWrite(trigPin, HIGH);

delayMicroseconds(10);



digitalWrite(trigPin, LOW);


duration = pulseIn(echoPin, HIGH);


distance = (duration*.0343)/2;


Serial.println(distance);

 delay(100);



if ((distance > 20) && (distance < 100)) {

  digitalWrite(3,HIGH);

 } else {

  digitalWrite(3,LOW);

}


if ((distance > 0) && (distance < 45)) {

  digitalWrite(2,HIGH);

 } else {

  digitalWrite(2,LOW);

}



if ((distance > 0) && (distance < 40)) {

  digitalWrite(soundPin,HIGH);

  delay (100);

  digitalWrite(soundPin,HIGH);

  delay (100);

  digitalWrite(soundPin,HIGH);

  delay(90);

  digitalWrite(soundPin,HIGH);

  delay(90);

  digitalWrite(soundPin,HIGH);

  delay(90);

 } else {

  digitalWrite(soundPin,LOW);

}


}