Translate

Monitor Suhu Ruangan Interface 7 Segment Sensor DS18B20

Monitor Suhu Ruangan Interface 7 Segment Sensor DS18B20


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk memonitor suhu ruangan menggunakan interface 7segment, alat ini menggunakan sensor ds18b20 water proof. untuk lebih jelasnya berikut adalah komponen dan kodingnya


a. Arduino Uno




b. Modul 7Segment




c. Sensor Suhu DS18B20





d. Program Arduino IDE

#include <Wire.h>
#include <OneWire.h>
OneWire  ds(10);  //output ds18b20 ke pin 10 arduino

byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
int celsius, fahrenheit;
 
byte zero  = B00000011;
byte one   = B10011111;
byte two   = B00100101;
byte three = B00001101;
byte four  = B10011001;
byte five  = B01001001;
byte six   = B01000001;
byte seven = B00011111;
byte eight = B00000001;
byte nine  = B00001001;

int latchPin = 4;  //Pin connected to STR(pin 1) of HEF4094
int clockPin = 3; //Pin connected to CLK(pin 3) of HEF4094
int dataPin = 2;  //Pin connected to D(pin 2) of HEF4094
int oe = 5;  //Pin connected to OE(pin 2) of HEF4094

int temp;
int x = 5;
int y;
int sensorValue;

void setup(){
 Serial.begin(9600);
 pinMode(latchPin, OUTPUT);
 pinMode(clockPin, OUTPUT);
 pinMode(dataPin, OUTPUT);
 pinMode(oe, OUTPUT);
 digitalWrite(oe,HIGH);
}

void loop(){
           
 if ( !ds.search(addr)) {
    ds.reset_search();
    delay(250);
    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

  present = ds.reset();
  ds.select(addr);   
  ds.write(0xBE);       

  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) {
      // "count remain" gives full 12 bit resolution
      raw = (raw & 0xFFF0) + 12 - data[6];
    }
  } else {
    byte cfg = (data[4] & 0x60);
    // at lower res, the low bits are undefined, so let's zero them
    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
    //// default is 12 bit resolution, 750 ms conversion time
  }
  celsius = (float)raw / 16.0;
 
  temp = celsius;
  int ribuan = temp / 1000;
  temp = temp % 1000;
  int ratusan = temp / 100;
  temp = temp % 100;
  int puluhan = temp / 10;
  int satuan = temp % 10;

 switch(ratusan){
   case 0:
   ratusan = zero;
   break;
   case 1:
   ratusan = one;
   break;
   case 2:
   ratusan = two;
   break;
   case 3:
   ratusan = three;
   break;
   case 4:
   ratusan = four;
   break;
   case 5:
   ratusan = five;
   break;
   case 6:
   ratusan = six;
   break;
   case 7:
   ratusan = seven;
   break;
   case 8:
   ratusan = eight;
   break;
   case 9:
   ratusan = nine;
   break;  
 }
  
 switch(puluhan){
   case 0:
   puluhan = zero;
   break;
   case 1:
   puluhan = one;
   break;
   case 2:
   puluhan = two;
   break;
   case 3:
   puluhan = three;
   break;
   case 4:
   puluhan = four;
   break;
   case 5:
   puluhan = five;
   break;
   case 6:
   puluhan = six;
   break;
   case 7:
   puluhan = seven;
   break;
   case 8:
   puluhan = eight;
   break;
   case 9:
   puluhan = nine;
   break;  
 }

 switch(satuan){
   case 0:
   satuan = zero;
   break;
   case 1:
   satuan = one;
   break;
   case 2:
   satuan = two;
   break;
   case 3:
   satuan = three;
   break;
   case 4:
   satuan = four;
   break;
   case 5:
   satuan = five;
   break;
   case 6:
   satuan = six;
   break;
   case 7:
   satuan = seven;
   break;
   case 8:
   satuan = eight;
   break;
   case 9:
   satuan = nine;
   break; 
 }

  digitalWrite(latchPin, HIGH); //Pull latch HIGH to send data
  shiftOut(dataPin, clockPin, LSBFIRST, satuan);
  shiftOut(dataPin, clockPin, LSBFIRST, puluhan);
  shiftOut(dataPin, clockPin, LSBFIRST, ratusan);
  digitalWrite(latchPin, LOW); //Pull latch HIGH to send data
  delay(1000);
  
 }




e. VIDEO HASILNYA







No comments:

Post a Comment