Learn to monitor and control your home & environment with self contained, inter-communicating microprocessors. Applications include ham radio, robotics, weather stations, model railroading, toys and more. - KK4HFJ
We just received a bunch of Gas Sensors from Hacktronics. These sensors include:
MQ2 - Flammable Gas & Smoke
MQ3 - Alcohol
MQ4 - Methane
MQ6 - LPG / IsoButane / Propane
MQ7 - Carbon Monoxide
MQ9 - Carbon Monoxide & Flammable Gas
Today's project is a smoke detector that turns on an LED when smoke concentrations exceed a certain level. We soldered the sensor to the carrier board, along with a sensitivity resistor and a 3 pin header. The carrier board pins are VCC (+5v), GND, and Out, which connects to A0 on our Arduino. We connected a LED to Pin 13 and Gnd as indication of an alarm state (smoke detected). See the video and the code we used:
Next step is a temp sensor for heat detection, and a relay for a siren.
// These constants won't change. They're used to give names// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int ledPin = 13; // LED connected to digital pin 13int sensorValue = 0; // value read from the sensorvoidsetup() {
// initialize serial communications at 9600 bps:Serial.begin(9600);
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
voidloop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// determine alarm statusif (sensorValue >= 750)
{
digitalWrite(ledPin, HIGH); // sets the LED on
}
else
{
digitalWrite(ledPin, LOW); // sets the LED off
}
// print the results to the serial monitor:Serial.print("sensor = " );
Serial.println(sensorValue);
// wait 10 milliseconds before the next loop// for the analog-to-digital converter to settle// after the last reading:delay(10);
}