0% found this document useful (0 votes)
14 views3 pages

Coding Arduino

1. The document describes code for an Arduino project that measures current, voltage, and power from solar panels using sensors and displays the results on an LCD screen and in a text file on an SD card. 2. It initializes libraries and components like the Real Time Clock, LCD screen, and SD card. Functions are defined to read the analog sensors for current and voltage and calculate power. 3. The main loop calls the functions to get readings, prints the results to the serial monitor and saves to the SD card. It also displays the date/time from the RTC and delays between loops.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Coding Arduino

1. The document describes code for an Arduino project that measures current, voltage, and power from solar panels using sensors and displays the results on an LCD screen and in a text file on an SD card. 2. It initializes libraries and components like the Real Time Clock, LCD screen, and SD card. Functions are defined to read the analog sensors for current and voltage and calculate power. 3. The main loop calls the functions to get readings, prints the results to the serial monitor and saves to the SD card. It also displays the date/time from the RTC and delays between loops.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

1.

Coding Arduino
#include <RTClib.h>
//DS3231 rtc;

RTC_DS3231 rtc;
#include <SPI.h> #include <SD.h> #include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); File myFile;


int analogPin = A0; const int pinADC1 = A1; const int pinADC2 = A2; float Vmodul =
0.0; float hasil = 0.0;
float R1 = 30000.0; float R2 = 7500.0; int value = 0;
int sensitivitas1 = 100; int sensitivitas2 = 100; int nilaiadc1= 00;
int nilaiadc2= 00;
int teganganoffset1 = 2500; int teganganoffset2 = 2500; double tegangan1 = 00;
double tegangan2 = 00; double nilaiarus1 = 00; double nilaiarus2 = 00;
int i;

int nilaidaya1; int nilaidaya2;

char daysOfTheWeek[7][12] = {"Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jumat",


"Sabtu"};

void setup()
{
pinMode(analogPin, INPUT); Serial.begin(9600);
// rtc.setDate(18, 7, 2021);
// rtc.setTime(13, 12, 00);
// rtc.setDOW(4);
Serial.println("Energy Meter Panel Surya"); Serial.println(" ");

// while(!Serial)
//{
// ;
// }
Serial.println("Initializing SD card"); if (!SD.begin(4))
{
Serial.println(" SD card Gagal! ");
//while(1);
}
Serial.println("SD card Berhasil ");

myFile = SD.open("data2.txt", FILE_WRITE);

// put your setup code here, to runonce:

if (! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1);


}

if (rtc.lostPower()) {
Serial.println("RTC lost power, lets set the time!"); rtc.adjust(DateTime(F( DATE
), F( TIME ))); // following line
sets the RTC to the date & time this sketch was compiled
// Set the current date, and time in the following format:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0)); // This line sets the RTC with an
explicit date & time, for example to set
}

lcd.init();
}

void arus1()
{
nilaiadc1=analogRead(pinADC1); tegangan1=(nilaiadc1/1024.0)*5000;
nilaiarus1=((tegangan1-teganganoffset1)/sensitivitas1);
nilaiarus1=nilaiarus1+5.027;
}
void arus2()
{
nilaiadc2=analogRead(pinADC2); tegangan2=(nilaiadc2/1024.0)*5000;
nilaiarus2=((tegangan2-teganganoffset2)/sensitivitas2); nilaiarus2=nilaiarus2+5.1;
}

void teg()
{
value=analogRead(analogPin); Vmodul=(value*5.0)/1024.0; hasil=Vmodul/(R2/(R1+R2));
hasil=hasil-0.55;
}

void daya1()
{
nilaidaya1=hasil*nilaiarus1;
}

void daya2()
{
nilaidaya2=hasil*nilaiarus2;
}

void loop()
{
arus1(); Serial.print("Arus 1 = "); Serial.print(nilaiarus1,3); Serial.println("
A");
myFile.print("Nilai Arus 1 : "); myFile.println(nilaiarus1,3);
//lcd.setCursor(0,0);
//lcd.print("Nilai Arus : "); lcd.setCursor(0,0); lcd.print(nilaiarus1);

arus2(); Serial.print("Arus 2 = "); Serial.print(nilaiarus2,3); Serial.println("


A");
myFile.print("Nilai Arus 2 : "); myFile.println(nilaiarus2,3);

teg(); Serial.print("Tegangan = "); Serial.print(hasil,2); Serial.println(" volt");


myFile.print("Nilai Tegangan : "); myFile.println(hasil,3);

daya1(); Serial.print("daya 1 = "); Serial.print(nilaidaya1,2); Serial.println("


Watt");
myFile.print("Nilai daya 1 : "); myFile.print(nilaidaya1,3);
myFile.println("watt"); lcd.setCursor(0,1); lcd.print(nilaidaya1);

daya2(); Serial.print("daya 2 = "); Serial.print(nilaidaya2,2); Serial.println("


Watt");
myFile.print("Nilai daya 2 : "); myFile.print(nilaidaya2,3);
myFile.println("watt");
//lcd.setCursor(0,1);

//lcd.print(nilaidaya2);

//lcd.clear(); Serial.print("Waktu = "); DateTime now = rtc.now();


Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); Serial.print(',');

// Serial.print(" ");
Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/');
Serial.print(now.year(), DEC); Serial.print('\t');

Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC);


Serial.print(':'); Serial.print(now.second(), DEC); Serial.println();

Serial.println();

//Serial.print(rtc.getDOWStr());
//Serial.print(" ");
//Serial.print(rtc.getDateStr());
//Serial.print(" ");
//Serial.println(rtc.getTimeStr());

//Serial.println(" ");
//Serial.println(" ");
//myFile.print("Waktu = ");
//myFile.print(rtc.getDOWStr());
/*myFile.print(" "); myFile.print(rtc.getDateStr()); myFile.print(" ");
myFile.println(rtc.getTimeStr()); myFile.println(" "); myFile.println(" ");*/
delay(2000);

// put your main code here, to run repeatedly:

You might also like