STEMpedia
Published © CC BY

DIY Projects for Halloween to Make a Spooky Town

Make your own DIY Halloween Town for Halloween using some previous projects and a DIY PIR sensor activated jack-o’- lantern.

IntermediateFull instructions provided3 hours691
DIY Projects for Halloween to Make a Spooky Town

Things used in this project

Hardware components

evive
STEMpedia evive
×1
evive IoT Kit
STEMpedia evive IoT Kit
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Fritzing Diagram for Spooky Pumpkin

Code

Arduino Code for Spooky Pumpkin

Arduino
#include<evive.h>

#define relay_pin  3    //relay is connected to pin number 3 of evive
#define pir_pin    2   // relay is connected to pin number 2 of evive
#define buzzer_pin 46  // buzzer is internally connected to pin number 46 of evive

unsigned int val =0;       // variable for storing pir sensor value
unsigned int reading =0;

void setup() 
    {
        // put your setup code here, to run once:

         pinMode(pir_pin, INPUT);     // declare sensor as input
         pinMode(relay_pin,OUTPUT);   // declare buzzer as output
         pinMode(led_pin,OUTPUT);
     }

void loop()
    {
    
        // put your main code here, to run repeatedly:
        
        val = digitalRead(pir_pin);  // read input value
        if (val == HIGH) // check if the input is HIGH
             {    
              while(digitalRead(pir_pin) )
              {
                if(digitalRead(40)==HIGH)
                {
                  sound(); 
                }
                      
              }
                
             }
         else 
             {
                 digitalWrite(relay_pin, HIGH); // turn relay OFF
                 noTone(buzzer_pin);
                 delay(100);
             }

      }

 void sound()
    {
         int pitch = 260 + reading / 4;
         tone(buzzer_pin, pitch);

         digitalWrite(relay_pin, LOW);
         delay(100);
         digitalWrite(relay_pin, HIGH);
         delay(100);
         digitalWrite(relay_pin, LOW);
         delay(100);
         digitalWrite(relay_pin, HIGH);
         delay(100);
         digitalWrite(relay_pin, LOW);
         delay(100);
         digitalWrite(relay_pin, HIGH);
         delay(100);
         digitalWrite(relay_pin, LOW);
         delay(100);
         digitalWrite(relay_pin, HIGH);
         delay(100);     
   }

evive Library

C/C++
No preview (download only).

Credits

STEMpedia

STEMpedia

42 projects • 169 followers
STEMpedia blends theory with experiential learning by offering state-of-the-art technology, projects, tutorials, courses, and much more.

Comments