Simple standalone industrial grade weather station
A stunning result will be achieved - the battery life of the weather station is longer than that of similar industrial products.
Components and supplies
1
LCD Nokia 5110
1
Breadboard (generic)
1
Jumper wires (generic)
1
Battery Holder, AA x 2
1
AA Batteries
2
LoRa Module
1
Gravity:SHT1x Humidity and Temperature Sensor
2
ATMEGA328P-PU
Tools and machines
1
Soldering iron (generic)
1
Solder Flux, Rosin
1
Solder Wire, Lead Free
1
Mini Side Cutter, 120mm Length with 25mm Jaw Capacity
Apps and platforms
1
Arduino IDE
Project description
Code
sketch_base
arduino
1/* 2 Autonomous Arduino-weather station on two AA batteries 3 https://create.arduino.cc/projecthub/user2199899/autonomous-arduino-weather-station-on-two-aa-batteries-65ec38 4*/ 5 6#include <avr/io.h> 7#include <util/delay.h> 8 9#include <SPI.h> 10#include <LoRa.h> 11#include <LowPower.h> 12#include "HTU21D.h" 13#include <LCD5110_Graph.h> 14 15#define VccHTU 8 //power supply and pull-up HTU21D (pin 14 AtMega328P, D8) 16HTU21D myHTU21D; 17float Tin; // room temperature 18int Hin; // вindoor humidity 19 20LCD5110 myNokia(3, 4, 5, 6, 7); 21extern uint8_t SmallFont[]; 22extern uint8_t MediumNumbers[]; 23 24float BatIn = 0; // battery voltage 25const int batteryPin = A0; //pin 23 (Atmega328P), to which the battery is connected for voltage measurement 26const float typVbg = 1.132; //calibration constant, 1.0 - 1.2 27 28unsigned int sleepCounter; //sleep timer 29 30int r; //broadcast listening cycle counter 31int mlc; //operating cycle counter without external sensor 32 33String LoRaData, Tout_str, Hout_str, BatIn_str, BatOut_str; 34 35// battery voltage measurement 36float readVcc() { 37 byte i; 38 float result = 0.0; 39 float tmp = 0.0; 40 41 for (i = 0; i < 1; i++) { 42 // Read 1.1V reference against AVcc 43 // set the reference to Vcc and the measurement to the internal 1.1V reference 44#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 45 ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 46#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) 47 ADMUX = _BV(MUX5) | _BV(MUX0); 48#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 49 ADMUX = _BV(MUX3) | _BV(MUX2); 50#else 51 // works on an Arduino 168 or 328 52 ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 53#endif 54 55 _delay_ms(3); // Wait for Vref to settle 56 ADCSRA |= _BV(ADSC); // Start conversion 57 while (bit_is_set(ADCSRA, ADSC)); // measuring 58 59 uint8_t low = ADCL; // must read ADCL first - it then locks ADCH 60 uint8_t high = ADCH; // unlocks both 61 62 tmp = (high << 8) | low; 63 tmp = (typVbg * 1023.0) / tmp; 64 result = result + tmp; 65 _delay_ms(5); 66 } 67 return result; 68} 69 70void Measurement() { 71 float Tin0; 72 // battery voltage measurement 73 BatIn = readVcc(); 74 // measurement of temperature and humidity in the room 75 Hin = myHTU21D.readHumidity(); 76 float Tin_p = myHTU21D.readTemperature(); 77 Tin = 0.1 * int(Tin_p * 10 + 0.5); //rounding to tenths 78 } 79 80void draw() { 81 myNokia.enableSleep(); 82 myNokia.clrScr(); 83 84 //Tin 85 char chr_Tin [5]; 86 String Tin_str = String(Tin); 87 myNokia.setFont(SmallFont); 88 myNokia.print(" C", LEFT, 0); 89 myNokia.print("In", LEFT, 8); 90 myNokia.setFont(MediumNumbers); 91 Tin_str.toCharArray(chr_Tin, 5); //number of characters + 1 92 myNokia.print(String(chr_Tin), CENTER, 0); 93 94 //Tout 95 char chr_Tout [5]; 96 myNokia.setFont(SmallFont); 97 myNokia.print(" C", LEFT, 16); 98 myNokia.print("Out", LEFT, 24); 99 myNokia.setFont(MediumNumbers); 100 Tout_str.toCharArray(chr_Tout, 5); 101 myNokia.print(String(chr_Tout), CENTER, 16); 102 103 // Hin, Hout 104 char chr_Hout [5]; 105 Hout_str.toCharArray(chr_Hout, 4); 106 myNokia.setFont(MediumNumbers); 107 myNokia.print(String(Hout_str), RIGHT, 32); 108 myNokia.setFont(SmallFont); 109 myNokia.print(" In Out", LEFT, 40); 110 myNokia.print(" %", LEFT, 32); 111 myNokia.setFont(MediumNumbers); 112 myNokia.print(String(Hin), LEFT, 32); 113 myNokia.setFont(SmallFont); 114 115 // Battery Level 116 if (BatIn < 2.2) { 117 myNokia.setFont(SmallFont); 118 myNokia.print("Bat", LEFT, 0); 119 } 120 121 if (BatOut_str == "BLow") { 122 myNokia.setFont(SmallFont); 123 myNokia.print("Bat", LEFT, 16); 124 } 125 126 myNokia.disableSleep(); 127 _delay_ms(5); 128} 129 130void drawStart() { 131 myNokia.enableSleep(); 132 myNokia.clrScr(); 133 134 //Tin 135 char chr_Tin [5]; 136 String Tin_str = String(Tin); 137 myNokia.setFont(SmallFont); 138 myNokia.print(" C", LEFT, 0); 139 myNokia.print("In", LEFT, 8); 140 myNokia.setFont(MediumNumbers); 141 Tin_str.toCharArray(chr_Tin, 5); // number of characters + 1 142 myNokia.print(String(chr_Tin), CENTER, 0); 143 144 // Battery Level 145 if (BatIn < 2.2) 146 { 147 myNokia.setFont(SmallFont); 148 myNokia.print("Bat!", RIGHT, 28); 149 } 150 151 //Hin 152 myNokia.setFont(SmallFont); 153 myNokia.print(" %", LEFT, 18); 154 myNokia.print("In", LEFT, 28); 155 myNokia.setFont(MediumNumbers); 156 myNokia.print(String(Hin), CENTER, 18); 157 158 //No signal! 159 myNokia.setFont(SmallFont); 160 myNokia.print("Out - - -", CENTER, 40); 161 162 myNokia.update(); 163 164 myNokia.disableSleep(); 165 _delay_ms(5); 166} 167 168void setup() { 169 Serial.begin(9600); 170 171 pinMode(VccHTU, OUTPUT); 172 digitalWrite(VccHTU, 1); 173 Serial.println("Power ON!"); 174 analogReference(DEFAULT); 175 176 // инициализация дисплея 177 myNokia.InitLCD(); 178 179 myNokia.setFont(SmallFont); 180 myNokia.clrScr(); 181 myNokia.print(">>>>>", CENTER, 20); 182 myNokia.update(); 183 _delay_ms(1000); 184 myNokia.setFont(SmallFont); 185 myNokia.clrScr(); 186 myNokia.print("))-->", CENTER, 20); 187 myNokia.update(); 188 189 if (!LoRa.begin(433E6)) { 190 Serial.println("Loading LoRa receiver failed!"); 191 while (1); 192 193 myNokia.setFont(SmallFont); 194 myNokia.clrScr(); 195 myNokia.print(" -> ->", CENTER, 20); 196 myNokia.update(); 197 } 198 199 // Диапазон для синхрослова – между "0-0xFF". 200 LoRa.setSyncWord(0xF3); 201 Serial.println("Broadcast listening. Waiting for a packet from an external sensor..."); 202 203 myHTU21D.begin(); 204 Measurement(); 205 drawStart(); 206 digitalWrite(VccHTU, 0); 207 _delay_ms(1000); 208 209 myNokia.clrScr(); 210 myNokia.print("Waiting", CENTER, 10); 211 myNokia.print("Message from", CENTER, 22); 212 myNokia.print("OUTSIDE", CENTER, 34); 213 myNokia.update(); 214} 215 216void loop() { 217 r++; 218 digitalWrite(VccHTU, 1); 219 if (r < 600) // 8 MHz; 220 { 221 mlc = 0; 222 // Listening to the broadcast, receiving, decoding. If a signal from an external sensor is received, 223 // then measurements in the room, displaying data on the screen and sleeping. 224 { 225 int packetSize = LoRa.parsePacket(); 226 if (packetSize) { 227 while (LoRa.available()) { 228 LoRaData = LoRa.readString(); 229 } 230 int pos1 = LoRaData.indexOf('#'); 231 int pos2 = LoRaData.indexOf('$'); 232 Tout_str = LoRaData.substring(0, pos1); 233 Hout_str = LoRaData.substring(pos1 + 1, pos2); 234 BatOut_str = LoRaData.substring(pos2 + 1, LoRaData.length()); 235 236 if ((LoRaData).substring(pos1, pos1 + 1) == "#") { 237 Serial.println("Принято, декодировано! r = " + String(r)); 238 r = 0; 239 Measurement(); 240 draw(); 241 digitalWrite(VccHTU, 0); 242 // sleepCounter = 49; 16 MHz 243 // sleepCounter = 48; 8 MHz 244 for (sleepCounter = 48; sleepCounter > 0; sleepCounter--) 245 { 246 digitalWrite(VccHTU, 1); 247 LoRa.sleep (); 248 LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF); 249 } 250 } 251 } 252 } 253 } else { 254 r = 600; 255 if (mlc < 250) // 4 hours, operating time without external sensor 256 { 257 Serial.println("Operation without external sensor."); 258 LoRa.sleep (); 259 Measurement(); 260 drawStart(); 261 digitalWrite(VccHTU, 0); 262 263 for (sleepCounter = 6; sleepCounter > 0; sleepCounter--) 264 { 265 digitalWrite(VccHTU, 1); 266 LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); 267 } 268 mlc++; 269 } else { 270 r = 0; 271 mlc = 0; 272 } 273 } 274 _delay_ms(110); 275} 276 277int main() { 278 init(); 279 setup(); 280 281 for (;;) { 282 loop(); 283 } 284}
sketch_out-sensor
arduino
1/* 2 Autonomous Arduino-weather station on two AA batteries 3 https://create.arduino.cc/projecthub/user2199899/autonomous-arduino-weather-station-on-two-aa-batteries-65ec38 4*/ 5 6#include <avr/io.h> 7#include <util/delay.h> 8 9#include <SPI.h> 10#include <LoRa.h> 11#include <LowPower.h> 12#include <Wire.h> 13#include <avr/power.h> 14#include "HTU21D.h" 15 16#define VccHTU 8 //power and pull HTU21D (pin 14 AtMega328P, D8) 17HTU21D myHTU21D; 18float Tout; // temperature 19int Hout; // humidity 20 21unsigned int sleepCounter, sleepCounter0; // counter that sets the sleep time 22int pct; // counter of the number of packets before going to sleep 23String messageOut; // LoRa message 24float BatOut; // battery voltage 25const int batteryPin = A0; // pin 23 (Atmega328P), to which the battery is connected for voltage measurement 26const float typVbg = 1.132; // calibration constant, 1.0 - 1.2 27 28int counter = 0; 29// battery voltage measurement 30float readVcc() { 31 byte i; 32 float result = 0.0; 33 float tmp = 0.0; 34 35 for (i = 0; i < 1; i++) { 36 // Read 1.1V reference against AVcc 37 // set the reference to Vcc and the measurement to the internal 1.1V reference 38#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) 39 ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 40#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) 41 ADMUX = _BV(MUX5) | _BV(MUX0); 42#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) 43 ADMUX = _BV(MUX3) | _BV(MUX2); 44#else 45 // works on an Arduino 168 or 328 46 ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); 47#endif 48 49 _delay_ms(3); // Wait for Vref to settle 50 ADCSRA |= _BV(ADSC); // Start conversion 51 while (bit_is_set(ADCSRA, ADSC)); // measuring 52 53 uint8_t low = ADCL; // must read ADCL first - it then locks ADCH 54 uint8_t high = ADCH; // unlocks both 55 56 tmp = (high << 8) | low; 57 tmp = (typVbg * 1023.0) / tmp; 58 result = result + tmp; 59 _delay_ms(5); 60 } 61 return result; 62} 63 64void Measurement () { 65 // measurement of temperature and humidity 66 Hout = myHTU21D.readHumidity(); 67 68 float Tout_p = myHTU21D.readTemperature(); 69 Tout = 0.1 * int(Tout_p * 10 + 0.5); //rounding to tenths 70 71 // измерение напряжения батареек 72 BatOut = 0.1 * int(readVcc() * 10 + 0.5); 73 if (BatOut < 2.2) { 74 BatOut = 0.0; 75 } else { 76 BatOut = 2.2; 77 } 78} 79 80void SendMessage () { 81 // send data (temperature, humidity, battery status) 82 if (BatOut > 2.1) { 83 messageOut = String(Tout) + "#" + String(Hout) + "$" + String("BGood"); 84 } 85 else { 86 messageOut = String(Tout) + "#" + String(Hout) + "$" + String("BLow"); 87 } 88 89 LoRa.beginPacket(); 90 LoRa.print(messageOut); 91 LoRa.endPacket(); 92} 93 94void setup() { 95 Serial.begin(9600); 96 Serial.println("Power ON"); 97 analogReference(DEFAULT); 98 99 pinMode(VccHTU, OUTPUT); 100 digitalWrite(VccHTU, 1); 101 _delay_ms(200); 102 myHTU21D.begin(); 103 104 int counter = 0; 105 while (!LoRa.begin(433E6) && counter < 10) { 106 Serial.println("Could not find LoRa transmitter!"); 107 counter++; 108 _delay_ms(500); 109 } 110 LoRa.setTxPower(4); // transmitter power, 2...20 dB 111 LoRa.setSyncWord(0xF3); 112} 113 114void loop() { 115 digitalWrite(VccHTU, 1); 116 if (pct < 3) 117 { // measurements, sending packets 118 Serial.println(messageOut); 119 Measurement (); 120 SendMessage (); 121 } else {// measurements, sending a packet and a long sleep 122 Serial.println(messageOut); 123 Serial.println("sleep ..."); 124 Measurement (); 125 SendMessage (); 126 for (sleepCounter = 6; sleepCounter > 0; sleepCounter--) 127 { 128 digitalWrite(VccHTU, 0); 129 digitalWrite(VccHTU, 1); 130 LoRa.sleep (); 131 LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); 132 } 133 pct = 0; 134 } 135 pct++; 136 if (pct >= 3) pct = 3; // counter overflow protection 137} 138 139int main() { 140 init(); 141 setup(); 142 143 for (;;) { 144 loop(); 145 } 146}
Downloadable files
Base
Base

External sensor
External sensor

Comments
Only logged in users can leave comments