Introduction: 103 - Burglar Alarm
Here is another Instructable in the Spark Core series, for those of you who don't know this is a beginners series to get around with your Spark Core. From this Instructable, I'm going to raise the level a bit, and start building actual things with the Spark Core.
In this Instructable, I'm going to show you how to build a simple burglar alarm with your alarm. From this instructable, it's time to start writing actual code and not just use the tinker app or blink code. This is not a complex burglar alarm, but a simple one which detects any movement in front of it, and sounds a buzzer if any movement is noted.
So let's start with the instructable......
Step 1: Getting Started
Let's start with collecting all the components required to proceed with the tutorial. The component list is simple, all you need is -
- Spark Core
- Photo Resistor
- Buzzer
- Breadboard
- Wires
If you don't know what a Spark core is or need detailed instructions you can check out the spark core home page or you can check out my previous Instructables. Once you got all the components you are good to go with the next step.
Step 2: Photo Resistor
Let's start with the photoresistor, a photoresistor is a component whose resistance decreases when light is incident on it. It acts as a switch which is on when light falls on it, If you are familiar with an Arduino you can use a button example to get it to work.
If you are a beginner then follow the circuit and use the tinker app to read the pin to which the photoresistor is connected (I got it connected to pin 0). When you show some light in front of it, you should get a HIGH in the tinker app.
Step 3: Buzzer
Connecting the buzzer, is quite simple. All you have to do is connect the negative end to ground and the positive to a digital pin of your choice. You can use the tinker app to set it ON and OFF.
Next let's start writing the code in the next step.
Step 4: Code
After getting the photoresistor and the buzzer connected time to upload the code, if you don't know how check out tutorial 101. Make sure you have got the pins right in the code to your circuit.
Code
<p>int lightPin = 2; //define a pin for Photo resistor<br>int ledPin=1; //define a pin for Buzzer int val = 0;</p><p>void setup() { pinMode( ledPin, OUTPUT ); pinMode( lightPin, INPUT ); }</p><p>void loop() { val = digitalRead(lightPin); if(val == LOW){ // If Photo resistor is low sound buzzer digitalWrite( ledPin, HIGH); } else { digitalWrite( ledPin, LOW); // If not Keep it Quite } }</p>
Step 5: Finishing
After you have completed a project, you can keep it parallel to a light source. And if there is any movement in front of it buzz.
In the next instructable in the series, I will show you how to boost up this circuit and enable it to send notifications to an android phone if the alarm is triggered (Let's connect the spark core to the internet).
If you have any doubts, problems or want to help me add something leave a comment below.