iwoox
Published © GPL3+

Weather Station With Wireless Data Transmitting

Upgrade of my previous project.

AdvancedFull instructions provided24 hours1,055
Weather Station With Wireless Data Transmitting

Things used in this project

Hardware components

DFRobot weather station kit
×1
DFRobot Solar panel 5V
×1
Solar Power Manager 5V
DFRobot Solar Power Manager 5V
×1
DFRobot interface shield for Arduino
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
DFRobot mouting kit
×1
DFRobot Arduino Uno
×1

Story

Read more

Code

Code for transmitter

C/C++
#include <RH_ASK.h>
// Include dependant SPI Library 
#include <SPI.h> 


char                 databuffer[35];
double               temp;

void getBuffer()                                                                    //Get weather status data
{
  int index;
  for (index = 0;index < 35;index ++)
  {
    if(Serial.available())
    {
      databuffer[index] = Serial.read();
      if (databuffer[0] != 'c')
      {
        index = -1;
      }
    }
    else
    {
      index --;
    }
  }
}

int transCharToInt(char *_buffer,int _start,int _stop)                               //char to int
{
  int _index;
  int result = 0;
  int num = _stop - _start + 1;
  int _temp[num];
  for (_index = _start;_index <= _stop;_index ++)
  {
    _temp[_index - _start] = _buffer[_index] - '0';
    result = 10*result + _temp[_index - _start];
  }
  return result;
}

int WindDirection()                                                                  //Wind Direction
{
  return transCharToInt(databuffer,1,3);
}

float WindSpeedAverage()                                                             //air Speed (1 minute)
{
  temp = 0.44704 * transCharToInt(databuffer,5,7);
  return temp;
}

float WindSpeedMax()                                                                 //Max air speed (5 minutes)
{
  temp = 0.44704 * transCharToInt(databuffer,9,11);
  return temp;
}

float Temperature()                                                                  //Temperature ("C")
{
  temp = (transCharToInt(databuffer,13,15) - 32.00) * 5.00 / 9.00;
  return temp;
}

float RainfallOneHour()                                                              //Rainfall (1 hour)
{
  temp = transCharToInt(databuffer,17,19) * 25.40 * 0.01;
  return temp;
}

float RainfallOneDay()                                                               //Rainfall (24 hours)
{
  temp = transCharToInt(databuffer,21,23) * 25.40 * 0.01;
  return temp;
}

int Humidity()                                                                       //Humidity
{
  return transCharToInt(databuffer,25,26);
}

float BarPressure()                                                                  //Barometric Pressure
{
  float temp_rf;
  return temp / 10.00;
}

float hum;    // Stores humidity value in percent
float temp_rf;   // Stores temperature value in Celcius
float wind_speed;

//RF 
String str_humid;
String str_temp;
String str_wind_speed;
String str_out;
 
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

void setup()
{
   // Initialize ASK Object
  rf_driver.init();
  //
  Serial.begin(9600);
}
void loop()
{
  getBuffer();   
   
   delay(2000);

    hum = Humidity();
    temp_rf = Temperature();
    wind_speed = WindSpeedMax();

    //
    str_humid = String(hum);
    
    // Convert Temperature to string
    str_temp = String(temp_rf);
    
    //
    str_wind_speed = String(wind_speed);
 
    // Combine Humidity and Temperature
    str_out = str_humid + "," + str_temp;
    
    // Compose output character
    const char *msg = str_out.c_str();
    //const char *msg1 = str_wind_speed.c_str();
    
    rf_driver.send((uint8_t *)msg, strlen(msg));
    rf_driver.waitPacketSent();
    
    //rf_driver.send((uint8_t *)msg1, strlen(msg1));
    //rf_driver.waitPacketSent();
 
  Serial.print("Temperature: ");
  Serial.print(Temperature());
  Serial.println("C  ");
  Serial.print("Humidity: ");
  Serial.print(Humidity());
  Serial.println("%  ");
  Serial.println("");
}

Code for receiver

C/C++
//RTC
#include "GravityRtc.h"
#include "Wire.h"  

GravityRtc rtc;     //RTC Initialization

////////////////////////////////////////////////
//LCD
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

#define BACKLIGHT_PIN 3

LiquidCrystal_I2C lcd(0x20, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 
///////////////////////////////////////////////////

// Include RadioHead Amplitude Shift Keying Library
#include <RH_ASK.h>
// Include dependant SPI Library 
#include <SPI.h> 
 
// Define output strings
 
String str_humid;
String str_temp;
String str_wind_speed;
String str_out;
 
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
 
void setup()
{

lcd.begin (20,4); //  
  // LCD Backlight ON
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.home ();
  //////////
  
    // Initialize ASK Object
    rf_driver.init();
    // Setup Serial Monitor
    Serial.begin(9600);

    //RTC
    rtc.setup();
    rtc.adjustRtc(2019,2,6,1,15,12,01);
}
 
void loop()
{
    // Set buffer to size of expected message
    uint8_t buf[11];
    uint8_t buflen = sizeof(buf);
    // Check if received packet is correct size
    if (rf_driver.recv(buf, &buflen))
    {
      
      // Message received with valid checksum
      // Get values from string
      
      // Convert received data into string
      str_out = String((char*)buf);
      
      // Split string into two values
      for (int i = 0; i < str_out.length(); i++) {
      if (str_out.substring(i, i+1) == ",") {
      str_humid = str_out.substring(0, i);
      str_temp = str_out.substring(i+1);
      break;
      }
    }
      
      // Print values to Serial Monitor
      Serial.print("Humidity: ");
      Serial.print(str_humid);
      Serial.print(" %");
      Serial.print("  - Temperature: ");
      Serial.println(str_temp);
      
      lcd.setCursor(0,0);
      lcd.print("Temperature: ");
      lcd.print(str_temp);
      lcd.print("C ");

      lcd.setCursor(0,1);
      lcd.print("Humidity: ");
      lcd.print(str_humid);
      lcd.print(" % ");

      //RTC
       rtc.read();
       lcd.setCursor(0,2); //0,3
       lcd.print("Date:");
       lcd.setCursor(0,3);
       lcd.print(rtc.day); 
       lcd.print(".");
       lcd.print(rtc.month);
       lcd.print(".");
       lcd.print(rtc.year);

       lcd.setCursor(13,2);
       lcd.print("Time:");
       lcd.setCursor(13,3);
       lcd.print(rtc.hour);
       lcd.print(":");
       lcd.print(rtc.minute);
      
       

    }
}
 

Credits

iwoox

iwoox

10 projects • 3 followers
Student at Faculty of Electrical Engineering and Computer Science.

Comments