test_Code / weather_Transmitter / weather_Transmitter.inoon commit Added link to project report (97a3ba0)
   1#include <bmp180.h>
   2
   3/*
   4 *      Arduino Weather Station
   5 *      Transmitter Unit
   6 *      
   7 *      Code by Andrew Lorimer, 2016
   8 */
   9
  10
  11
  12// Libraries
  13#include <OneWire.h>      // Used for BMP180
  14#include <Wire.h>         // Used for BMP180 (I2C communication)
  15#include <VirtualWire.h>  // Used for 433 MHz transmitter
  16#include "DHT.h"          // Adafruit DHTxx lib
  17
  18// Set up DHT22
  19#define dhtpin 2          // Digital connection to DHT22
  20DHT dht(dhtpin, DHT22);   // Create DHT22 object
  21
  22
  23// Set up BMP180
  24#define bmppin 0x77       // I2C address of BMP180
  25const unsigned char OSS = 0;  // Oversampling Setting
  26int ac1; // Calibration values
  27int ac2;
  28int ac3;
  29unsigned int ac4;
  30unsigned int ac5;
  31unsigned int ac6;
  32int b1;
  33int b2;
  34int mb;
  35int mc;
  36int md;
  37long b5; //
  38
  39// Set up 433 MHz transmitter
  40#define INTEGER_MAX (pow(2,31)-1)
  41#define E_MAX (pow(10, 7))
  42#define E_MIN (pow(10, -6))
  43#define EPSILON 0.000000119209
  44OneWire oneWire(10);
  45int RF_TX_PIN = 12;
  46
  47
  48
  49
  50
  51void setup()
  52{
  53  Serial.begin(9600);
  54  Serial.println("Entering setup routine...");
  55
  56  // DHT22 (humidity & temp)
  57  dht.begin();
  58  Serial.println("> Successfully started DHT22");
  59  
  60  //Pressure sensor
  61  Wire.begin();
  62  CalibratePressure();
  63  Serial.println("> Successfully started BMP180");
  64
  65    // Setup transmit pin
  66  vw_set_tx_pin(RF_TX_PIN); 
  67  vw_setup(2000); //
  68  Serial.println("> Successfully started 433 MHz transmitter");
  69
  70  //For Debug
  71  Serial.println("Finished setup routine.\n");
  72}
  73
  74
  75
  76
  77
  78
  79
  80void loop() {
  81
  82  // Humidity (DHT22)
  83  float humidity = dht.readHumidity(); // Read humidity
  84  if (isnan(humidity)) {Serial.println("ERROR: Failed to read humidity from DHT22.");}
  85  SendData("#H"+ ((String)humidity)); // Send humidity data
  86
  87  // Temperature (BMP180)
  88  float temperature = readTemperature(); // Read temperature
  89  if (isnan(temperature)) {Serial.println("ERROR: Failed to read temperature from BMP180.");}
  90  SendData("#C"+(String(temperature,2))); // Send temperature data
  91
  92  // Barometric pressure (BMP180)
  93  float pressure = readPressure(); // Read pressure
  94  if (isnan(pressure)) {Serial.println("ERROR: Failed to read pressure from BMP180.");}
  95  SendData("#P"+(String(pressure/100,2)));
  96  
  97  delay(5000); //Wait for next loop
  98  
  99}
 100
 101
 102
 103
 104
 105
 106
 107void SendData(String data) {
 108  
 109  Serial.println("Sending " + data);
 110  
 111  const char* rawdata = data.c_str(); // Conver input string to char array
 112  digitalWrite(13, true); // Flash onboard TX light
 113  vw_send((uint8_t *)rawdata, strlen(rawdata)); //Send Data
 114  vw_wait_tx(); // Wait until the whole message is gone
 115  digitalWrite(13, false);
 116  
 117}
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135