Dr. Kayarvizhy N Dr. Kayarvizhy N

General

Arduino – Fire alarm (LED and Buzzer)

August 17, 2016All posts

¨Instructions:

¨Download NewPing library from here: NewPing

¨Put the “NewPing” folder in “libraries\”.

¨In the Arduino IDE, create a new sketch (or open one) and select from the menubar “Sktech->Import Library->NewPing”.

¨Comment it all out like this in NewPing.cpp:

¨/*
#if defined (__AVR_ATmega32U4__) // Use Timer4 for ATmega32U4 (Teensy/Leonardo).
ISR(TIMER4_OVF_vect) {
#else
ISR(TIMER2_COMPA_vect) {
#endif
if(intFunc) intFunc(); // If wrapped function is set, call it.
}*/

¨ 

#include<SoftwareSerial.h>
#include <NewPing.h>

int sensorPin = A0; // select the input pin for the LDR
int sensorValue = 0; // variable to store the value coming from the sensor
int led = 9; // Output pin for LED
int buzzer = 12; // Output pin for Buzzer
void setup() {
// declare the ledPin and buzzer as an OUTPUT:
pinMode(led, OUTPUT);
pinMode(buzzer,OUTPUT);
Serial.begin(9600);
}
void loop()
{

sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if (sensorValue < 100)
{
Serial.println("Fire Detected");
Serial.println("LED on");
digitalWrite(led,HIGH);
tone(buzzer,2000,1000);
delay(1000);
}
digitalWrite(led,LOW);
digitalWrite(buzzer,LOW);
delay(sensorValue);
}

 

0 0 votes
Article Rating
0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Oldest
Newest Most Voted