/* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include // Economie d'énergie #include const byte TRANSMITTER_PIN = 9; // Init RCSwitch RCSwitch mySwitch = RCSwitch(); // float temperature = 0.0; float pressure = 0.0; float pression = 0.0; float presiune = 0.0; int sensorValue = 0; int sensorValue2 = 0; int sensorValue3 = 0; int distance = 0; const int TrigPin = 2; const int EchoPin = 3; // ################# Barometre #### Adafruit_BMP085 bmp; // ##################### const unsigned long TIME = 512; const unsigned long TWOTIME = TIME*2; /******************************************************************/ void setup() { // Serial.begin(9600); mySwitch.enableTransmit(TRANSMITTER_PIN); pinMode(TrigPin, OUTPUT); pinMode(EchoPin, INPUT); // BMP if (!bmp.begin()) { // Serial.println("nu exita senzor compatibil BMP085 sau BMP180"); while (1) {} } } void loop() { // en premier pour la température barometre(); readSensors(); readPresence(); // printAll(); sendAll(); //Narcoleptic.delay(45000); // During this time power consumption is minimised(5000); delay(5000); } void sendAll() { sendValues(1111, temperature * 100); sendValues(2222, (int) (pression * 10)); sendValues(3333, (int) (pressure * 10)); sendValues(4444, sensorValue); sendValues(5555, sensorValue2); sendValues(6666, (int) (sensorValue3 / 10.24)); sendValues(7777, distance); // mySwitch.send("TEST"); } void barometre() { /* See Example: TypeA_WithDIPSwitches */ // mySwitch.switchOn("00001", "10000"); // delay(1000); temperature = bmp.readTemperature(); pressure= bmp.readPressure() / 100.0; pression = pressure / 101.325; pression = pression * 0.760 * 100; // http://en.wikipedia.org/wiki/Atmospheric_pressure#Mean_sea_level_pressure // Serial.print("Presiure la nivelul marii (calculata) = "); presiune = bmp.readSealevelPressure() / 101.325; presiune = presiune * 0.760; } void printAll() { Serial.print("Temperature="); Serial.print(temperature); //Serial.print(" *C"); Serial.print(" Pression="); Serial.print(pressure); Serial.print(" Mercure="); Serial.print(pression); //Serial.print(" mmHg"); // Calculate altitude assuming 'standard' barometric // pressure of 1013.25 millibar = 101325 Pascal Serial.print(" Altitude="); Serial.print(bmp.readAltitude()); // Serial.print(" m"); //Serial.print(" Pression au niveau de la mer (calculee) = "); Serial.print(" Mer="); Serial.print(bmp.readSealevelPressure()); //Serial.print(" Pa / "); Serial.print(" MerMercure="); Serial.print(presiune); Serial.println(" mmHg"); Serial.print("fumee="); Serial.print(sensorValue); Serial.print(" gaz="); Serial.print(sensorValue2); Serial.print(" photo="); Serial.println((int) (sensorValue3 / 10.24)); // you can get a more precise measurement of altitude // if you know the current sea level pressure which will // vary with weather and such. If it is 1015 millibars // that is equal to 101500 Pascals. // Serial.print("Altitude reelle = "); // Serial.print(bmp.readAltitude(101500)); // Serial.println(" m"); // // Serial.println(); } void readPresence() { digitalWrite(TrigPin, LOW); //Low high and low level take a short time to TrigPin pulse delayMicroseconds(2); digitalWrite(TrigPin, HIGH); delayMicroseconds(10); digitalWrite(TrigPin, LOW); float cm = pulseIn(EchoPin, HIGH) / 58.0; //Echo time conversion into cm cm = (int(cm * 100.0)) / 100.0; //Keep two decimal places distance = cm * 100; // Serial.print(cm); // Serial.print("cm"); // Serial.println(); } void readSensors() { // ##########################################" // Analogic read // ------------------------------------------ sensorValue = analogRead(A0); sensorValue2 = analogRead(A1); sensorValue3 = analogRead(A2); // int sensorValue4 = digitalRead(10); //vol = (float)sensorValue / 1024 * 5.0; // ########################################## } void sendValues(int id, int value) { // char buf[7]; //char buf2[7]; /* See Example: TypeA_WithDIPSwitches */ // itoa(id, buf, 10); // itoa(value, buf2, 10); // Serial.print(value); // Serial.println(buf2); mySwitch.send(id, 32); delay(500); mySwitch.send(value, 32); // mySwitch.switchOn(buf,buf2); delay(500); // mySwitch.switchOn(id, value); // delay(1000); }