/* Outside transmitter * * * * Send data via RF 433MHz to receiver * * CONNECTIONS * RF 433MHz: VCC -> 5V GND -> GND Data -> D12 * Si7021: VCC -> 5V GND -> GND SCL -> SCL SDA -> SDA */ #include #include #include "SPI.h" // Is it really neaded for BMP280 SPI? #include "Adafruit_Si7021.h" Adafruit_Si7021 sensor = Adafruit_Si7021(); #include "LowPower.h" int ledPin = 13; char Msg[30];// The string that we are going to send trought rf transmitter void setup() { Serial.begin(9600); sensor.begin(); pinMode(ledPin,OUTPUT); // Set LED at D13 as output // VirtualWire setup vw_setup(2000); // Bits per sec for RF vw_set_tx_pin(12);// Set the Tx pin. Default is 12 } void loop() { // si7021 Read and store values float humidity_float = sensor.readHumidity(); float temp_float = sensor.readTemperature(); // For debugging Serial.println("VALUES READ:"); Serial.print("Temperature: "); Serial.print(temp_float); Serial.println("C"); Serial.print("Humidity: "); Serial.print(humidity_float); Serial.println("%"); Serial.println(); // Convert si7021 float values to integers to be send by RF with 2 decimal point precision temp_float = temp_float * 100; // Multiply by 100 for 2 decimal point precision int b = int(temp_float); // http://forum.arduino.cc/index.php?topic=82462.0 int temperature = round(b); // Round float number to nearest integer humidity_float = humidity_float * 100; // Multiply by 100 for 2 decimal point precision int a = int(humidity_float); // http://forum.arduino.cc/index.php?topic=82462.0 int humidity = round(a); // Round float number to nearest integer // Send message through RF sprintf(Msg, "%d,%d", humidity,temperature); // Turn on a light to show transmitting Serial.println("Read Values OK!"); digitalWrite(ledPin, HIGH); delay(1000); vw_send((uint8_t *)Msg, strlen(Msg)); vw_wait_tx(); // Wait until the whole message is gone digitalWrite(ledPin, LOW); // Turn off a light after transmission // Lowpower library supports max sleep time of 8s // use loop as many times as needed to achieve longer sleep //30 * 8s = 240s for(int i=0;i<30;i++) // sleep for 4 minutes { LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); } }