/* 01010000011100100110111101110100011011110010000001000111 Smart Smoke Detector Created August 30, 2015 Modified August 30, 2015 by Anthony Garofalo (Proto G) Visit my YouTube channel here: https://www.youtube.com/channel/UCpTuKJrXFwybnpOG7HpTpZw Visit my Instructables page here: http://www.instructables.com/member/Proto+G/ _____ ______ _____ _______ _____ ______ |_____] |_____/ | | | | | | ____ | | \_ |_____| | |_____| |_____| 01010000011100100110111101110100011011110010000001000111 */ int SensorA0; int tinkerDigitalRead(String pin); int tinkerDigitalWrite(String command); int tinkerAnalogRead(String pin); int tinkerAnalogWrite(String command); int speakerPin = D0; int sensorValue; int threshold = 450; //Determine your threshold using the mobile Tinker application. Find the level at which the sensor detects smoke. void setup() { pinMode(0, OUTPUT);//Speaker Spark.variable("SensorA0", &SensorA0, INT);//Connect your smoke sensor to A0 //The following 4 lines are only needed for the mobile tinker application. Spark.function("digitalread", tinkerDigitalRead); Spark.function("digitalwrite", tinkerDigitalWrite); Spark.function("analogread", tinkerAnalogRead); Spark.function("analogwrite", tinkerAnalogWrite); } void loop() { sensorValue = analogRead(A0); // read the input on analog pin 0: if(sensorValue > threshold){ Spark.publish("Smoke"); digitalWrite(speakerPin, HIGH); delay(15000); //delay cascade to prevent too many texts sensorValue = analogRead(A0); if(sensorValue > threshold){ Spark.publish("Smoke"); digitalWrite(speakerPin, HIGH); delay(60000); } sensorValue = analogRead(A0); if(sensorValue > threshold){ Spark.publish("Smoke"); digitalWrite(speakerPin, HIGH); delay(120000); } sensorValue = analogRead(A0); if(sensorValue > threshold){ Spark.publish("Smoke"); digitalWrite(speakerPin, HIGH); delay(600000); } sensorValue = analogRead(A0); if(sensorValue > threshold){ Spark.publish("Smoke"); digitalWrite(speakerPin, HIGH); delay(600000); } digitalWrite (speakerPin, LOW); } delay(100); // delay in between reads for stability } //The following code allows you to still use the mobile Tinker application int tinkerDigitalRead(String pin) { int pinNumber = pin.charAt(1) - '0'; if (pinNumber< 0 || pinNumber >7) return -1; if(pin.startsWith("D")) { pinMode(pinNumber, INPUT_PULLDOWN); return digitalRead(pinNumber);} else if (pin.startsWith("A")){ pinMode(pinNumber+10, INPUT_PULLDOWN); return digitalRead(pinNumber+10);} return -2;} int tinkerDigitalWrite(String command){ bool value = 0; int pinNumber = command.charAt(1) - '0'; if (pinNumber< 0 || pinNumber >7) return -1; if(command.substring(3,7) == "HIGH") value = 1; else if(command.substring(3,6) == "LOW") value = 0; else return -2; if(command.startsWith("D")){ pinMode(pinNumber, OUTPUT); digitalWrite(pinNumber, value); return 1;} else if(command.startsWith("A")){ pinMode(pinNumber+10, OUTPUT); digitalWrite(pinNumber+10, value); return 1;} else return -3;} int tinkerAnalogRead(String pin){ int pinNumber = pin.charAt(1) - '0'; if (pinNumber< 0 || pinNumber >7) return -1; if(pin.startsWith("D")){ pinMode(pinNumber, INPUT); return analogRead(pinNumber);} else if (pin.startsWith("A")){ pinMode(pinNumber+10, INPUT); return analogRead(pinNumber+10);} return -2;} int tinkerAnalogWrite(String command){ int pinNumber = command.charAt(1) - '0'; if (pinNumber< 0 || pinNumber >7) return -1; String value = command.substring(3); if(command.startsWith("D")){ pinMode(pinNumber, OUTPUT); analogWrite(pinNumber, value.toInt()); return 1;} else if(command.startsWith("A")){ pinMode(pinNumber+10, OUTPUT); analogWrite(pinNumber+10, value.toInt()); return 1;} else return -2;}