Altimeter Arduino + Jam Digital dan Suhu

Selamat malah sahabat blogger dan sahabat arduino. pada kesempatan kali ini saya akan memposting project pesanan sahabat saya yang bertema tentang ketinggian. karena sahabat saya ini adalah seorang pendaki gunung dan dia ingin membuat alat yang bisa mengetahui ketinggian dia berada pada saat melakukan pendakian. dan saya mempunyai ide yaitu dengan memanfaatkan sensor BMP280, sensor ini difungsikan untuk mengetahui suatu tekanan pada suatu tempat bahkan ketinggian. jadi sensor tersebut kita gabungkan dengan sebuah microcontroller Arduino yang diengkapi dengan display LCD 16x2. 


tak perlu panjang lebar. mungkin buat teman-teman yang ingin membuatnya juga bisa mengikuti langkah-langkah  yang ada dipostingan ini dengan benar. dan ada beberapa bahan yang harus disiapakan sebelum teman-teman memulai perakitan diantaranya adalah:
1. Arduino Uno R3
2. LCD 16x2
3. sensor BMP280
4. Modul RTC DS3231
5. sensor DHT 11
6. 4 tombol
7. 4 resistor
8. kabel jumper secukupnya
Untuk skematik rangkaian sesuai gambar dibawah ini.

Namun pada kesempatan kali ini saya membuatnya di PCB lubang dan di masukkan kedalam box seperti gambar dibawah ini.







Program Utama

=================================Source Code================================

#include "dht11.h"  
#include "LiquidCrystal.h"  
#include "DS3231.h"
#include "Wire.h" 
#include "Adafruit_BMP280.h"



dht11 DHT11; //Suhu dan kelembapan
Adafruit_BMP280 bmp;  //Sensor Barometric
DS3231 Clock; //Real Time Clock

//Pin Yang digunakan untuk DHT 11
#define DHT11PIN 7

//Pin Yang digunakan Untuk LCD 16x2
LiquidCrystal lcd(13, 12, 11, 10, 8, 7);
/*
LCD RS ke  pin 13
LCD Enable ke pin 12
LCD D4 pin ke pin 11
LCD D5 pin ke pin 10
LCD D6 pin ke pin 9
LCD D7 pin ke pin 8
*/


//PIN Modul BMP280 
//SCL -> SCL or A5
//SDA -> SDA or A4

//PIN Modul RTC DS321 
//SCL -> SCL or A5
//SDA -> SDA or A4


//Pin Penggunaan Tombol
const int nextButton = 6;       //PIN 6
const int editButton = 5;       //PIN 5
const int increaseButton = 4;   //PIN 4
const int descreaseButton = 3; //PIN 3



//************ Variables & Functions *****************//
//variable sensor dan fungsi
int checkDHT11(void);

//BMP280 variables
float BMP_pressure;    //To store the barometric pressure (Pa)
float BMP_temperature; //To store the temperature (oC)
int BMP_altimeter;     //To store the altimeter (m) (you can also use it as a float variable)
void getBMP280Values(void);


//Variable RTC DS3231
int second,minute,hour,date,month,year,DStemperature; 
void ReadDS3231(void);
bool Century=false;
bool h12;
bool PM;
byte ADay, AHour, AMinute, ASecond, ABits;
bool ADy, A12h, Apm;
byte Byear, Bmonth, Bdate, BDoW, Bhour, Bminute, Bsecond;
int startPoint;
int endPoint;
int i, j;
int speed = 50;
String txtMsg = "Entropy";  
String txtMsg1 = "Station";  

#define DisplayDelay 1000     //delay of the LCD refresh at displaying the data from sersors
#define EditDelay 1000         //delay of the LCD refresh at editing time and date

void DisplayIntro(void);                      
char *getDayofweek(int d, int m, int y);      
int isLeapYear(int y);                        
int displayValue=0;               
int editValue=0;                 
bool edit=false;                  
 
//print data from all sensors
void printAll(void);
//print time from DS3231
void printTime(void);
void printHourMinute(void);
//print date from DS3231
void printDate(void);
//print temperature from DHT11
void printTemperature(void);
//print humidity from DHT11
void printHumidity(void);
//print barometer from BMP280
void printBarometer(void);



