Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino Mega 2560-Based Multi-Sensor Weather Station with TFT Display and IR Control

Image of Arduino Mega 2560-Based Multi-Sensor Weather Station with TFT Display and IR Control

Circuit Documentation

Summary

This project involves an Arduino Mega 2560 microcontroller interfaced with various sensors and modules. The circuit reads temperature data from multiple DS18B20 sensors, displays the data on an ILI9341 TFT display, and maintains time using an Adafruit DS1307 RTC module. Additionally, it receives IR signals using a VS1838B IR receiver.

Component List

  1. Arduino Mega 2560

    • Description: A microcontroller board based on the ATmega2560.
    • Pins: IOREF, RESET, 3V3, 5V, GND, VIN, A0-A15, D0-D53, AREF, SDA, SCL
  2. ILI9341 TFT Display

    • Description: A 2.8" TFT display with a resolution of 240x320 pixels.
    • Pins: SD_CS, SD_MOSI, SD_MISO, SD_SCK, VCC, GND, CS, RESET, D/C, SD(MOSI), SCK, LED, SDO(MISO), T_CLK, T_CS, T_DIN, T_OUT, T_IRQ
  3. Adafruit DS1307 RTC Breakout

    • Description: A real-time clock module that keeps track of the current time.
    • Pins: SQW, SCL, SDA, VCC, GND
  4. VS1838B IR Receiver

    • Description: An infrared receiver module for receiving IR signals.
    • Pins: OUT, GND, VCC
  5. DS18B20

    • Description: A digital temperature sensor.
    • Pins: VDD, DQ, GND
  6. Resistor

    • Description: A 4.7k Ohm resistor.
    • Pins: pin1, pin2
    • Properties: Resistance: 4700 Ohms
  7. Adafruit MS8607 PHT Sensor

    • Description: A sensor for measuring pressure, humidity, and temperature.
    • Pins: VCC, 3.3V, GND, SCL, SDA

Wiring Details

Arduino Mega 2560

  • 3V3 connected to LED of ILI9341 TFT Display
  • D51 connected to SD(MOSI) of ILI9341 TFT Display
  • D52 connected to SCK of ILI9341 TFT Display
  • D21/SCL connected to SCL of Adafruit MS8607 PHT Sensor, Adafruit DS1307 RTC Breakout
  • D20/SDA connected to SDA of Adafruit MS8607 PHT Sensor, Adafruit DS1307 RTC Breakout
  • 5V connected to pin1 of Resistor, VCC of Adafruit DS1307 RTC Breakout, VCC of VS1838B IR Receiver, VCC of Adafruit MS8607 PHT Sensor, VCC of ILI9341 TFT Display
  • D3 PWM connected to DQ of DS18B20 sensors via pin2 of Resistor
  • GND connected to GND of Adafruit DS1307 RTC Breakout, GND of VS1838B IR Receiver, GND of Adafruit MS8607 PHT Sensor, VDD of DS18B20 sensors, GND of ILI9341 TFT Display
  • A1 connected to CS of ILI9341 TFT Display
  • A2 connected to D/C of ILI9341 TFT Display
  • A3 connected to RESET of ILI9341 TFT Display
  • D2 PWM connected to OUT of VS1838B IR Receiver

ILI9341 TFT Display

  • LED connected to 3V3 of Arduino Mega 2560
  • SD(MOSI) connected to D51 of Arduino Mega 2560
  • SCK connected to D52 of Arduino Mega 2560
  • VCC connected to 5V of Arduino Mega 2560
  • GND connected to GND of Arduino Mega 2560
  • CS connected to A1 of Arduino Mega 2560
  • D/C connected to A2 of Arduino Mega 2560
  • RESET connected to A3 of Arduino Mega 2560

Adafruit DS1307 RTC Breakout

  • SCL connected to D21/SCL of Arduino Mega 2560
  • SDA connected to D20/SDA of Arduino Mega 2560
  • VCC connected to 5V of Arduino Mega 2560
  • GND connected to GND of Arduino Mega 2560

VS1838B IR Receiver

  • OUT connected to D2 PWM of Arduino Mega 2560
  • GND connected to GND of Arduino Mega 2560
  • VCC connected to 5V of Arduino Mega 2560

DS18B20 Sensors

  • DQ connected to D3 PWM of Arduino Mega 2560 via pin2 of Resistor
  • GND connected to 5V of Arduino Mega 2560
  • VDD connected to GND of Arduino Mega 2560

Resistor

  • pin1 connected to 5V of Arduino Mega 2560
  • pin2 connected to DQ of DS18B20 sensors

Adafruit MS8607 PHT Sensor

  • SCL connected to D21/SCL of Arduino Mega 2560
  • SDA connected to D20/SDA of Arduino Mega 2560
  • VCC connected to 5V of Arduino Mega 2560
  • GND connected to GND of Arduino Mega 2560

Code Documentation

/*
 * Arduino Mega 2560 Circuit Project
 * This code reads temperature data from multiple DS18B20 sensors,
 * displays the data on an ILI9341 TFT display, and maintains time
 * using an Adafruit DS1307 RTC module. It also receives IR signals
 * using a VS1838B IR receiver.
 */

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <RTClib.h>
#include <IRremote.h>

// Pin definitions
#define TFT_CS A1
#define TFT_DC A2
#define TFT_RST A3
#define ONE_WIRE_BUS 3
#define IR_RECEIVE_PIN 2

// Initialize display
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);

// Initialize oneWire instance
OneWire oneWire(ONE_WIRE_BUS);

// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);

// Initialize RTC
RTC_DS1307 rtc;

// Initialize IR receiver
IRrecv irrecv(IR_RECEIVE_PIN);
decode_results results;

void setup() {
  // Start serial communication
  Serial.begin(9600);

  // Initialize the display
  tft.begin();
  tft.setRotation(3);
  tft.fillScreen(ILI9341_BLACK);

  // Initialize temperature sensors
  sensors.begin();

  // Initialize RTC
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (!rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // Set the RTC to the current date and time
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }

  // Initialize IR receiver
  irrecv.enableIRIn();
}

void loop() {
  // Read temperature sensors
  sensors.requestTemperatures();
  float temp1 = sensors.getTempCByIndex(0);
  float temp2 = sensors.getTempCByIndex(1);
  float temp3 = sensors.getTempCByIndex(2);

  // Display temperature on TFT
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_WHITE); tft.setTextSize(2);
  tft.print("Temp1: "); tft.println(temp1);
  tft.print("Temp2: "); tft.println(temp2);
  tft.print("Temp3: "); tft.println(temp3);

  // Read and display time from RTC
  DateTime now = rtc.now();
  tft.print(now.year(), DEC); tft.print('/');
  tft.print(now.month(), DEC); tft.print('/');
  tft.print(now.day(), DEC); tft.print(' ');
  tft.print(now.hour(), DEC); tft.print(':');
  tft.print(now.minute(), DEC); tft.print(':');
  tft.print(now.second(), DEC); tft.println();

  // Check for IR signal
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume();
  }

  delay(1000); // Update every second
}

This code initializes