Ardumotive Arduino Greek Playground
  • Home
    • About us
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

Arduino Wireless Weather Station

Available Languages
Picture
Picture

Introduction 

Published date: 28/11/2018
Picture
In this DIY guide I will show you how to make your own wireless weather station. In this project I decided to make my own PCB that is based on Arduino UNO microcontroller - Atmega328p.
Bellow you will find the electronic schematic with PCB layout so you can easily produce it.

Let's get started.

What you will need - Hardware Part List

For Master Station you will need:
  • Our custom PCB circuit *
  • Atmega328 (with Arduino UNO bootloader)
  • 28 dip socket
  • 16 MHz crystal oscillator
  • ​2x22 pF capacitors
  • 1x100nF ceramic capacitor
  • 1x10uF Electrolytic Capacitor
  • 1x10K resistor
  • Screw terminal 2P 2.54mm
  • 2xPin Header 1x5 Female 2.54mm​
----> Or use an Arduino board with breadboard
  • Basic 8x2 Character LCD - Black on Green 5V
  • Wireless Serial Transceiver Module HC12
  • ​Trimmer 20kOhm
  • DHT-22 sensor (or any other DHT family sensor)
  • Push Button Latching - 12.5mm
  • DC Power Jack
  • On/Off SW (lcd back light)
 Power by 5V power adapter or USB powerbank

For every Slave - Sensor Station you will need:
  • Our custom PCB circuit *
  • Atmega328 (with Arduino UNO bootloader)
  • 28 dip socket
  • 16 MHz crystal oscillator
  • ​2x22 pF capacitors
  • 1x100nF ceramic capacitor
  • 1x10uF Electrolytic Capacitor
  • 1x10K resistor
  • Screw terminal 2P 2.54mm
  • 2xPin Header 1x5 Female 2.54mm​
----> Or use an Arduino board with breadboard​
  • Wireless Serial Transceiver Module HC12
One of the following sensors:
  • DHT-22 sensor (or any other DHT)
  • DS18B20 (Waterproof) and 1x4.7K Resistor
  • Photocell and 1x 10K Resistor

​ Power by 5V power adapter or USB powerbank or battery pack
​
*You will also need a TTL to USB module or an Arduino UNO board for the programming procedure. 

The circuit at EasyEDA, the free online circuit design platform

Picture
Master Circuit
Picture
PCB Master
Picture
Slave Circuit
Picture
PCB Slave
EasyEDA is a free, zero- install, cloud-based EDA tool, designed to give electrical engineers, educators, engineering students and electronics hobbyists an Easier EDA Experience. It is easy to use circuit design, circuit simulator and PCB design that runs in your web browser.

Arduino Connection Pins

--> For Master Station
​LCD
  • ​RS pin to Arduino Pin 3
  • EN pin to Arduino Pin 4
  • D4 pin to Arduino Pin 5
  • D5 pin to Arduino Pin 6
  • D6 pin to Arduino Pin 7
  • D7 pin to Arduino Pin 11

DHT Sensor
  • Data pin to Arduino Pin 2

HC-12
  • TX pin to Arduino Pin 8
  • RX pin to Arduino Pin 9
--> For Slave/Sensor Station
DHT Sensor
  • Data pin to Arduino Pin 8

DS18B20 Sensor
  • Data pin to Arduino Pin 2

Photocell
  • to Arduino A0

The code

Connect your circuit with TTL to USB module  with 5 cables to the programming header. The pins RX and TX must be cross-connected.

NOTE: If you are using the Arduino UNO board make sure to remove the ATmega328 IC from it first and connect the headers RX to RX and TX to TX pins of the board. The RS pin must be connected to Arduino UNO reset pin.

Master

/***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) /*********************/
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*  
 *  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​ 

/***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
/*********************/
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*  
 *  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;
  }
}
Download the code from here and open it with Arduino IDE. Inside you will also find the library file.

​
code_files.zip
File Size: 22 kb
File Type: zip
Download File

JLCPCB - Make your own circuit boad from 2$!

Enter here to produce your PCB board!

Use JLCPCB for $2 PCB Fabrication & 2-day Build Time, the quality is really good, check the below photo of our pcb board.
gerber_pcb_master_v1_20181129112035.zip
File Size: 21 kb
File Type: zip
Download File

gerber_pcb_slave_v1_20181129112050.zip
File Size: 15 kb
File Type: zip
Download File

Picture

3D Parts

Picture
Master A
Picture
Master B
Picture
Slave A
Picture
Slave B
3dfiles.zip
File Size: 169 kb
File Type: zip
Download File

Well Done!

Picture
I hope you liked this, let me know in the comments!!!
Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates
Ardumotive Arduino Greek Playground