Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views9 pages

Sensors Connection

The document outlines a graduation project involving a sensor circuit using various components including temperature sensors, a pressure sensor, an ultrasonic sensor, an RTC module, and an SD card module, all controlled by an Arduino Uno. It details the wiring connections for each component, shared rules for setup, and includes code for data logging and sensor management. Additionally, it provides instructions for obtaining unique addresses for the DS18B20 temperature sensors used in the project.

Uploaded by

johnhanna414
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views9 pages

Sensors Connection

The document outlines a graduation project involving a sensor circuit using various components including temperature sensors, a pressure sensor, an ultrasonic sensor, an RTC module, and an SD card module, all controlled by an Arduino Uno. It details the wiring connections for each component, shared rules for setup, and includes code for data logging and sensor management. Additionally, it provides instructions for obtaining unique addresses for the DS18B20 temperature sensors used in the project.

Uploaded by

johnhanna414
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

🎓 SENSOR CIRCUIT OF GRADUATION PROJECT

🧩 Components You're Using:

1. ✅ 3x DS18B20 – Measures:
o Inlet air temperature
o Chimney inlet air temperature
o Water temperature
2. ✅ 1x BMP280 – Measures pressure inside the solar chimney
3. ✅ 1x Ultrasonic Sensor (HC-SR04) – Measures water level in the
desalination tank
4. ✅ 1x RTC Module (DS3231 or DS1307) – Keeps accurate time
5. ✅ 1x Micro SD Card Module – Stores the sensor data
6. ✅ Arduino Uno Rev3 – Controls and powers everything

🧠 Shared Rules First (Applies to All Components)


• All VCC/5V lines must go to the Arduino 5V pin
• All GND lines go to Arduino GND
• We can use a breadboard or terminal blocks for cleaner wiring
• Every component should share one common GND
✅ 1. 3 x DS18B20 Temperature Sensors (OneWire)

🔗 WIRING (ALL 3 on the same data pin – D3):

DS18B20
Connection Explanation
Wire
Red (VCC) Arduino 5V Powers the sensor
Black (GND) Arduino GND Ground
Yellow
Arduino D3 All 3 sensors share the same data line
(Data)
4.7kΩ between D3 and Pull-up resistor needed for OneWire
Resistor
5V protocol

📌 We will distinguish between the 3 sensors in code using their unique


address (already handled in my sketch).

✅ 2. BMP280 (Pressure Sensor)

🔗 WIRING (I2C Protocol):

BMP280
Connect to Why
Pin
Arduino 3.3V or Some modules accept both; check your board
VCC
5V label
GND Arduino GND Common ground
SDA Arduino A4 I2C Data line
SCL Arduino A5 I2C Clock line

📌 Shares I2C bus with the RTC. That’s okay — I2C supports multiple devices.
✅ 3. Ultrasonic Sensor (e.g., HC-SR04)

🔗 WIRING:

HC-SR04 Pin Connect to Why


VCC Arduino 5V Power
GND Arduino GND Ground
TRIG Arduino D4 Triggers sound pulse
ECHO Arduino D5 Receives echo response

📌 Use digital pins for TRIG and ECHO — no analog needed.

✅ 4. RTC Module (DS3231 or DS1307)

🔗 WIRING (I2C — shared with BMP280):

RTC Pin Connect to Why


VCC Arduino 5V Power
GND Arduino GND Ground
SDA Arduino A4 Data line
SCL Arduino A5 Clock line

📌 Insert CR1220 coin cell battery into the RTC’s battery holder so it keeps
time even when Arduino is off.
✅ 5. SD Card Module (SPI Communication)

🔗 WIRING (Standard SPI):

SD Module Pin Connect to Arduino Why


CS (Chip Select) D10 To enable SD communication
MOSI D11 SPI data to card
MISO D12 SPI data from card
SCK D13 SPI clock
VCC 5V Power
GND GND Ground

📌 This uses 4 digital pins (D10–D13). Don’t overlap these with other SPI
devices unless you use SPI multiplexing.

🧩 TOTAL ARDUINO PIN USAGE

Arduino Pin Used For


D3 DS18B20 x3 (OneWire)
D4 Ultrasonic TRIG
D5 Ultrasonic ECHO
D10 SD Card CS
D11 SD Card MOSI
D12 SD Card MISO
D13 SD Card SCK
A4 I2C SDA (BMP280 + RTC)
A5 I2C SCL (BMP280 + RTC)

✅ We're well within the pin limit of the Arduino Uno!


We’re using:

• ✅ 3x DS18B20 temperature sensors:


o Sensor 1 → Inlet air temperature
o Sensor 2 → Chimney inlet temperature
o Sensor 3 → Water temperature
• ✅ 1x BMP280 → Pressure
• ✅ 1x Ultrasonic → Water level
• ✅ 1x RTC module (DS3231 or DS1307)
• ✅ 1x SD Card Module

