Untuk waktu yang lama, saya ingin membuat stasiun cuaca tanpa menggunakan internet. Sangat bagus untuk mengukur data cuaca di sekitar Anda dan melihat data saat diinginkan. jadi, saya membuat stasiun cuaca lokal yang tampak keren yang dapat mengukur tekanan udara di sekitar Anda, suhu, kelembaban, dan indeks UV hari itu (jika Anda meletakkannya di dekat jendela). Tunggu ada lebihnya! juga memiliki layar Jam untuk menunjukkan Waktu, tanggal, dan hari dalam seminggu.
Dalam tutorial ini, saya akan menunjukkan cara membuat stasiun cuaca dingin ini dalam langkah-langkah tersebut.
BMP280 adalah sensor tekanan dan suhu atmosfer dan menggunakan protokol I2C atau SPI untuk berkomunikasi dengan Arduino. Disini saya menggunakan SPI. Untuk menggunakan SPI, sambungkan-
Pada bagian kode, untuk menggunakan sensor ini kita membutuhkan sebuah library. pertama-tama saya sertakan librarynya pada kode #include
. Anda dapat mengunduh perpustakaan dari sini.
Kemudian saya menentukan pin SPI untuk sensor. Pada fungsi setup, saya menginisialisasi sensor BMP, dan pada fungsi loop, saya membaca data tekanan dan suhu menggunakan bmp.readPressure()
dan bmp.readTemperature()
memerintah. Saya membagi nilai tekanan dengan 100 untuk mengukur tekanan dalam satuan hPa. Untuk mengukur ketinggian saya menggunakan bmp.readAltitude(1005.47)
memerintah. Di sini Anda harus mengubah nilai (1005.47)
sesuai dengan tekanan rata-rata area Anda.
Stasiun cuaca ini juga memiliki layar waktu yang dapat menunjukkan waktu saat ini, tanggal, dan hari yang lemah. Untuk tujuan ini, saya menggunakan modul DS231 RTC, yang menggunakan protokol I2C untuk berkomunikasi. jadi untuk menggunakan ini, sambungkan-
Saya menggunakan sensor ini untuk mengukur kelembaban. Untuk itu, saya menghubungkan data keluar ke Arduino D2 . Dan dalam program tersebut, saya menyertakan library DHT #include
kemudian di setup saya menginisialisasi sensor dan di loop, saya membaca nilai kelembaban menggunakan dht.readHumidity()
perintah.
Saya menggunakan layar OLED 0,96" 128*64 untuk proyek ini, ia menggunakan protokol I2C jadi saya menghubungkannya ke Arduino sebagai berikut-
Dalam program, pada awalnya, saya menyertakan perpustakaan Adafruit_SSD1306 dan Adafruit_GFX
kemudian saya membuat variabel tampilan dan juga menambahkan beberapa bitmap untuk menampilkan beberapa gambar. Dalam pengaturan, saya menginisialisasi tampilan. kemudian di loop, saya menampilkan setiap data menggunakan display.print()
fungsi. Saya menampilkan data pada empat halaman, Waktu, Tekanan, suhu &kelembaban, dan indeks_UV. ada jeda 5 detik antara setiap halaman.
Kode
Kode stasiun cuaca lokalArduino
#include #include #include #include #include #include #include #include #include //#include #define SCREEN_WIDTH 128#define SCREEN_HEIGHT_SCREEN_HEIGHT_SCREEN_WID 64#define , OLED_RESET);#define BMP_SCK (13)#define BMP_MISO (12)#define BMP_MOSI (11)#define BMP_CS (10)DS3231 jam;bool abad =false;bool h12Flag;bool pmFlag;Adafruit_BMP280 bmp(BMP_CS, BMP_MISOSI, BMP_MISOSI, BMP_MISOSI , BMP_SCK);#define DHTPIN 2#define DHTTYPE DHT11DHT dht(DHTPIN, DHTTYPE);const unsigned char PROGMEM frame0 [] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x01, 0xFF, 0x80, 0x00, 0x00, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x7F, 0x81, 0xFE, 0x00, 0x00, 0xFC, 0x00, 0x3F, 0x01 0xF0, 0x00, 0x0F, 0x80, 0x03, 0xE0, 0x18, 0x07, 0xC0, 0x07, 0x86, 0 x18, 0x61, 0xE0, 0x0F, 0x02, 0x00, 0x40, 0xF0, 0x0F, 0x02, 0x00, 0x40, 0xF0, 0x1E, 0x00, 0x00, 0x00, 0x78, 0x1C, 0x40, 0x00, 0x023, 0x38, 0x 0x00, 0x06, 0x3C, 0x3C, 0x01, 0x80, 0x00, 0x3C, 0x38, 0x00, 0x80, 0x00, 0x1C, 0x38, 0x00, 0xC0, 0x00, 0x1C, 0x78, 0x00, 0xE0, 0x00, 0x1E 0xF0, 0x03, 0x9E, 0x79, 0xC0, 0x7C, 0x03, 0x9E, 0x78, 0x00, 0x7E, 0x00, 0x1E, 0x38, 0x00, 0x7E, 0x00, 0x1C, 0x38, 0xFC, 0xFF, 0x3F, 0x3F, 0xF 0x7E, 0x3F, 0x3C, 0x3C, 0xFE, 0x7E, 0x7F, 0x3C, 0x1C, 0x7E, 0x18, 0x7E, 0x38, 0x1E, 0x3F, 0x00, 0xFC, 0x78, 0x0F, 0x3, 0xFC, 0x3F, 0xC 0xFF, 0xF8, 0xF0, 0x07, 0x87, 0xFF, 0xE1, 0xE0, 0x03, 0xC1, 0xFF, 0x83, 0xC0, 0x03, 0xF0, 0x3C, 0x0F, 0xC0, 0x01, 0xFC, 0x00, 0x3F, 0x80, 0x80 0x81, 0xFE, 0x00, 0x00, 0x3F, 0xFF, 0xFC, 0x00, 0x00, 0x0F, 0xFF, 0xF0, 0x00, 0x00, 0x01, 0xFF, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};const unsigned char PROGMEM frame1 [] ={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x00, 0x00, 0x01, 0x00, 0x9D, 0x80, 0x00, 0x 0xB4, 0xE0, 0x00, 0x06, 0x80, 0xA6, 0x80, 0x00, 0x04, 0xC0, 0xA6, 0xE0, 0x00, 0x0C, 0x40, 0xA6, 0xE0, 0x00, 0x08, 0x60, 0xA6, 0x80, 0x00 0xA6, 0xE0, 0x00, 0x08, 0x60, 0xA6, 0x80, 0x00, 0x0E, 0xC0, 0xA6, 0xE0, 0x00, 0x03, 0x80, 0xA6, 0x80, 0x00, 0x00, 0x10, 0xA6, 0x38,00, 0x00 0xA6, 0xE0, 0x00, 0x00, 0x38, 0xA6, 0x80, 0x00, 0x00, 0x6C, 0xA6, 0xE0, 0x00, 0x00, 0x44, 0xA6, 0x80, 0x00, 0x00, 0x6C, 0xA6, 0xE0, 0x 0xA6, 0x80, 0x00, 0x00, 0x00, 0xA6, 0x80, 0x00, 0x00, 0x00, 0xA4, 0xE0, 0x00, 0x00, 0x00, 0xA6, 0x80, 0x00, 0x00, 0x40, 0xA6, 0xE0, 0x00, 00 0xA6, 0x80, 0x00, 0x01, 0xA0, 0xA6, 0xE0, 0x00, 0x01, 0x30, 0xA6, 0xE0, 0x00, 0x03, 0x10, 0xA6, 0x80, 0x00, 0x02, 0x18, 0xA6, 0xE0, 0x00, 0xE0, 0x00 0xA6, 0x80, 0x00, 0x06, 0x08, 0xA6, 0x80, 0x00, 0x02, 0x19, 0xA6, 0xC0, 0x00, 0x03, 0xF3, 0x26, 0x60 , 0x00, 0x00, 0xC6, 0x26, 0x30, 0x00, 0x00, 0x0C, 0xE3, 0x10, 0x00, 0x00, 0x09, 0x80, 0x98, 0x00, 0x00, 0x19, 0x00, 0xC8, 0x00, 0x00, 0x13, 0x00, 0x13 , 0x00, 0x00, 0x12, 0x00, 0x6C, 0x00, 0x00, 0x12, 0x00, 0x6C, 0x00, 0x00, 0x12, 0x00, 0x6C, 0x00, 0x00, 0x1B, 0x00, 0x4C, 0x00, 0x00, 0x09 , 0x00, 0x00, 0x0C, 0xC1, 0x98, 0x00, 0x00, 0x04, 0x7F, 0x30, 0x00, 0x00, 0x06, 0x1C, 0x60, 0x00, 0x00, 0x03, 0x81, 0xC0, 0x00, 0x00, 0x00 , 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};const unsigned char PROGMEM frame2 [] ={0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF , 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF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0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0 xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x80};pengaturan batal() { Serial.begin(57600); if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { Serial.println(F("SSD1306 gagal")); } Kawat.mulai(); dht.mulai(); if (!bmp.begin()) { Serial.println(F("Masalah.bmp")); sementara (1) penundaan (10); } tampilan.clearDisplay(); display.setTextColor(PUTIH); tampilan.setTextSize(1); display.setCursor(0, 9); display.setFont(&FreeSans9pt7b); display.println("**** LOKAL ****"); display.setCursor(0, 38); display.setFont(&FreeMonoBoldOblique12pt7b); display.println("air"); display.setCursor(27, 58); display.println("Stasiun"); tampilan.display(); penundaan(2000); bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Mode Operasi. */ Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */ Adafruit_BMP280::SAMPLING_X16, /* Tekanan oversampling */ Adafruit_BMP280::FILTER_X16, /* Adafruit_BMP280::STANDBY_MS_500); /* Waktu siaga. */}void loop() { //Tampilan waktu.clearDisplay(); display.setTextColor(PUTIH); tampilan.setTextSize(1); display.setCursor(13, 15); display.setFont(&FreeMonoBoldOblique12pt7b); display.print(clock.getHour(h12Flag, pmFlag)); display.setCursor(38, 15); tampilan.println(":"); display.setCursor(50, 15); display.println(jam.getMinute()); display.setCursor(70, 15); if (pmFlag) { display.println("PM"); } else { display.println("AM "); } display.setFont(&FreeSans9pt7b); display.setCursor(20, 60); display.println(jam.getDate()); display.setCursor(40, 60); tampilan.println("/"); display.setCursor(46, 60); display.println(jam.getBulan(abad)); display.setCursor(65, 60); tampilan.println("/"); display.setCursor(70, 60); tampilan.println("20"); display.setCursor(90, 60); display.println(jam.getTahun()); display.setCursor(30, 30); display.setFont(&FreeSans9pt7b); switch (clock.getDoW()) { kasus 1:display.println("Sabtu"); merusak; kasus 2:display.println("Minggu"); merusak; kasus 3:display.println("Senin"); merusak; kasus 4:display.println("Selasa"); merusak; kasus 5:display.println("Rabu"); merusak; kasus 6:display.println("Kamis"); merusak; kasus 7:display.println("Jumat"); merusak; } tampilan.tampilan(); penundaan(5000); //P tampilan.clearDisplay(); display.drawBitmap(0, 0, frame0, 40, 40, 1); display.setFont(&FreeSans9pt7b); display.setCursor(41, 28); display.println(bmp.readPressure() / 100); display.setCursor(110, 28); tampilan.setFont(); display.println("hPa"); display.setCursor(0, 55); display.setFont(&FreeSans9pt7b); display.println("Ketinggian:"); display.setCursor(65, 62); display.println(bmp.readAltitude(1005.47)); display.setCursor(113, 62); tampilan.println("m"); tampilan.display(); penundaan(5000); //T&RH display.clearDisplay(); display.setFont(&FreeMonoBoldOblique12pt7b); display.drawBitmap(0, 5, frame1, 40, 51, 1); display.setCursor(35, 30); display.print(bmp.readTemperature()); display.setFont(&FreeSans9pt7b); display.setCursor(102, 28); tampilan.println("*"); display.setCursor(110, 31); tampilan.println("C"); tampilan.setFont(); display.setCursor(66, 45); display.println("RH :"); byte RH =dht.readHumidity(); display.setCursor(95, 45); display.println(RH); display.setCursor(110, 45); tampilan.println("%"); display.drawBitmap(0, 56, frame2, 135, 15, 1); tampilan.display(); penundaan(5000); //tampilan UV.clearDisplay(); float sensorValue =analogRead(A0); float sensorVoltage =sensorValue / 1024 * 5.0; int UV_index =sensorVoltage / 0.1; display.setFont(&FreeSans9pt7b); display.setCursor(0, 15); display.print("INDEKS UV"); display.setCursor(58, 45); display.println(UV_index); tampilan.display(); delay(5000);}
Suku cadang dan penutup khusus
Skema