Example Code for Arduino-Weather Station Data Reading
Last revision 2025/12/08
This project demonstrates how to use the DFRobot Weather Station Kit with an Arduino board to read and display real-time weather data including wind direction, average/max wind speed, temperature, humidity, rainfall, and air pressure. Users will learn how to interface the kit with Arduino, parse serial data output from the module, and convert raw data into human-readable formats.
Hardware Preparation
- DFRduino UNO R3 (or similar) x 1
- APRS Weather Station Kit x 1
- M-M/F-M/F-F Jumper wires x 1
Software Preparation
Wiring Diagram

Please unplug the cable on the TX&RX interface, or it will interfere with the sketch uploading.
Other Preparation Work
Our code uses 9600 as the default serial port baud rate. If you upload our sample code directly, you will need to unplug the J2 jumper cap and install the J1 jumper cap.
Sample Code
/*!
* @file SEN0186.ino
* @brief DFRobot brings you this new version of the weather station kit that integrates anemometer, wind vane and rain gauge.
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @license The MIT License (MIT)
* @author DFRobot
* @version V1.0
* @date 2023-08-03
*/
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 transCharToInt_T(char* _buffer)
{
int result = 0;
if (_buffer[13] == '-') {
result = 0 - (((_buffer[14] - '0') * 10) + (_buffer[15] - '0'));
} else {
result = ((_buffer[13] - '0') * 100) + ((_buffer[14] - '0') * 10) + ((_buffer[15] - '0'));
}
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_T(databuffer) - 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
{
temp = transCharToInt(databuffer, 28, 32);
return temp / 10.00;
}
void setup()
{
Serial.begin(9600);
}
void loop()
{
getBuffer(); //Begin!
Serial.print("Wind Direction: ");
Serial.print(WindDirection());
Serial.println(" ");
Serial.print("Average Wind Speed (One Minute): ");
Serial.print(WindSpeedAverage());
Serial.println("m/s ");
Serial.print("Max Wind Speed (Five Minutes): ");
Serial.print(WindSpeedMax());
Serial.println("m/s");
Serial.print("Rain Fall (One Hour): ");
Serial.print(RainfallOneHour());
Serial.println("mm ");
Serial.print("Rain Fall (24 Hour): ");
Serial.print(RainfallOneDay());
Serial.println("mm");
Serial.print("Temperature: ");
Serial.print(Temperature());
Serial.println("C ");
Serial.print("Humidity: ");
Serial.print(Humidity());
Serial.println("% ");
Serial.print("Barometric Pressure: ");
Serial.print(BarPressure());
Serial.println("hPa");
Serial.println("");
Serial.println("");
}
Result
Note: Due to the fact that there is no wind in the test environment, all parameters related to wind speed and wind direction are 0.

Indicator Light
- DAT flashes synchronously when sending data
- TX flashes synchronously when sampling wind speed
- RX flashes synchronously when rain sensor is working
Was this article helpful?
