Translate

ARDUINO Dotmatrix Max7219 Monitor Suhu dan Kelembaban (Temperature dan Humidity) Sensor DHT11)

ARDUINO Dotmatrix Max7219 Monitor Suhu dan Kelembaban (Temperature dan Humidity) Sensor DHT11


       Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat monitor suhu dan kelembaban dengan penampil dotmatrix max7219. sensor yang digunakan yaitu DHT11. alat ini menggunakan arduino sebagai mikrokontrollernya. yang perlu diperhatikan disini yaitu posisi dari penempatan karakter angka pada dotmatrik yang bisa disimak diprogram. berikut adalah daftar komponen dan programnya.



a. Arduino Uno




b. Modul Dotmatrix Max7219




c. Sensor Suhu dan Kelembaban DHT11







d. Program Arduino IDE

#include "LedControl.h"
#include <FontLEDClock.h>                // Font library
#include <Wire.h>  
#include <LedControl.h>   
#include "DHT.h"

#define DHTPIN 2     // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);

const int numDevices = 4;      // number of MAX7219s used in this case 2
const long scrollDelay = 40;   // adjust scrolling speed
unsigned long bufferLong [14] = {0};  
LedControl lc=LedControl(12,11,10,4);//DATA | CLK | CS/LOAD | number of matrices
const unsigned char scrollText[] PROGMEM ={"   YANUAR MUKHAMMAD           "};

// pin 12 is connected to the DataIn on the display
// pin 11 is connected to the CLK on the display
// pin 10 is connected to LOAD on the display

//global variables
byte intensity = 5;                      // Default intensity/brightness (0-15)
byte clock_mode = 0;                     // Default clock mode. Default = 0 (basic_mode)
bool random_mode = 0;                    // Define random mode - changes the display type every few hours. Default = 0 (off)
byte old_mode = clock_mode;              // Stores the previous clock mode, so if we go to date or whatever, we know what mode to go back to after.
bool ampm = 1;                           // Define 12 or 24 hour time. 0 = 24 hour. 1 = 12 hour
byte change_mode_time = 0;               // Holds hour when clock mode will next change if in random mode.
unsigned long delaytime = 500;           // We always wait a bit between updates of the display
int rtc[7];                              // Holds real time clock output

int cacah;

//define constants
#define NUM_DISPLAY_MODES 3              // Number display modes (conting zero as the first mode)
#define NUM_SETTINGS_MODES 4             // Number settings modes = 6 (conting zero as the first mode)
#define SLIDE_DELAY 20                   // The time in milliseconds for the slide effect per character in slide mode. Make this higher for a slower effect
#define cls          clear_display       // Clear display


void setup() {
 dht.begin();
 Serial.begin(9600); //start serial

for (int x=0; x<numDevices; x++)
  {
    lc.shutdown(x,false);       //The MAX72XX is in power-saving mode on startup
    lc.setIntensity(x,8);       // Set the brightness to default value
    lc.clearDisplay(x);         // and clear the display
  }
  
  //initialize the 4 matrix panels
  //we have already set the number of devices when we created the LedControl
  int devices = lc.getDeviceCount();
  //we have to init all devices in a loop
  for (int address = 0; address < devices; address++) {
    /*The MAX72XX is in power-saving mode on startup*/
    lc.shutdown(address, false);
    /* Set the brightness to a medium values */
    lc.setIntensity(address, intensity);
    /* and clear the display */
    lc.clearDisplay(address);
  }


  //Show software version & hello message
  //printver();
  //set_time();

    //test all leds.
  for (byte x = 0; x <= 31; x++) {
    for (byte y = 0; y <= 7; y++) {
      plot(x, y, 1);
    }
  }
  delay(500);
  fade_down();
  
}

void loop() {
  byte i = 0;
  String stra;
  String strb;
  char ver_b[9];
  char ver_c[9];
  
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 float f = dht.readTemperature(true);

 int hum = h;
 int suhu = t;

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);
  
  stra = String(suhu);
  strb = String(hum);
  
  char ver_a[9] = "TH:";
  stra.toCharArray(ver_b,9);;
  strb.toCharArray(ver_c,9);;
  
  while (ver_a[i]) {
    puttinychar((i * 4), 1, ver_a[i]);
    delay(35);
    i++;
  }
  delay(700);
 // fade_down();
  i = 0;
  
  
  while (ver_b[i]) {
    puttinychar((i * 4)+12, 1, ver_b[i]);
    delay(35);
    i++;
  }
  delay(700);
  //fade_down();
   i = 0;
   
  while (ver_c[i]) {
    puttinychar((i * 4)+22, 1, ver_c[i]);
    delay(35);
    i++;
  }
  delay(700);
  //fade_down();
 i = 0;
  
}

// puttinychar
// Copy a 3x5 character glyph from the myfont data structure to display memory, with its upper left at the given coordinate
// This is unoptimized and simply uses plot() to draw each dot.
void puttinychar(byte x, byte y, char c)
{
  byte dots;
  if (c >= 'A' && c <= 'Z' || (c >= 'a' && c <= 'z') ) {
    c &= 0x1F;   // A-Z maps to 1-26
  }
  else if (c >= '0' && c <= '9') {
    c = (c - '0') + 32;
  }
  else if (c == ' ') {
    c = 0; // space
  }
  else if (c == '.') {
    c = 27; // full stop
  }
  else if (c == ':') {
    c = 28; // colon
  }
  else if (c == '\'') {
    c = 29; // single quote mark
  }
  else if (c == '!') {
    c = 30; // single quote mark
  }
  else if (c == '?') {
    c = 31; // single quote mark
  }

  for (byte col = 0; col < 3; col++) {
    dots = pgm_read_byte_near(&mytinyfont[c][col]);
    for (char row = 0; row < 5; row++) {
      if (dots & (16 >> row))
        plot(x + col, y + row, 1);
      else
        plot(x + col, y + row, 0);
    }
  }
}


//plot a point on the display
void plot (byte x, byte y, byte val) {

  //select which matrix depending on the x coord
  byte address;
  if (x >= 0 && x <= 7)   {
    address = 3;
  }
  if (x >= 8 && x <= 15)  {
    address = 2;
    x = x - 8;
  }
  if (x >= 16 && x <= 23) {
    address = 1;
    x = x - 16;
  }
  if (x >= 24 && x <= 31) {
    address = 0;
    x = x - 24;
  }

  if (val == 1) {
    lc.setLed(address, y, x, true);
  } else {
    lc.setLed(address, y, x, false);
  }
}


//clear screen
void clear_display() {
  for (byte address = 0; address < 4; address++) {
    lc.clearDisplay(address);
  }
}


void fade_down() {

  //fade from global intensity to 1
  for (byte i = intensity; i > 0; i--) {
    for (byte address = 0; address < 4; address++) {
      lc.setIntensity(address, i);
    }
    delay(30); //change this to change fade down speed
  }

  clear_display(); //clear display completely (off)

  //reset intentsity to global val
  for (byte address = 0; address < 4; address++) {
    lc.setIntensity(address, intensity);
  }
}





e. Video Hasilnya









No comments:

Post a Comment