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.
Arduino Mega 2560
ILI9341 TFT Display
Adafruit DS1307 RTC Breakout
VS1838B IR Receiver
DS18B20
Resistor
Adafruit MS8607 PHT Sensor
/*
* 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