void setup() {
  pinMode(nextButton, INPUT_PULLUP);
  pinMode(editButton, INPUT_PULLUP);
  pinMode(increaseButton, INPUT_PULLUP);
  pinMode(descreaseButton, INPUT_PULLUP);

//Set jenis LCD yg digunakan
  lcd.begin(16, 2);

//inisialisasi BaudRate Serial Communication
  Serial.begin(9600);

//inisialisai interface I2c
  Wire.begin();

//Set Sensor BMP280
  bmp.begin();    

//Display the "entropy station" intro
  DisplayIntro();

//clear the LCD display
  lcd.clear();
}


void loop() {

 
if ( digitalRead(editButton) == HIGH) { //check Edit mode
    edit=!edit;
    editValue=0;  
    displayValue=0;
    delay(EditDelay);
   }



if(edit==false) //edit mode is off, display the values from sensors
{
  
//no Blinking when displaying the data
lcd.noCursor();


  if( digitalRead(nextButton) ==HIGH){
    displayValue++;
  }

  switch(displayValue){
    case 0:                   //Print data from all sensors
      lcd.clear();
      printAll();
    break;
    case 1:                   //print Time
      ReadDS3231(); //read data from DS3231 (time and date)
      lcd.clear();
      printTime();
    break;
    case 2:                   //print Date
      ReadDS3231(); //read data from DS3231 (time and date)
      lcd.clear();
      printDate();
    break;
    case 3:                 //Print Temperature from DHT11
      checkDHT11();
      lcd.clear();
      printTemperature();
    break;      
    case 4:                 //Print Humidity from DHT11
      checkDHT11();
      lcd.clear();    
      printHumidity();
    break;   
    case 5:                 //Print Barometric Pressure from BMP280
      getBMP280Values();
      lcd.clear();
      printBarometer();
    break;  
    default:
      lcd.clear();
      displayValue=0;
      printAll();
    break;
  }

  delay(DisplayDelay);  
  
}
else    //the edit mode is on, setting the date&time
{

//delay the medy 
delay(EditDelay);
lcd.clear();

  if( digitalRead(nextButton) ==HIGH){    //selecting which value to modify
    editValue++;
  }

  switch(editValue){
    case 0:                  // Edit HOUR
      lcd.noCursor();
      ReadDS3231(); //read data from DS3231 (time and date)
      printHourMinute();
      //lcd.setCursor(5, 0);
        if( digitalRead(increaseButton) ==HIGH){
          hour++;
          if(hour>23) hour=0;
          }
        if( digitalRead(descreaseButton) ==HIGH){
          hour--;
          if(hour<0) hour=23;
          }
       Clock.setHour(hour); 
       printHourMinute();
       lcd.setCursor(5, 0);
       lcd.cursor();
    break;
    case 1:                //Edit MINUTES
      lcd.noCursor();
      ReadDS3231(); //read data from DS3231 (time and date)
      printHourMinute();
      //lcd.setCursor(8, 0);
        if( digitalRead(increaseButton) ==HIGH){
          minute++;
          if(minute>59) minute=0;
          }
        if( digitalRead(descreaseButton) ==HIGH){
          minute--;
          if(minute<0) minute=59;
          }
       Clock.setMinute(minute); 
       printHourMinute();
       lcd.setCursor(8, 0);
       lcd.cursor();
    break;
    case 2:                            //Edit DAY
      lcd.noCursor();
      ReadDS3231(); //read data from DS3231 (time and date)
      printDate();
      //lcd.setCursor(9, 0);
      if( digitalRead(increaseButton) ==HIGH){
          date++;
          if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)  
          {
            if (date>31) date=1;
          }
          else if(month == 4 || month == 6 || month == 9 || month == 11 )  
          {
            if (date>30) date=1;
          }
          else if(month==2)
          {
            if(isLeapYear(year)==1)
            {
              if (date>29) date=1;
            }
            else if(isLeapYear(year)==0)
            {
              if (date>28) date=1;
            }
          }
          }
        if( digitalRead(descreaseButton) ==HIGH){
          date--;
          if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)  
          {
            if (date<1) date=31;
          }
          else if(month == 4 || month == 6 || month == 9 || month == 11 )  
          {
            if (date<1) date=30;
          }
          else if(month==2)
          {
            if(isLeapYear(year)==1)
            {
              if (date<1) date=29;
            }
            else if(isLeapYear(year)==0)
            {
              if (date<1) date=28;
            }
          }
          }
       Clock.setDate(date); 
       printDate();
       lcd.setCursor(5, 0);
       lcd.cursor();
    break;
    case 3:                      //Edit Month
      lcd.noCursor();
      ReadDS3231(); //read data from DS3231 (time and date)
      printDate();
      
        if( digitalRead(increaseButton) ==HIGH){
          month++;
            if (month>12) month=1;
          }
        if( digitalRead(descreaseButton) ==HIGH){
          month--;
            if (month<1) month=12;
          }
          
       Clock.setMonth(month); 
       printDate();
       lcd.setCursor(8, 0);
       lcd.cursor();
    break;      
    case 4:                     // Edit Year
      lcd.noCursor();
      ReadDS3231(); //read data from DS3231 (time and date)
      printDate();
      //lcd.setCursor(9, 0);
        if( digitalRead(increaseButton) ==HIGH){
          year++;
            if (year>99) year=1;
          }
        if( digitalRead(descreaseButton) ==HIGH){
          year--;
            if (year<1) year=99;
          }
          
       Clock.setYear(year); 
       printDate();
       lcd.setCursor(11, 0);
       lcd.cursor(); 
    break;   
    default:
      editValue=0;
      lcd.clear();
      lcd.setCursor(3,0);
      lcd.print("Time & Date");
    break;
  } 
}
  
}

