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
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>
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 A0
OneWire oneWire (ONE_WIRE_BUS);
DallasTemperature sensors (&oneWire );
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
byte decToBcd(byte val)
{
return( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val)
{
return( (val/16*10) + (val%16) );
}
void setup()
{
lcd.begin();
sensors.begin();
Wire.begin();
Serial.begin(9600);
emon1.voltage(2, 230, 1.4);
emon1.current(1,56);
LightSensor.begin();
sensors.begin();
}
void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS);
Wire.write(0);
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(dayOfWeek));
Wire.write(decToBcd(dayOfMonth));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.endTransmission();
}
void readDS3231time(byte *second,byte *minute,byte *hour,byte *dayOfWeek, byte *dayOfMonth,byte *month,byte *year)
{
Wire.beginTransmission(DS3231_I2C_ADDRESS); Wire.write(0);
Wire.endTransmission();
Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
*second = bcdToDec(Wire.read() & 0x7f);
*minute = bcdToDec(Wire.read());
*hour = bcdToDec(Wire.read() & 0x3f);
*dayOfWeek = bcdToDec(Wire.read());
*dayOfMonth = bcdToDec(Wire.read());
*month = bcdToDec(Wire.read());
*year = bcdToDec(Wire.read());
}
void displayTime()
{
readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
&year);
lcd.setCursor(0,0);
lcd.print(hour, DEC);
lcd.print(":");
if (minute<10)
{
lcd.print("0");
}
lcd.print(minute, DEC);
lcd.print(":");
if (second<10)
{
lcd.print("0");
}
lcd.print(second, DEC);
lcd.setCursor(13,0);
lcd.print(dayOfMonth, DEC);
lcd.print("/");
lcd.print(month, DEC);
lcd.print("/");
if (year<10)
{
lcd.print("/");
lcd.print(year, DEC);
}
void loop(){
displayTime();
delay(1000);
lux = LightSensor.GetLightIntensity();
Irms = emon1.calcIrms(1480);
emon1.calcVI(20,2000);
Vrms = emon1.Vrms;
sensors.requestTemperatures();
if(Vrms < 0,5){
Vrms = 0;
}
if(Irms < 0.05){
Irms = 0;
}
lcd.setCursor(11,1);
lcd.print("Lux= ");
lcd.print(lux);
lcd.setCursor(10,2);
lcd.print ("Suhu= ");
lcd.println(sensors.getTempCByIndex(00));
lcd.setCursor(0,1);
lcd.print("V = ");
lcd.print(Vrms);
lcd.setCursor(0,2);
lcd.print("A = ");
lcd.print(Irms);
lcd.setCursor(0,3);
lcd.print("W = ");
lcd.print(Vrms*Irms);
cacah++;
if(cacah >= 60){
lcd.clear();
simpan();
cacah = 0;
lcd.clear();
}
}
void simpan(){
while (!Serial) { ;
}
Serial.print("Initializing SD card...");
lcd.print("Initializing SD card...");
pinMode(10, OUTPUT);
if (!SD.begin(53)) {
Serial.println("initialization failed!");
Serial.print("initialization failed!");
lcd.print("initialization failed!");
return;
}
Serial.println("initialization done.");
Serial.print("initialization done.");
lcd.print("initialization done.");
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile) {
myFile.print("Tanggal:");
myFile.print(dayOfMonth);
myFile.print("/");
myFile.print(month);
myFile.print("/");
myFile.println(year);
myFile.print("Jam:");
myFile.print(hour);
myFile.print(":");
myFile.print(minute);
myFile.print(":");
myFile.println(second);
myFile.print("V= ");
myFile.println(Vrms);
myFile.print("I= ");
myFile.println(Irms);
myFile.print("P= ");
myFile.println(Vrms*Irms);
myFile.print ("°C= ");
myFile.println(sensors.getTempCByIndex(00));
myFile.print("Lux= ");
myFile.println(lux);
myFile.close();
Serial.println("done.");
}
else {
Serial.println("error opening test.txt");
}
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
while (myFile.available()) {
Serial.write(myFile.read());
myFile.close();
} else {
Serial.println("error opening test.txt");
}
}
Foto Alat datalogger suhu,cahaya,tegangan dan arus 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 :