🧠 Important DS18B20 Note:


All three sensors can be connected to the same OneWire pin (e.g. D3), because the DS18B20 uses a
unique internal address.

You’ll scan and save those addresses first, then assign them as:

• sensorAir
• sensorChimney
• sensorWater

🛠️ Wiring for 3 DS18B20 Sensors (shared pin)


Wire Color Connect to Arduino
Red (VCC) 5V
Black (GND) GND
Yellow (DATA) D3 (shared for all 3 sensors)

+ Add a 4.7kΩ resistor between D3 (Data) and 5V.


Code (3 DS18B20 + BMP280 + Ultrasonic + RTC + SD)
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <RTClib.h>
#include <Adafruit_BMP280.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// ----- Pins -----


#define ONE_WIRE_BUS 3
#define TRIG_PIN 4
#define ECHO_PIN 5
#define SD_CS 10

// ----- Sensor Objects -----


OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
Adafruit_BMP280 bmp;
RTC_DS3231 rtc;

// ----- SD File -----


File dataFile;

// ----- Device Addresses -----


DeviceAddress sensorAir = { 0x28, 0xFF, 0x1A, 0xB1, 0x93, 0x16, 0x04, 0xD6
};
DeviceAddress sensorChimney = { 0x28, 0xFF, 0x8C, 0x72, 0x91, 0x16, 0x03,
0xEC };
DeviceAddress sensorWater = { 0x28, 0xFF, 0x39, 0xA3, 0x93, 0x16, 0x04,
0x9B };
// Replace these with your actual addresses (I'll explain how below)

void setup() {
Serial.begin(9600);
sensors.begin();
bmp.begin(0x76);
rtc.begin();

pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);

if (!SD.begin(SD_CS)) {
Serial.println("SD card init failed!");
} else {
dataFile = SD.open("log.txt", FILE_WRITE);
if (dataFile) {
dataFile.println("Time, InletAirTemp, ChimneyTemp, WaterTemp,
Pressure(hPa), WaterLevel(cm)");
dataFile.close();
}
}
}

void loop() {
sensors.requestTemperatures();

float tempAir = sensors.getTempC(sensorAir);


float tempChimney = sensors.getTempC(sensorChimney);
float tempWater = sensors.getTempC(sensorWater);

float pressure = bmp.readPressure() / 100.0F;

// Water Level
digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
long duration = pulseIn(ECHO_PIN, HIGH);
float level = duration * 0.034 / 2;

DateTime now = rtc.now();


String timeStamp = String(now.hour()) + ":" + String(now.minute()) + ":"
+ String(now.second());

Serial.print(timeStamp); Serial.print(" | ");


Serial.print("Air: "); Serial.print(tempAir); Serial.print(" °C, ");
Serial.print("Chimney: "); Serial.print(tempChimney); Serial.print(" °C,
");
Serial.print("Water: "); Serial.print(tempWater); Serial.print(" °C, ");
Serial.print("Pressure: "); Serial.print(pressure); Serial.print(" hPa,
");
Serial.print("Level: "); Serial.print(level); Serial.println(" cm");

dataFile = SD.open("log.txt", FILE_WRITE);


if (dataFile) {
dataFile.print(timeStamp); dataFile.print(", ");
dataFile.print(tempAir); dataFile.print(", ");
dataFile.print(tempChimney); dataFile.print(", ");
dataFile.print(tempWater); dataFile.print(", ");
dataFile.print(pressure); dataFile.print(", ");
dataFile.println(level);
dataFile.close();
}

delay(10000); // Log every 10 seconds


}
🧠 How to Get DS18B20 Addresses
Upload this simple sketch first:

#include <OneWire.h>
#include <DallasTemperature.h>

OneWire oneWire(3); // Change pin if needed


DallasTemperature sensors(&oneWire);

void setup() {
Serial.begin(9600);
sensors.begin();

Serial.println("Looking for devices...");


DeviceAddress deviceAddress;

int deviceCount = sensors.getDeviceCount();


Serial.print("Found "); Serial.print(deviceCount); Serial.println("
device(s).");

for (int i = 0; i < deviceCount; i++) {


if (sensors.getAddress(deviceAddress, i)) {
Serial.print("Device "); Serial.print(i); Serial.print(": ");
for (uint8_t j = 0; j < 8; j++) {
if (deviceAddress[j] < 16) Serial.print("0");
Serial.print(deviceAddress[j], HEX);
if (j < 7) Serial.print(", ");
}
Serial.println();
}
}
}

🧠 Copy the 8-byte address of each sensor and paste into the DeviceAddress variables in
the main code.

You might also like