ardumotive
Published © CC BY-NC-SA

Arduino Wireless Weather Station

In this DIY guide I will show you how to make your own wireless weather station.

AdvancedFull instructions provided250
Arduino Wireless Weather Station

Things used in this project

Hardware components

Master PCB Custom Circuit
×1
Slave PCB Custom PCB
×1
ATmega328
Microchip ATmega328
with Arduino UNO bootloader
×2
28 dip socket
×2
16 MHz Crystal
16 MHz Crystal
×2
Capacitor 22 pF
Capacitor 22 pF
×4
Capacitor 100 nF
Capacitor 100 nF
×2
Capacitor 10 µF
Capacitor 10 µF
×2
Resistor 10k ohm
Resistor 10k ohm
×2
Screw Terminal 2P 2.54mm
×2
Pin Header 1x5 Female 2.54mm
×4
Basic 8x2 Character LCD - Black on Green 5V
×1
Trimmer Potentiometer, 20 kohm
Trimmer Potentiometer, 20 kohm
×1
Wireless Serial Transceiver Module HC12
×2
Push Button
×1
DC Power Connector, Jack
DC Power Connector, Jack
×1
Toggle Switch, Toggle
Toggle Switch, Toggle
×1
Arduino USB 2 Serial micro
Arduino USB 2 Serial micro
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Custom parts and enclosures

PCB Schematic

Master

PCB Schematic

Slave

Schematics

Master

Slave

Code

Master

C/C++
/*  
 *  Weather Station - Arduino Based by Ardumotive.com
 *  Code for Master Unit - More info can be found at http://www.ardumotive.com/workshop.html 
 *  Dev: Michalis Vasilakis // Ver 1.0 // Date: 20/11/2018
 */

/***CONFIGURATION ****/
const long interval = 5000;  // ms
const int slaves = 1; //Number of slaves (max 16) (go to line 95 and complete the if statement for every sensor)
/*********************/
//Libraries
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
#include "DHT.h"
//DHT Sensor
#define DHTPIN 2
#define DHTTYPE DHT22   
DHT dht(DHTPIN, DHTTYPE);
//LCD 16x2 Pinout
#define RS 3
#define EN 4
#define D4 5
#define D5 6
#define D6 7
#define D7 11
LiquidCrystal lcd(RS,EN,D4,D5,D6,D7);
SoftwareSerial sSerial(8, 9); // RX, TX
//Variables
int temp=0;
int hum=0;
char incomingByte; 
String command;
boolean messageCompleted=false;
boolean newMessage=false;
unsigned long previousMillis = 0;        
int next=0;

void setup() {
  Serial.begin(9600);
  sSerial.begin(9600);
  lcd.begin(8,2);
  lcd.print("Weather");
  lcd.setCursor(0,1);
  lcd.print("Station");
}

void loop() {
  requestFromSlaves();
  communication();
}

void requestFromSlaves(){
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    if(next<slaves){
      String msg = "<D"+String(next,HEX)+">";
      sSerial.write(msg.c_str());
      next++;
    }
    else{
      readDHT(); //Read the sensor of the 'Master Station'
      next=0;
    }
    
  }
}

void communication(){
  if (sSerial.available()){
    incomingByte = sSerial.read();
    if(incomingByte=='>'){
      messageCompleted=true;
      newMessage=false;
    }
    else if (incomingByte=='<'){
      newMessage=true;
    }

    if (newMessage){
      command.concat(incomingByte);
    }
  }

  if(messageCompleted){
    if (command.charAt(1)=='S'){
      if (command.charAt(2)=='0'){   //<--- 0 is the number of slave sensor station address
        String msg = command.substring(3);
        lcd.clear();
        lcd.print("Balcony:"); //Change line 1 text
        lcd.setCursor(0,1);
        lcd.print(msg);
      }
      // Config for more sensors:
  /*  else if (command.charAt(2)=='1'){ //<--- 1 is the number of slave sensor station address
        String msg = command.substring(3);
        lcd.clear();
        lcd.print("My room:"); //Change line 1 text
        lcd.setCursor(0,1);
        lcd.print(msg);
      }
  */   
    }
    command="";
    messageCompleted=false;
  }
  
}

void readDHT(){
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  String msg = String(temp) + "C " + String(hum) + "%";
  lcd.clear();
  lcd.print("Here...");
  lcd.setCursor(0,1);
  lcd.print(msg);
}

Slave

C/C++
/*  
 *  Weather Station - Arduino Based by Ardumotive.com
 *  Code for Slave Sensor Unit with DHT sensor
 *  More info can be found at http://www.ardumotive.com/workshop.html 
 *  Dev: Michalis Vasilakis // Ver 1.0 // Date: 20/11/2018
 */

/***CONFIGURATION ****/
const long interval = 5000;  // ms
String ADDR = "0"; //Device address from 0 to f
#define SENSOR_TYPE 1 // Type of sensor in slave unit. Can be 1 for DHT, 2 for DS18B20 or 3 for PHOTOCELL
/*********************/
//Libraries
#include "DHT.h"
#include <OneWire.h>
#include <DallasTemperature.h>
//DHT Sensor
#define DHTPIN 8
#define DHTTYPE DHT22   // Change "DHT22" only if you are using a different DHT sensor (!). eg DHT11
DHT dht(DHTPIN, DHTTYPE);
//DS18B20
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
//Photocell
#define PHOTOCELL A0

//Variables
int temp=0;
int hum=0;
String res;
char incomingByte; 
String command;
boolean messageCompleted=false;
boolean newMessage=false;
String fromSensor;
unsigned long previousMillis = 0;       

void setup() {
  Serial.begin(9600);
  switch (SENSOR_TYPE) {
    case 1:
      dht.begin();
      break;
    case 2:
      sensors.begin();
      break;
    case 3:
      break;
  }
}

void loop() {
  communication();
  switch (SENSOR_TYPE) {
    case 1:
      readDHT();
      break;
    case 2:
      readDS18B20();
      break;
    case 3:
      readPhotocell();
      break;
  } 
}

void readDHT(){
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    hum = dht.readHumidity();
    temp = dht.readTemperature();
    fromSensor = "<S"+ADDR+String(temp) + "C " + String(hum) + "%>";
  }
}
void readDS18B20(){
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    sensors.requestTemperatures(); 
    temp = sensors.getTempCByIndex(0);
    fromSensor = "<S"+ADDR+ "Temp " + "C>";
  }
}
void readPhotocell(){
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    int photocellReading = analogRead(PHOTOCELL);
    if (photocellReading < 10) {
      res = "Dark";
    } else if (photocellReading < 200) {
      res = "Dim";
    } else if (photocellReading < 500) {
      res = "Light";
    } else if (photocellReading < 800) {
      res = "Bright";
    }
    fromSensor = "<S"+ADDR + res+">";
  }
}
void communication(){
  if (Serial.available()){
    incomingByte = Serial.read();
    if(incomingByte=='>'){
      messageCompleted=true;
      newMessage=false;
    }
    else if (incomingByte=='<'){
      newMessage=true;
    }
    if (newMessage){
      command.concat(incomingByte);
    }
  }
  if(messageCompleted){
    if (command.charAt(1)=='D'){
      if (command.substring(2)==ADDR){ 
        Serial.print(fromSensor);
      }
    }
    command="";
    messageCompleted=false;
  }
}

Credits

ardumotive

ardumotive

1 project • 2 followers

Comments