//print barometer from BMP280
void printBarometer()
{
//get value from sensor
 
  lcd.setCursor(2, 0);
  lcd.print("Barometer:");
  
  lcd.setCursor(5, 1);
  Serial.println((int)BMP_pressure);
  lcd.print((int)BMP_pressure);
  lcd.print("hPa");  
}



//print date from DS3231
void printDate()
{
  
  //ReadDS3231(); //read data from DS3231 (time and date)

  //date
  lcd.setCursor(4, 0);
  if(date<10) lcd.print('0');
  lcd.print(date);
  lcd.print('-');  
  if(month<10) lcd.print('0');
  lcd.print(month);
  lcd.print('-');  
  if(year<10) lcd.print('0');
  lcd.print(year);

  lcd.setCursor(4, 1);
  
  lcd.print(getDayofweek(date, month, year+2000));
}




//print time from DS3231
void printTime()
{

  //ReadDS3231(); //read data from DS3231 (time and date)

  //TIME
  lcd.setCursor(4, 0);
  if(hour<10) lcd.print('0');
  lcd.print(hour);
  lcd.print(':');  
  if(minute<10) lcd.print('0');
  lcd.print(minute);
  lcd.print(':');  
  if(second<10) lcd.print('0');
  lcd.print(second);
}


void printHourMinute()
{

  //ReadDS3231(); //read data from DS3231 (time and date)

  //TIME
  lcd.setCursor(4, 0);
  if(hour<10) lcd.print('0');
  lcd.print(hour);
  lcd.print(':');  
  if(minute<10) lcd.print('0');
  lcd.print(minute);
  lcd.print(':');  
  if(second<10) lcd.print('0');
  lcd.print(second);

}

//print data from all sensors
void printAll(void)
{
  //read data from DHT11 (temperature and Humidity)
  if (checkDHT11()== 1) 
  {
    lcd.print("DHT11 error");
  }

// read data from DS3231 (time & date )
  ReadDS3231(); 

// read data from BMP280 (barometer)
  getBMP280Values();

  //TIME
  lcd.setCursor(1, 0);
  if(hour<10) lcd.print('0');
  lcd.print(hour);
  lcd.print(':');  
  if(minute<10) lcd.print('0');
  lcd.print(minute);

  //DATE
  lcd.setCursor(7, 0);
  if(date<10) lcd.print('0');  
  lcd.print(date);
  lcd.print('-');
  if(month<10) lcd.print('0');  
  lcd.print(month);
  lcd.print('-');
  if(year<10) lcd.print('0'); 
  lcd.print(year);    

  //Temperature
  lcd.setCursor(0, 1);
  lcd.print(DHT11.temperature);
 // lcd.print((char)178);
  lcd.print('C');   

  //Humidity
  lcd.setCursor(4, 1);
  //lcd.print(DHT11.humidity);
  lcd.print(DHT11.humidity);
  lcd.print('%');   
/*
  //Barometer
  lcd.setCursor(9, 1);
  lcd.print((int)BMP_pressure);
  lcd.print("hPa");  
*/
   //Altimeter
  lcd.setCursor(9, 1);
  lcd.print((int)getBMP280Values);
  Serial.print((int)getBMP280Values);
  lcd.print("MDPL");  
  
    
}


