Arduino Controlled Security Lights Also Scary Prop for Halloween

1,009

18

2

Posted in TechnologyArduino

Introduction: Arduino Controlled Security Lights Also Scary Prop for Halloween

About: HI i am currently studying in class 11...in love with computes and AI..

If you are lost in a jungle and don't know what to do to notify you about an animal and like i wold do you took your arduino kit then this is a ultrasonic oject ditector which will tell you about any animal near......

Step 1: Materials Required

The stuffs required are

  1. arduino
  2. buzzer(local shop)
  3. led(local shop)
  4. switch(local shop)
  5. bread board
  6. jumper wire( male to male)
  7. resistors(according to the leds used)

Step 2: Connect the Main Parts

  1. connect the switch in the middle as shown
  2. connect the led so that they have a common ground keep a pin gap between two leds use 2 green, 2 yellow,4 red.
  3. connect the buzzer as shown
  4. connect the proximity sensor according to the pins

Step 3: Wiring

wire it according to the image....... or according the video......

Step 4:

#define trig 12

#define echo 13

#define power_pin 11

#define buzzerReset A0

#define buzzer 10
int ledS[] = {2,3,4,5,6,7,8,A1};

boolean alarmTrig = false;

boolean ledFlash = false; void setup()

{ Serial.begin(9600);

pinMode(trig,OUTPUT);

pinMode(echo,INPUT);

pinMode(power_pin,OUTPUT);

pinMode(buzzerReset , INPUT);

pinMode(buzzer , OUTPUT);

digitalWrite(power_pin,HIGH); // As because there is no external power source so we need the pin 1 as HIGH

for(int i=0;i<8;i++)

pinMode(ledS[i] , OUTPUT);

} void loop()

{

double distance = hc_sr04(trig, echo); // calls hc_sr04() and get the distance form it

Serial.print(distance); // print the distance Serial.println("cms ahead"); int indicate = map(constrain(distance , 1,20) , 1 , 20 , 0 , 8);

if(ledFlash == false)

{

for(int i = 0 ; i<=indicate ; i++) {

digitalWrite(ledS[i] , LOW);

}

for(int i=indicate ; i<=8 ; i++)

{

if(i == 0)

alarmTrig = true;

digitalWrite(ledS[i] , HIGH);

}

} if(alarmTrig == true)

{

activate_alarm();

}

if(digitalRead(buzzerReset) == HIGH)

resetBuzzer(); } void resetBuzzer()

{ alarmTrig = false;

ledFlash = false;

digitalWrite(buzzer , LOW);

}

double hc_sr04(double trigPin , double echoPin)

{

double duration, distance; // This procedure is mentioned in the datasheet of HC-SR04 attached

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH); //Check out the refernce to know about this function......select "pulseIn"

then press Ctrl + Shift + F

distance = ((duration/1000000)*33000)/2; // distance = speed * time/2

return constrain(distance,0,200); // dont know what constrain is just select it and Ctrl + Shift + F

}

void activate_alarm()

{ ledFlash = true; analogWrite(buzzer, 255);

for(int i=0;i<8;i++)

digitalWrite(ledS[i] , HIGH);

delay(100); analogWrite(buzzer , 150);

for(int i=0;i<8;i++)

digitalWrite(ledS[i] , LOW);

delay(100);

}

Share

    Recommendations

    • Woodworking Contest

      Woodworking Contest
    • Microcontroller Contest

      Microcontroller Contest
    • Casting Contest

      Casting Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    2 Comments

    thanks your instructables are also awesome......................