Components and supplies
Capacitor 10 µF
Capacitor 22 pF
Master PCB Custom Circuit
Capacitor 100 nF
DC Power Connector, Jack
Trimmer Potentiometer, 20 kohm
Screw Terminal 2P 2.54mm
28 dip socket
Slave PCB Custom PCB
16 MHz Crystal
ATmega328
Arduino USB 2 Serial micro
Push Button
Wireless Serial Transceiver Module HC12
Basic 8x2 Character LCD - Black on Green 5V
Resistor 10k ohm
Pin Header 1x5 Female 2.54mm
Toggle Switch, Toggle
Tools and machines
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Soldering iron (generic)
Solder Wire, Lead Free
Apps and platforms
Arduino IDE
Arduino Web Editor
Project description
Code
Slave
c_cpp
1/* 2 * Weather Station - Arduino Based by Ardumotive.com 3 * Code for Slave Sensor Unit with DHT sensor 4 * More info can be found at http://www.ardumotive.com/workshop.html 5 * Dev: Michalis Vasilakis // Ver 1.0 // Date: 20/11/2018 6 */ 7 8/***CONFIGURATION ****/ 9const long interval = 5000; // ms 10String ADDR = "0"; //Device address from 0 to f 11#define SENSOR_TYPE 1 // Type of sensor in slave unit. Can be 1 for DHT, 2 for DS18B20 or 3 for PHOTOCELL 12/*********************/ 13//Libraries 14#include "DHT.h" 15#include <OneWire.h> 16#include <DallasTemperature.h> 17//DHT Sensor 18#define DHTPIN 8 19#define DHTTYPE DHT22 // Change "DHT22" only if you are using a different DHT sensor (!). eg DHT11 20DHT dht(DHTPIN, DHTTYPE); 21//DS18B20 22#define ONE_WIRE_BUS 2 23OneWire oneWire(ONE_WIRE_BUS); 24DallasTemperature sensors(&oneWire); 25//Photocell 26#define PHOTOCELL A0 27 28//Variables 29int temp=0; 30int hum=0; 31String res; 32char incomingByte; 33String command; 34boolean messageCompleted=false; 35boolean newMessage=false; 36String fromSensor; 37unsigned long previousMillis = 0; 38 39void setup() { 40 Serial.begin(9600); 41 switch (SENSOR_TYPE) { 42 case 1: 43 dht.begin(); 44 break; 45 case 2: 46 sensors.begin(); 47 break; 48 case 3: 49 break; 50 } 51} 52 53void loop() { 54 communication(); 55 switch (SENSOR_TYPE) { 56 case 1: 57 readDHT(); 58 break; 59 case 2: 60 readDS18B20(); 61 break; 62 case 3: 63 readPhotocell(); 64 break; 65 } 66} 67 68void readDHT(){ 69 unsigned long currentMillis = millis(); 70 if (currentMillis - previousMillis >= interval) { 71 previousMillis = currentMillis; 72 hum = dht.readHumidity(); 73 temp = dht.readTemperature(); 74 fromSensor = "<S"+ADDR+String(temp) + "C " + String(hum) + "%>"; 75 } 76} 77void readDS18B20(){ 78 unsigned long currentMillis = millis(); 79 if (currentMillis - previousMillis >= interval) { 80 previousMillis = currentMillis; 81 sensors.requestTemperatures(); 82 temp = sensors.getTempCByIndex(0); 83 fromSensor = "<S"+ADDR+ "Temp " + "C>"; 84 } 85} 86void readPhotocell(){ 87 unsigned long currentMillis = millis(); 88 if (currentMillis - previousMillis >= interval) { 89 previousMillis = currentMillis; 90 int photocellReading = analogRead(PHOTOCELL); 91 if (photocellReading < 10) { 92 res = "Dark"; 93 } else if (photocellReading < 200) { 94 res = "Dim"; 95 } else if (photocellReading < 500) { 96 res = "Light"; 97 } else if (photocellReading < 800) { 98 res = "Bright"; 99 } 100 fromSensor = "<S"+ADDR + res+">"; 101 } 102} 103void communication(){ 104 if (Serial.available()){ 105 incomingByte = Serial.read(); 106 if(incomingByte=='>'){ 107 messageCompleted=true; 108 newMessage=false; 109 } 110 else if (incomingByte=='<'){ 111 newMessage=true; 112 } 113 if (newMessage){ 114 command.concat(incomingByte); 115 } 116 } 117 if(messageCompleted){ 118 if (command.charAt(1)=='D'){ 119 if (command.substring(2)==ADDR){ 120 Serial.print(fromSensor); 121 } 122 } 123 command=""; 124 messageCompleted=false; 125 } 126} 127
Slave
c_cpp
1/* 2 * Weather Station - Arduino Based by Ardumotive.com 3 * Code for Slave Sensor Unit with DHT sensor 4 * More info can be found at http://www.ardumotive.com/workshop.html 5 * Dev: Michalis Vasilakis // Ver 1.0 // Date: 20/11/2018 6 */ 7 8/***CONFIGURATION ****/ 9const long interval = 5000; // ms 10String ADDR = "0"; //Device address from 0 to f 11#define SENSOR_TYPE 1 // Type of sensor in slave unit. Can be 1 for DHT, 2 for DS18B20 or 3 for PHOTOCELL 12/*********************/ 13//Libraries 14#include "DHT.h" 15#include <OneWire.h> 16#include <DallasTemperature.h> 17//DHT Sensor 18#define DHTPIN 8 19#define DHTTYPE DHT22 // Change "DHT22" only if you are using a different DHT sensor (!). eg DHT11 20DHT dht(DHTPIN, DHTTYPE); 21//DS18B20 22#define ONE_WIRE_BUS 2 23OneWire oneWire(ONE_WIRE_BUS); 24DallasTemperature sensors(&oneWire); 25//Photocell 26#define PHOTOCELL A0 27 28//Variables 29int temp=0; 30int hum=0; 31String res; 32char incomingByte; 33String command; 34boolean messageCompleted=false; 35boolean newMessage=false; 36String fromSensor; 37unsigned long previousMillis = 0; 38 39void setup() { 40 Serial.begin(9600); 41 switch (SENSOR_TYPE) { 42 case 1: 43 dht.begin(); 44 break; 45 case 2: 46 sensors.begin(); 47 break; 48 case 3: 49 break; 50 } 51} 52 53void loop() { 54 communication(); 55 switch (SENSOR_TYPE) { 56 case 1: 57 readDHT(); 58 break; 59 case 2: 60 readDS18B20(); 61 break; 62 case 3: 63 readPhotocell(); 64 break; 65 } 66} 67 68void readDHT(){ 69 unsigned long currentMillis = millis(); 70 if (currentMillis - previousMillis >= interval) { 71 previousMillis = currentMillis; 72 hum = dht.readHumidity(); 73 temp = dht.readTemperature(); 74 fromSensor = "<S"+ADDR+String(temp) + "C " + String(hum) + "%>"; 75 } 76} 77void readDS18B20(){ 78 unsigned long currentMillis = millis(); 79 if (currentMillis - previousMillis >= interval) { 80 previousMillis = currentMillis; 81 sensors.requestTemperatures(); 82 temp = sensors.getTempCByIndex(0); 83 fromSensor = "<S"+ADDR+ "Temp " + "C>"; 84 } 85} 86void readPhotocell(){ 87 unsigned long currentMillis = millis(); 88 if (currentMillis - previousMillis >= interval) { 89 previousMillis = currentMillis; 90 int photocellReading = analogRead(PHOTOCELL); 91 if (photocellReading < 10) { 92 res = "Dark"; 93 } else if (photocellReading < 200) { 94 res = "Dim"; 95 } else if (photocellReading < 500) { 96 res = "Light"; 97 } else if (photocellReading < 800) { 98 res = "Bright"; 99 } 100 fromSensor = "<S"+ADDR + res+">"; 101 } 102} 103void communication(){ 104 if (Serial.available()){ 105 incomingByte = Serial.read(); 106 if(incomingByte=='>'){ 107 messageCompleted=true; 108 newMessage=false; 109 } 110 else if (incomingByte=='<'){ 111 newMessage=true; 112 } 113 if (newMessage){ 114 command.concat(incomingByte); 115 } 116 } 117 if(messageCompleted){ 118 if (command.charAt(1)=='D'){ 119 if (command.substring(2)==ADDR){ 120 Serial.print(fromSensor); 121 } 122 } 123 command=""; 124 messageCompleted=false; 125 } 126} 127
Master
c_cpp
1/* 2 * Weather Station - Arduino Based by Ardumotive.com 3 * Code 4 for Master Unit - More info can be found at http://www.ardumotive.com/workshop.html 5 6 * Dev: Michalis Vasilakis // Ver 1.0 // Date: 20/11/2018 7 */ 8 9/***CONFIGURATION 10 ****/ 11const long interval = 5000; // ms 12const int slaves = 1; //Number of 13 slaves (max 16) (go to line 95 and complete the if statement for every sensor) 14/*********************/ 15//Libraries 16#include 17 <LiquidCrystal.h> 18#include <SoftwareSerial.h> 19#include "DHT.h" 20//DHT 21 Sensor 22#define DHTPIN 2 23#define DHTTYPE DHT22 24DHT dht(DHTPIN, DHTTYPE); 25//LCD 26 16x2 Pinout 27#define RS 3 28#define EN 4 29#define D4 5 30#define D5 6 31#define 32 D6 7 33#define D7 11 34LiquidCrystal lcd(RS,EN,D4,D5,D6,D7); 35SoftwareSerial 36 sSerial(8, 9); // RX, TX 37//Variables 38int temp=0; 39int hum=0; 40char incomingByte; 41 42String command; 43boolean messageCompleted=false; 44boolean newMessage=false; 45unsigned 46 long previousMillis = 0; 47int next=0; 48 49void setup() { 50 Serial.begin(9600); 51 52 sSerial.begin(9600); 53 lcd.begin(8,2); 54 lcd.print("Weather"); 55 lcd.setCursor(0,1); 56 57 lcd.print("Station"); 58} 59 60void loop() { 61 requestFromSlaves(); 62 63 communication(); 64} 65 66void requestFromSlaves(){ 67 unsigned long currentMillis 68 = millis(); 69 if (currentMillis - previousMillis >= interval) { 70 previousMillis 71 = currentMillis; 72 if(next<slaves){ 73 String msg = "<D"+String(next,HEX)+">"; 74 75 sSerial.write(msg.c_str()); 76 next++; 77 } 78 else{ 79 readDHT(); 80 //Read the sensor of the 'Master Station' 81 next=0; 82 } 83 84 85 } 86} 87 88void communication(){ 89 if (sSerial.available()){ 90 incomingByte 91 = sSerial.read(); 92 if(incomingByte=='>'){ 93 messageCompleted=true; 94 95 newMessage=false; 96 } 97 else if (incomingByte=='<'){ 98 newMessage=true; 99 100 } 101 102 if (newMessage){ 103 command.concat(incomingByte); 104 } 105 106 } 107 108 if(messageCompleted){ 109 if (command.charAt(1)=='S'){ 110 if 111 (command.charAt(2)=='0'){ //<--- 0 is the number of slave sensor station address 112 113 String msg = command.substring(3); 114 lcd.clear(); 115 lcd.print("Balcony:"); 116 //Change line 1 text 117 lcd.setCursor(0,1); 118 lcd.print(msg); 119 120 } 121 // Config for more sensors: 122 /* else if (command.charAt(2)=='1'){ 123 //<--- 1 is the number of slave sensor station address 124 String msg = command.substring(3); 125 126 lcd.clear(); 127 lcd.print("My room:"); //Change line 1 text 128 129 lcd.setCursor(0,1); 130 lcd.print(msg); 131 } 132 */ 133 134 } 135 command=""; 136 messageCompleted=false; 137 } 138 139} 140 141void 142 readDHT(){ 143 hum = dht.readHumidity(); 144 temp = dht.readTemperature(); 145 146 String msg = String(temp) + "C " + String(hum) + "%"; 147 lcd.clear(); 148 149 lcd.print("Here..."); 150 lcd.setCursor(0,1); 151 lcd.print(msg); 152} 153
Slave
c_cpp
1/* 2 * Weather Station - Arduino Based by Ardumotive.com 3 * Code 4 for Slave Sensor Unit with DHT sensor 5 * More info can be found at http://www.ardumotive.com/workshop.html 6 7 * Dev: Michalis Vasilakis // Ver 1.0 // Date: 20/11/2018 8 */ 9 10/***CONFIGURATION 11 ****/ 12const long interval = 5000; // ms 13String ADDR = "0"; //Device address 14 from 0 to f 15#define SENSOR_TYPE 1 // Type of sensor in slave unit. Can be 1 for 16 DHT, 2 for DS18B20 or 3 for PHOTOCELL 17/*********************/ 18//Libraries 19#include 20 "DHT.h" 21#include <OneWire.h> 22#include <DallasTemperature.h> 23//DHT Sensor 24#define 25 DHTPIN 8 26#define DHTTYPE DHT22 // Change "DHT22" only if you are using a 27 different DHT sensor (!). eg DHT11 28DHT dht(DHTPIN, DHTTYPE); 29//DS18B20 30#define 31 ONE_WIRE_BUS 2 32OneWire oneWire(ONE_WIRE_BUS); 33DallasTemperature sensors(&oneWire); 34//Photocell 35#define 36 PHOTOCELL A0 37 38//Variables 39int temp=0; 40int hum=0; 41String res; 42char 43 incomingByte; 44String command; 45boolean messageCompleted=false; 46boolean 47 newMessage=false; 48String fromSensor; 49unsigned long previousMillis = 0; 50 51void 52 setup() { 53 Serial.begin(9600); 54 switch (SENSOR_TYPE) { 55 case 1: 56 57 dht.begin(); 58 break; 59 case 2: 60 sensors.begin(); 61 62 break; 63 case 3: 64 break; 65 } 66} 67 68void loop() { 69 70 communication(); 71 switch (SENSOR_TYPE) { 72 case 1: 73 readDHT(); 74 75 break; 76 case 2: 77 readDS18B20(); 78 break; 79 case 80 3: 81 readPhotocell(); 82 break; 83 } 84} 85 86void readDHT(){ 87 88 unsigned long currentMillis = millis(); 89 if (currentMillis - previousMillis 90 >= interval) { 91 previousMillis = currentMillis; 92 hum = dht.readHumidity(); 93 94 temp = dht.readTemperature(); 95 fromSensor = "<S"+ADDR+String(temp) + 96 "C " + String(hum) + "%>"; 97 } 98} 99void readDS18B20(){ 100 unsigned 101 long currentMillis = millis(); 102 if (currentMillis - previousMillis >= interval) 103 { 104 previousMillis = currentMillis; 105 sensors.requestTemperatures(); 106 107 temp = sensors.getTempCByIndex(0); 108 fromSensor = "<S"+ADDR+ "Temp " 109 + "C>"; 110 } 111} 112void readPhotocell(){ 113 unsigned long currentMillis 114 = millis(); 115 if (currentMillis - previousMillis >= interval) { 116 previousMillis 117 = currentMillis; 118 int photocellReading = analogRead(PHOTOCELL); 119 if 120 (photocellReading < 10) { 121 res = "Dark"; 122 } else if (photocellReading 123 < 200) { 124 res = "Dim"; 125 } else if (photocellReading < 500) { 126 127 res = "Light"; 128 } else if (photocellReading < 800) { 129 res 130 = "Bright"; 131 } 132 fromSensor = "<S"+ADDR + res+">"; 133 } 134} 135void 136 communication(){ 137 if (Serial.available()){ 138 incomingByte = Serial.read(); 139 140 if(incomingByte=='>'){ 141 messageCompleted=true; 142 newMessage=false; 143 144 } 145 else if (incomingByte=='<'){ 146 newMessage=true; 147 } 148 149 if (newMessage){ 150 command.concat(incomingByte); 151 } 152 } 153 154 if(messageCompleted){ 155 if (command.charAt(1)=='D'){ 156 if (command.substring(2)==ADDR){ 157 158 Serial.print(fromSensor); 159 } 160 } 161 command=""; 162 163 messageCompleted=false; 164 } 165} 166
Master
c_cpp
1/* 2 * Weather Station - Arduino Based by Ardumotive.com 3 * Code for Master Unit - More info can be found at http://www.ardumotive.com/workshop.html 4 * Dev: Michalis Vasilakis // Ver 1.0 // Date: 20/11/2018 5 */ 6 7/***CONFIGURATION ****/ 8const long interval = 5000; // ms 9const int slaves = 1; //Number of slaves (max 16) (go to line 95 and complete the if statement for every sensor) 10/*********************/ 11//Libraries 12#include <LiquidCrystal.h> 13#include <SoftwareSerial.h> 14#include "DHT.h" 15//DHT Sensor 16#define DHTPIN 2 17#define DHTTYPE DHT22 18DHT dht(DHTPIN, DHTTYPE); 19//LCD 16x2 Pinout 20#define RS 3 21#define EN 4 22#define D4 5 23#define D5 6 24#define D6 7 25#define D7 11 26LiquidCrystal lcd(RS,EN,D4,D5,D6,D7); 27SoftwareSerial sSerial(8, 9); // RX, TX 28//Variables 29int temp=0; 30int hum=0; 31char incomingByte; 32String command; 33boolean messageCompleted=false; 34boolean newMessage=false; 35unsigned long previousMillis = 0; 36int next=0; 37 38void setup() { 39 Serial.begin(9600); 40 sSerial.begin(9600); 41 lcd.begin(8,2); 42 lcd.print("Weather"); 43 lcd.setCursor(0,1); 44 lcd.print("Station"); 45} 46 47void loop() { 48 requestFromSlaves(); 49 communication(); 50} 51 52void requestFromSlaves(){ 53 unsigned long currentMillis = millis(); 54 if (currentMillis - previousMillis >= interval) { 55 previousMillis = currentMillis; 56 if(next<slaves){ 57 String msg = "<D"+String(next,HEX)+">"; 58 sSerial.write(msg.c_str()); 59 next++; 60 } 61 else{ 62 readDHT(); //Read the sensor of the 'Master Station' 63 next=0; 64 } 65 66 } 67} 68 69void communication(){ 70 if (sSerial.available()){ 71 incomingByte = sSerial.read(); 72 if(incomingByte=='>'){ 73 messageCompleted=true; 74 newMessage=false; 75 } 76 else if (incomingByte=='<'){ 77 newMessage=true; 78 } 79 80 if (newMessage){ 81 command.concat(incomingByte); 82 } 83 } 84 85 if(messageCompleted){ 86 if (command.charAt(1)=='S'){ 87 if (command.charAt(2)=='0'){ //<--- 0 is the number of slave sensor station address 88 String msg = command.substring(3); 89 lcd.clear(); 90 lcd.print("Balcony:"); //Change line 1 text 91 lcd.setCursor(0,1); 92 lcd.print(msg); 93 } 94 // Config for more sensors: 95 /* else if (command.charAt(2)=='1'){ //<--- 1 is the number of slave sensor station address 96 String msg = command.substring(3); 97 lcd.clear(); 98 lcd.print("My room:"); //Change line 1 text 99 lcd.setCursor(0,1); 100 lcd.print(msg); 101 } 102 */ 103 } 104 command=""; 105 messageCompleted=false; 106 } 107 108} 109 110void readDHT(){ 111 hum = dht.readHumidity(); 112 temp = dht.readTemperature(); 113 String msg = String(temp) + "C " + String(hum) + "%"; 114 lcd.clear(); 115 lcd.print("Here..."); 116 lcd.setCursor(0,1); 117 lcd.print(msg); 118} 119
Downloadable files
Slave
Slave
Master
Master
Documentation
PCB Schematic
Master
PCB Schematic
PCB Schematic
Master
PCB Schematic
PCB Schematic
Slave
PCB Schematic
PCB Schematic
Master
PCB Schematic
Comments
Only logged in users can leave comments