void DisplayIntro(void)
{
   startPoint = 0;   //set starting point
  endPoint = 12;    //set ending point
  lcd.clear();

  //for each letter of the string starting from the last one.
  for (i = txtMsg.length() - 1; i >= 0; i--)
  {
    startPoint = 0;


    //for each position on the LCD display
    for (j = 0; j < endPoint; j++)
    {

      lcd.setCursor(startPoint, 0);
      lcd.print(txtMsg[i]);

      delay(speed);

      if (startPoint != endPoint - 1) {
        lcd.setCursor(startPoint, 0);
        lcd.print(' ');
      }
      startPoint++;
    }
   
   startPoint = 0;
   for (j = 0; j < endPoint; j++)
    {

      lcd.setCursor(startPoint, 1);
      lcd.print(txtMsg1[i]);

      delay(speed);

      if (startPoint != endPoint - 1) {
        lcd.setCursor(startPoint, 1);
        lcd.print(' ');
      }
      startPoint++;
    }
    
    endPoint--;

    delay(speed);
  }

  // hold the string on the display for 2 sec.
  delay(2000);  
}


/*
 * read values from DS3231
 */
void ReadDS3231(void)
{
  second=Clock.getSecond();
  minute=Clock.getMinute();
  hour=Clock.getHour(h12, PM);
  date=Clock.getDate();
  month=Clock.getMonth(Century);
  year=Clock.getYear();
  DStemperature=Clock.getTemperature();
}




/*
 * read values from BMP280 sensor
 */
void getBMP280Values(void)
{
  //Read values from the sensor:
  BMP_pressure = bmp.readPressure()/100;
  BMP_temperature = bmp.readTemperature();
  BMP_altimeter = bmp.readAltitude (1003); //Change the "1050.35" to your city current barrometric pressure (https://www.wunderground.com)
  
}



/*
 * print Temperature on the LCD display from DHT11
 */
void printTemperature()
{

  lcd.setCursor(2, 0);
  lcd.print("Temperature:");
  
  lcd.setCursor(5, 1);
  lcd.print(DHT11.temperature);
  //lcd.print((char)178);
  lcd.print('C'); 

}



/*
 * print Humidity on the LCD display from  DHT11
 */
void printHumidity()
{

    lcd.setCursor(2, 0);
    lcd.print("Humidity:");
    
    
    lcd.setCursor(5, 1);
    lcd.print(DHT11.humidity);
    lcd.print('%'); 

}

//Reading the DHT11 sensor condition
int checkDHT11()
{
int chk = DHT11.read(DHT11PIN);

Serial.print("Reading DHT11 sensor: ");
  switch (chk)
  {
    case DHTLIB_OK: 
    Serial.println("DHT11:OK\n"); 
    return 0;
    break;
    
    case DHTLIB_ERROR_CHECKSUM: 
    Serial.println("DHT11:Checksum error\n");
    return 1;
    break;
    
    case DHTLIB_ERROR_TIMEOUT: 
    Serial.println("DHT11:Time out error\n");
    return 1;
    break;
    
    default: 
    Serial.println("DHT11:Unknown error\n");
    return 1;
    break;
  }

}



char *getDayofweek(int d, int m, int y)
{
    static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };
    int day;
    y -= m < 3;
    day = ( y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
     switch(day){
      case 0 :return("Minggu");
      case 1 :return("Senin");
      case 2 :return("Selasa");
      case 3 :return("Rabu");
      case 4 :return("Kamis");
      case 5 :return("Juma'at");
      case 6 :return("Sabtu");
      default:return("Error: Invalid Argument Passed");
   }
}


int isLeapYear(int y)
{

if ( y%400 == 0)
    return 1;
  else if ( y%100 == 0)
    return 0;
  else if ( year%4 == 0 )
    return 1;
  else
    return 0;  
 
  return 0;

}

Video Hasil


1 comment

Unknown said...

William Hill Betting Locations | Mapyro
Find wooricasinos.info William 출장샵 Hill sports betting locations in worrione Maryland, West Virginia, Indiana, Pennsylvania, 1등 사이트 South Dakota, West Virginia and more. BetRivers.com. https://tricktactoe.com/

Dicky B_Mz. Powered by Blogger.