Membuat alat data logger suhu, cahaya, tegangan dan arus dengan Arduino dan SD Card

Pada tutorial kali ini saya akan share bagaimana membuat data logger dengan arduino. Alat data logger ini dapat mencatat hasil pengukuran suhu, cahaya, tegangan dan arus listrik dan di simpan di Micro SD Card. Sebelum membahas lebih dalam, ada baiknya kita harus mengetahui lebih dulu apa itu datalogger ..

Datalogger ( Perekam Data ) adalah sebuah alat elektronik yang mencatat data dari waktu ke waktu baik yang terintegrasi dengan sensor dan instrumen. Atau secara singkat data logger adalah alat untuk melakukan data logging.

BACA JUGA : TEORI DATA LOGGER

Cara membuat data logger dengan arduino

Sistem alat ukur Datalogger meliputi 4 parameter yakni, tegangan, arus, intensitas cahaya dan suhu

Komponen utama

  • Sensor tegangan ZMPT101B
  • Sensor Arus SCT-013-000
  • Sensor Cahaya BH1750
  • Sensor Suhu DS18B20
  • Liquid Crystal Display (LCD) 20 x 4 I2C
  • Modul (MicroSD Card Adapter)
  • Serial RTC (Real Time Clock) DS3231
  • Mikrokontroler Arduino Atmega 2560

Komponen pendukung

  • Sensor tegangan ZMPT101B
  • Resistor 33 Ohm,4,7K, 10K, 1K
  • Capasitor 1 uF
  • PCB
  • Power supply Output 12 Volt, 3 A
  • Kabel jumper
  • Stop Kontak

Skema layout PCB

membuat data logger dengan arduino

Sketch program alat data logger Arduino

