Arduino UNO digunakan untuk membaca nilai temperatur dengan 3 sensor suhu jenis DS1820, LM35 dan Thermocouple . Hasil pembacaan ketiga sensor akan ditampilkan ke Serial Monitor.
Kebutuhan Hardware
- Arduino UNO Board
- Modul sensor temperatur DS1820
- Modul sensor LM35
- Modul Sensor Thermocouple dan driver MAX6675
- Power Supply +5 Vdc
Sensor Thermocouple | Source
Sensor DS1820 Waterproof | Source
Sensor LM35 | Source
Schematic
Koneksi Arduino dengan Sensor DS1820
Koneksi Arduino dengan Driver Max6675
Koneksi Arduino dengan Sensor LM35
Source Code/Sketch
#include <OneWire.h>
#include <Wire.h>
#include "max6675.h"
OneWire ds(11); // on pin 11 --DS1820
int thermoDO = 8;
int thermoCS = 9;
int thermoCLK = 10;
unsigned int adc,tempDS,tempLM,tempTC;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
//============================================
void setup(void) {
Serial.begin(9600);
Serial.println("Monitoring 3 Sensor Suhu : DS1820, Thermocouple, LM35");
}
//===========================================
void loop(void) {
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
//===================================
if ( !ds.search(addr)) {
ds.reset_search();
delay(250);
return;
}
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10: // Chip = DS18S20 or old DS1820
type_s = 1;
break;
case 0x28: // Chip = DS18B20
type_s = 0;
break;
case 0x22: // Chip = DS1822
type_s = 0;
break;
default: //Device is not a DS18x20 family device.
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
raw = (raw & 0xFFF0) + 12 - data[6];
}
}
else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
tempDS=celsius;
//====================
adc = analogRead(0);
tempLM=(adc*5)/10;
//====================
celsius=thermocouple.readCelsius();
tempTC=celsius;
Serial.print("Temp DS1820=");
Serial.print(tempDS);
Serial.println(" Celcius");
Serial.print("Temp Thermocouple=");
Serial.print(tempTC);
Serial.println(" Celcius");
Serial.print("Temp LM35=");
Serial.print(tempLM);
Serial.println(" Celcius");
delay(1000);
}
#include <Wire.h>
#include "max6675.h"
OneWire ds(11); // on pin 11 --DS1820
int thermoDO = 8;
int thermoCS = 9;
int thermoCLK = 10;
unsigned int adc,tempDS,tempLM,tempTC;
MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
//============================================
void setup(void) {
Serial.begin(9600);
Serial.println("Monitoring 3 Sensor Suhu : DS1820, Thermocouple, LM35");
}
//===========================================
void loop(void) {
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;
//===================================
if ( !ds.search(addr)) {
ds.reset_search();
delay(250);
return;
}
// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10: // Chip = DS18S20 or old DS1820
type_s = 1;
break;
case 0x28: // Chip = DS18B20
type_s = 0;
break;
case 0x22: // Chip = DS1822
type_s = 0;
break;
default: //Device is not a DS18x20 family device.
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44, 1); // start conversion, with parasite power on at the end
delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
raw = (raw & 0xFFF0) + 12 - data[6];
}
}
else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
tempDS=celsius;
//====================
adc = analogRead(0);
tempLM=(adc*5)/10;
//====================
celsius=thermocouple.readCelsius();
tempTC=celsius;
Serial.print("Temp DS1820=");
Serial.print(tempDS);
Serial.println(" Celcius");
Serial.print("Temp Thermocouple=");
Serial.print(tempTC);
Serial.println(" Celcius");
Serial.print("Temp LM35=");
Serial.print(tempLM);
Serial.println(" Celcius");
delay(1000);
}
Jalannya Alat
Jalankan Serial Monitor (dari menu Tool – Serial Monitor) set baud rate pada nilai 9600 bps. Pada Serial Monitor akan tampil nilai temperature yang dibaca oleh Arduino dengan sensor suhu DS1820 , LM35 dan Thermocouple. Jika temperatur berubah, tampilan di Serial Monitor akan mengikutinya.
Video untuk Project II - 18. Mengakses 3 Channel Suhu, LM35, DS1820 dan Thermocouple berbasis Arduino
KAMI MELAYANI JASA PEMBUATAN HARDWARE ATAU SOFTWARE BERBASIS ARDUINO
KONTAK KAMI 085743320570 (adi sanjaya)
No comments:
Post a Comment