September 2016
Intermediate to advanced
495 pages
9h 37m
English
Now that the hardware for our project is ready, we can write down the code for the project so that we have a usable alarm system. The goal is to make the buzzer produce a sound whenever motion is detected and also to make the LED flash. However, whenever the button is pressed, the alarm will be switched off.
Here is the complete code for this project:
// Code for the simple alarm system // Pins const int alarm_pin = 5; const int led_pin = 6; const int motion_pin = 7; const int button_pin = 12; // Alarm boolean alarm_mode = false; // Variables for the flashing LED int ledState = LOW; long previousMillis = 0; long interval = 100; // Interval at which to blink (milliseconds) void setup() { // Set pins to output pinMode(led_pin,OUTPUT); ...Read now
Unlock full access