40
LAMPIRAN 1
Kode Program Lengkap
#include <OneWire.h>
#include <DallasTemperature.h> #include "EmonLib.h"
// Data wire is plugged into pin 2 on the Arduino #define ONE_WIRE_BUS 12
const int analogVoltPin = A2; const int analogCurrentPin = A1; float amp=0;
float volt=0, voltage; EnergyMonitor emon1;
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire);
void setup() {
// initialize serial communication at 9600 bits per second Serial.begin(9600);
Serial.println("CLEARDATA"); //clears up any data left from previous projects Serial.println("LABEL,Time,Detik ke-,Data"); //always write LABEL, so excel knows
the next things will be the names of the columns (instead of Acolumn you could write Time for instance)
Serial.println("RESETTIMER"); //resets timer to 0 emon1.current(analogCurrentPin, 111.1);
sensors.begin(); delay(1000); }
41 void loop() {
//tegangan
voltage = analogRead(analogVoltPin); volt =(voltage*25/1023);
amp = ((analogRead(analogCurrentPin)*0.0048876)-2.5)/0.066 ;
Serial.print("DATA,TIME,TIMER,");//writes the time in the first column A and the time since the measurements started in column B
sensors.requestTemperatures(); // Send the command to get temperatures Serial.print(sensors.getTempCByIndex(0));
Serial.print(" C; "); Serial.print(volt); Serial.print(" Volt; "); Serial.print(amp); Serial.print(" Ampere"); Serial.println("");
delay(1000); // need for a minute to read the next data }