Arduino watches for a kitchen catastrophe

Hardware Design

These instructions lead to the setup shown in Figure 8: I connect the buzzer, or the base of the transistor if you are using a siren, to pin 13 with a 1K resistor. You can also set up the smoke sensor as a generic analogical sensor. The final product is a homemade detector device like the one shown in Figure 9.

Figure 8: Connection schematics for the fire alarm.
Figure 9: A working DIY home fire alarm.

In the second example, which you can see in Figure 10, connect the fluid detector as a digital device and the methane detector in a fashion similar to the smoke detector. The difference is you're going to mount an Ethernet shield on top to upload the data to the web. The Ethernet shield sits on top of the Arduino, and you can access all the I/O pins through the shield; additionally, you can connect the device to your network.

Figure 10: Schematics for the monitoring system.

Programming

Listing 1 shows how to monitor for the presence of smoke. If the amount detected exceeds a certain limit, the program activates the alarm, sending a HIGH signal to the designated pin.

Listing 1

DIY Fire Alarm

01 // Static Variables
02
03 int smokeSensor = A0;      // Smoke sensor pin
04 int buzzer =  13;       // Buzzer pin
05
06 // Dynamic variables
07 int smokeValue = 0;  // Value read in by the smoke sensor
08
09 void setup() {
10   // Initiates the buzzer pin as OUTPUT
11   pinMode(buzzer, OUTPUT);
12 }
13
14 void loop() {
15   // Read the analogical value from the sensor and store it as %
16   smokeValue = analogRead(smokeSensor);
17   smokeValue = map(smokeValue,0,1023,0,100);
18   // Short wait
19   delay(50);
20   // If the smoke level is too high, activate the alarm
21   if (smokeValue > 60) {
22     digitalWrite(buzzer, HIGH);
23   }
24   else {
25     digitalWrite(buzzer, LOW);
26   }
27 }

The second example (Listing 2) measures the analogical and digital values from the sensors and uploads them to a website. The data appears as a simple line on the IP address assigned to your web server, as shown in Figure 11.

Figure 11: The readings from the sensors are uploaded to a web page.

Listing 2

Monitoring Kitchen Hazards

01 // Libraries we need
02 #include <SPI.h>
03 #include <Ethernet.h>
04
05 // Define server MAC and IP
06 // ID of Ethernet module:
07 byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xFE, 0x70 };
08 // IP address assigned to the Arduino Ethernet Shield:
09 IPAddress ip(192,168,1,191);
10
11 // Starts the server on port 80
12 EthernetServer server(80);
13
14 // Static variables
15 int  liquidDetection= 2;   // Pin for the water sensor
16 int CO2Sensor = A0;       // Pin for the CO2  sensor
17
18 // Dynamic variables
19 int liquidState = 0;   // We'll assume there is no water or CO2 around to start with
20 int CO2Value = 0;
21
22 void setup() {
23   // Initializes the input pin for the liquid sensor
24   pinMode(liquidDetection, INPUT);
25   // Initiate the Ethernet connection and the server
26   Ethernet.begin(mac, ip);
27   server.begin();
28 }
29
30 void loop() {
31   // Read in the digital value for the presence of liquid
32   liquidState = digitalRead(liquidDetection);
33   // Read in the analogical value of CO2 and store it as %
34   CO2Value = analogRead(CO2Sensor);
35   CO2Value = map(CO2Value,0,1023,0,100);
36
37   // Listen for potential incoming clients
38   EthernetClient client = server.available();
39   if (client) {
40     // An HTTP petition ends with a blank line
41     boolean currentLineIsBlank = true;
42     while (client.connected()) {
43       if (client.available()) {
44         char c = client.read();
45
46         // Check if the HTTP request has finished or not
47         if (c == '\n' && currentLineIsBlank) {
48           // Send standard HTTP header
49           client.println("HTTP/1.1 200 OK");
50           client.println("Content-Type: text/html");
51           client.println();
52
53            client.print("KITCHEN MONITOR");
54            client.print(" => ");
55
56             // Print out value from the liquid sensor
57             client.print("[Presence of liquid");
58             client.print(" = ");
59             if (liquidState == 0){
60             client.print("No");
61             } else {
62             client.print("Yes");
63             }
64             client.print("]");
65
66             // Print the amount of CO2
67             client.print(" ; [CO2");
68             client.print(" = ");
69             client.print(CO2Value);
70             client.print(" %] ");
71
72             break;
73         }
74         if (c == '\n') {
75           // Start a new line
76           currentLineIsBlank = true;
77         }
78         else if (c != '\r') {
79           // Get a character
80           currentLineIsBlank = false;
81         }
82       }
83     }
84     // Give the server time to receive the data
85     delay(1);
86     // Close connection
87     client.stop();
88   }
89 }

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content