#include <OneWire.h>
#include <DallasTemperature.h>
#include "Wire.h"
#include <BH1750FVI.h>
#define DS3231_I2C_ADDRESS 0x68
#include <SPI.h>
#include <SD.h>
#include "EmonLib.h"
#include <LiquidCrystal_I2C.h> &nbsp;
BH1750FVI::eDeviceAddress_t DEVICEADDRESS = BH1750FVI::k_DevAddress_H;
BH1750FVI LightSensor(BH1750FVI::k_DevModeContHighRes);
LiquidCrystal_I2C lcd(0x27, 20, 4);
EnergyMonitor emon1;
int cacah = 0;
int Jam;
int Tanggal;
File myFile;
float Vrms;
float Irms;
uint16_t lux;
#define ONE_WIRE_BUS &nbsp;A0
OneWire oneWire (ONE_WIRE_BUS);
DallasTemperature sensors (&oneWire );
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
byte decToBcd(byte val)
{
 &nbsp;return( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)
{
 &nbsp;return( (val/16*10) + (val%16) );
} &nbsp;
void setup()
{
 &nbsp;lcd.begin();
 &nbsp;sensors.begin();
 &nbsp;Wire.begin();
 &nbsp;Serial.begin(9600);
 &nbsp;emon1.voltage(2, 230, 1.4);
 &nbsp;&nbsp;emon1.current(1,56);
 &nbsp;&nbsp;LightSensor.begin();
 &nbsp;&nbsp;sensors.begin();
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
 &nbsp;Wire.beginTransmission(DS3231_I2C_ADDRESS);
 &nbsp;Wire.write(0);
 &nbsp;Wire.write(decToBcd(second));
 &nbsp;Wire.write(decToBcd(minute)); 
 &nbsp;Wire.write(decToBcd(hour)); 
 &nbsp;Wire.write(decToBcd(dayOfWeek));
 &nbsp;Wire.write(decToBcd(dayOfMonth)); 
 &nbsp;Wire.write(decToBcd(month)); 
 &nbsp;Wire.write(decToBcd(year)); 
 &nbsp;Wire.endTransmission();
}
void readDS3231time(byte *second,byte *minute,byte *hour,byte *dayOfWeek, byte *dayOfMonth,byte *month,byte *year)
{
 &nbsp;Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0);
 &nbsp;Wire.endTransmission();
 &nbsp;Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
 &nbsp;*second = bcdToDec(Wire.read() & 0x7f);
 &nbsp;*minute = bcdToDec(Wire.read());
 &nbsp;*hour = bcdToDec(Wire.read() & 0x3f);
 &nbsp;*dayOfWeek = bcdToDec(Wire.read());
 &nbsp;*dayOfMonth = bcdToDec(Wire.read());
 &nbsp;*month = bcdToDec(Wire.read());
 &nbsp;*year = bcdToDec(Wire.read());
}
void displayTime()
{
 &nbsp;readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
 &nbsp;&year);
 &nbsp;lcd.setCursor(0,0);
 &nbsp;lcd.print(hour, DEC);
 &nbsp;lcd.print(":");
 &nbsp;if (minute<10)
 &nbsp;{
 &nbsp;&nbsp;&nbsp;lcd.print("0");
 &nbsp;}
 &nbsp;lcd.print(minute, DEC);
 &nbsp;lcd.print(":");
 &nbsp;if (second<10)
 &nbsp;{
 &nbsp;&nbsp;&nbsp;lcd.print("0");
 &nbsp;}
 &nbsp;lcd.print(second, DEC);
 &nbsp;lcd.setCursor(13,0);
 &nbsp;lcd.print(dayOfMonth, DEC);
 &nbsp;lcd.print("/");
 &nbsp;lcd.print(month, DEC);
 &nbsp;lcd.print("/");
 &nbsp;if (year<10)
 &nbsp;{
 &nbsp;&nbsp;&nbsp;lcd.print("/");
 &nbsp;
 &nbsp;lcd.print(year, DEC);
}
void loop(){
 &nbsp;displayTime(); 
 &nbsp;delay(1000); 
 &nbsp;lux = LightSensor.GetLightIntensity();
 &nbsp;Irms = emon1.calcIrms(1480);
 &nbsp;emon1.calcVI(20,2000);
 &nbsp;Vrms = emon1.Vrms;
 &nbsp;sensors.requestTemperatures();
if(Vrms < 0,5){
 &nbsp;Vrms = 0;
 &nbsp;}
if(Irms < 0.05){
 &nbsp;Irms = 0;
 &nbsp;}
 &nbsp;lcd.setCursor(11,1);
 &nbsp;lcd.print("Lux= ");
 &nbsp;lcd.print(lux);
 &nbsp;lcd.setCursor(10,2);
 &nbsp;lcd.print ("Suhu= ");
 &nbsp;lcd.println(sensors.getTempCByIndex(00));
 &nbsp;lcd.setCursor(0,1);
 &nbsp;lcd.print("V = ");
 &nbsp;lcd.print(Vrms);
 &nbsp;lcd.setCursor(0,2);
 &nbsp;lcd.print("A = ");
 &nbsp;lcd.print(Irms);
 &nbsp;lcd.setCursor(0,3);
 &nbsp;lcd.print("W = ");
 &nbsp;lcd.print(Vrms*Irms);
 &nbsp;
 &nbsp;cacah++;
 &nbsp;if(cacah >= 60){
 &nbsp;lcd.clear();
 &nbsp;simpan();
 &nbsp;cacah = 0;
 &nbsp;lcd.clear();
 &nbsp;} 
}
void simpan(){
while (!Serial) { &nbsp;&nbsp;; 
 &nbsp;}
 &nbsp;Serial.print("Initializing SD card...");
 &nbsp;lcd.print("Initializing SD card...");
 &nbsp;pinMode(10, OUTPUT);
 &nbsp;if (!SD.begin(53)) {
 &nbsp;&nbsp;&nbsp;Serial.println("initialization failed!");
 &nbsp;&nbsp;Serial.print("initialization failed!");
 &nbsp;&nbsp;lcd.print("initialization failed!");
 &nbsp;&nbsp;&nbsp;return;
 &nbsp;}
 &nbsp;Serial.println("initialization done.");
 &nbsp;Serial.print("initialization done.");
 &nbsp;lcd.print("initialization done.");
 &nbsp;myFile = SD.open("test.txt", FILE_WRITE);
 &nbsp;if (myFile) {
 &nbsp;&nbsp;&nbsp;myFile.print("Tanggal:");
 &nbsp;&nbsp;&nbsp;myFile.print(dayOfMonth);
 &nbsp;&nbsp;&nbsp;myFile.print("/");
 &nbsp;&nbsp;&nbsp;myFile.print(month);
 &nbsp;&nbsp;&nbsp;myFile.print("/");
 &nbsp;&nbsp;&nbsp;myFile.println(year);
 &nbsp;&nbsp;&nbsp;myFile.print("Jam:");
 &nbsp;&nbsp;&nbsp;myFile.print(hour);
 &nbsp;&nbsp;&nbsp;myFile.print(":");
 &nbsp;&nbsp;&nbsp;myFile.print(minute);
 &nbsp;&nbsp;&nbsp;myFile.print(":"); &nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp;myFile.println(second);
 &nbsp;&nbsp;&nbsp;myFile.print("V= ");
 &nbsp;&nbsp;&nbsp;myFile.println(Vrms);
 &nbsp;&nbsp;&nbsp;myFile.print("I= ");
 &nbsp;&nbsp;&nbsp;myFile.println(Irms);
 &nbsp;&nbsp;&nbsp;myFile.print("P= ");
 &nbsp;&nbsp;&nbsp;myFile.println(Vrms*Irms);
 &nbsp;&nbsp;&nbsp;myFile.print ("°C= ");
 &nbsp;&nbsp;&nbsp;myFile.println(sensors.getTempCByIndex(00));
 &nbsp;&nbsp;&nbsp;myFile.print("Lux= ");
 &nbsp;&nbsp;&nbsp;myFile.println(lux);
 &nbsp;&nbsp;&nbsp;myFile.close();
 &nbsp;&nbsp;&nbsp;Serial.println("done.");
 &nbsp;}
 &nbsp;else {
 &nbsp;&nbsp;&nbsp;Serial.println("error opening test.txt");
 &nbsp;}
 &nbsp;myFile = SD.open("test.txt");
 &nbsp;if (myFile) {
 &nbsp;&nbsp;&nbsp;Serial.println("test.txt:");
 &nbsp;&nbsp;&nbsp;while (myFile.available()) {
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Serial.write(myFile.read());
 &nbsp;&nbsp;&nbsp;
 &nbsp;&nbsp;&nbsp;myFile.close();
 &nbsp;} else {
 &nbsp;&nbsp;&nbsp;Serial.println("error opening test.txt");
 &nbsp;}
}

Foto Alat datalogger suhu,cahaya,tegangan dan arus Arduino

membuat data logger dengan arduino

Untuk memeriksa informasi yang sudah direkam, silahkan keluarkan kartu SD dari modul dan buka file datalogger.txt di komputer atau HP kalian

Agar lebih jelas, silahkan tonton video nya berikut ini :

Tinggalkan Balasan

Scroll to Top