Components and supplies
Arduino Nano R3
DHT 11 module
USB A to mini USB B cable
3D PRINTED ENCLOSURE
BMP-280 PRESSURE SENSOR
1.44 inch ST7735 LCD Display
Tools and machines
Double sided tape
Soldering iron (generic)
3D Printer (generic)
Soldering Wire
Apps and platforms
Fusion 360
Arduino IDE
Project description
Code
THE CODE
c_cpp
THIS IS THE RELEVANT SKETCH FOR THE PROJECT, THE COMMENT STATEMENTS WILL EXPLAIN THE WORKING
1#include <SPI.h> //include Serial Peripheral Interface library 2#include <Wire.h> //include Two Wire Interface library 3#include <Adafruit_GFX.h> // include Adafruit graphics library 4#include <Adafruit_ST7735.h> // include Adafruit ST7735 TFT library 5#include <Adafruit_BMP280.h> // include Adafruit BMP280 sensor library 6#include "DHT.h" //include DHTXX sensor library 7#define DHTPIN 2 //DHT11 data pin connected to arduino pin D2 8#define DHTTYPE DHT11 //specifying the type of DHT sensor used 9#define TFT_RST 8 // TFT RST pin is connected to arduino pin D8 10#define TFT_CS 10 // TFT CS pin is connected to arduino pin D9 11#define TFT_DC 9 // TFT DC pin is connected to arduino pin D10 12// initialize ST7735 SERIES TFT library 13Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST); 14 15// define device I2C address: 0x76 or 0x77 (0x77 is the library default address) 16#define BMP280_I2C_ADDRESS 0x76 17 18Adafruit_BMP280 bmp280; // initialize Adafruit BMP280 library 19DHT dht(DHTPIN, DHTTYPE); // initialize DHT sensor 20 21void setup(void) 22{ 23 dht.begin(); // synchronizing DHT sensor 24 tft.initR(INITR_144GREENTAB); // initialize a ST7735S chip, black tab 25 tft.fillScreen(ST77XX_BLACK); // setting black background 26 tft.drawFastHLine(0, 15 , tft.width(), ST77XX_CYAN);// draw horizontal seperation line at position (0, 15) 27 28 tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK); // set text color to white and black background 29 tft.setTextSize(1); // setting text size to 1 30 //tft.setCursor(4, 0); // move cursor to position (4, 0) pixel 31 //tft.print("ARDUINO + ST7735 TFT"); 32 tft.setCursor(25, 5); // move cursor to position (25, 5) pixel 33 tft.print("WEATHER BUDDY"); 34 35 // initialize the BMP280 sensor 36 if( bmp280.begin(BMP280_I2C_ADDRESS) == 0 ) 37 { // connection error or device address wrong! 38 tft.setTextColor(ST77XX_RED, ST77XX_CYAN); // set text color to red and black background 39 tft.setTextSize(2); // setting text size to 2 40 tft.setCursor(5, 76); // move cursor to position (5, 76) pixel 41 tft.print("Connection"); 42 tft.setCursor(35, 100); // move cursor to position (35, 100) pixel 43 tft.print("Error"); 44 while(1); // stay here 45 } 46 47 tft.drawFastHLine(0, 55, tft.width(), ST77XX_CYAN); // draw horizontal seperation line at position (0, 55)pixel 48 tft.drawFastHLine(0, 95, tft.width(), ST77XX_CYAN); // draw horizontal seperation line at position (0, 195)pixel 49 tft.setTextColor(ST77XX_RED, ST77XX_BLACK); // set text color to red and black background 50 tft.setCursor(30, 20); // move cursor to position (30, 20) pixel 51 tft.print("TEMPERATURE "); // setting heading for first section 52 tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK); // set text color to cyan and black background 53 tft.setCursor(40, 60); // move cursor to position (40, 60) pixel 54 tft.print("HUMIDITY "); // setting heading for second section 55 tft.setTextColor(ST77XX_GREEN, ST7735_BLACK); // set text color to green and black background 56 tft.setCursor(40, 100); // move cursor to position (40, 100) pixel 57 tft.print("PRESSURE "); // setting heading for third section 58 tft.setTextSize(2); // setting text size to 2 59} 60 61// main loop 62void loop() 63 { 64 65 char _buffer[8]; 66 // read temperature, humidity and pressure from the BMP280 sensor 67 float temp = bmp280.readTemperature(); // get temperature in °C 68 float hum = dht.readHumidity(); // get humidity in rH% 69 float pres = bmp280.readPressure(); // get pressure in hPa 70 71 // print temperature (in °C) 72 if(temp < 0) // if temperature < 0 73 sprintf( _buffer, "-%02u.%02u", (int)abs(temp), (int)(abs(temp) * 100) % 100 ); 74 else // if temperature >= 0 75 sprintf( _buffer, " %02u.%02u", (int)temp, (int)(temp * 100) % 100 );// setting the value approximation 76 tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK); // set text color to yellow and black background 77 tft.setCursor(11, 34); // move cursor to position (11,34) pixel 78 tft.print(_buffer); // print temperature from BMP-280 sensor 79 tft.drawCircle(89, 34, 2, ST77XX_YELLOW); // print the degree symbol ( ° )(can be omitted if * is used instead) 80 tft.setCursor(95, 34); // move cursor to position (95,34) pixel 81 tft.print("C"); // print the Celcius symbol 82 83 // 2: print humidity (in %) 84 sprintf( _buffer, "%02u ", (int)(hum)); // setting the value approximation 85 tft.setTextColor(ST77XX_MAGENTA, ST77XX_BLACK); // set text color to magenta and black background 86 tft.setCursor(45, 74); // move cursor to position (45,74) pixel 87 tft.print(_buffer); // print humidity from DHT-11 sensor 88 tft.setCursor(75, 74); // move cursor to position (75,74) pixel 89 tft.print("%"); // print the percentage symbol 90 91 92 // 3: print pressure (in hPa) 93 sprintf( _buffer, "%04u.%02u", (int)(pres/100), (int)((uint32_t)pres % 100) ); // setting the value approximation 94 tft.setTextColor(ST77XX_ORANGE, ST77XX_BLACK); // set text color to orange and black background 95 tft.setCursor(3, 112); // move cursor to position (3,112)pixel 96 tft.print(_buffer); // print atmospheric pressure from BMP-280 97 tft.setCursor(91, 112); // move cursor to position (91,112)pixel 98 tft.print("hPa"); // print unit of atmospheric pressure as hecto pascal 99 100 delay(1000); // wait 1 second before taking next sensor reading 101 102}
Downloadable files
CIRCUIT DIAGRAM
YOU JUST NEED TO FOLLOW THE WIRING SHOWN.
CIRCUIT DIAGRAM
CIRCUIT DIAGRAM
YOU JUST NEED TO FOLLOW THE WIRING SHOWN.
CIRCUIT DIAGRAM
Documentation
3D PARTS
THIS IS THE STL FILE FOR THE 3D PRINTED PARTS I USED
3D PARTS
3D PARTS
THIS IS THE STL FILE FOR THE 3D PRINTED PARTS I USED
3D PARTS
Comments
Only logged in users can leave comments
dnbakshi07
0 Followers
•0 Projects
Table of contents
Intro
46
0