Untitled

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 5

/*

Mini Project by
Maaz Khan
M.Aneeb Khan
M.Muez khan
*/
//#include <SD.h>
//#include <SoftwareSerial.h>
#include <LiquidCrystal.h> // library for LCD
//SoftwareSerial gpsSerial(1, 0); // RX, TX
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers
of the interface pins

const int chipSelect = 4;


const int currentPin = A0; //connect current sensor with A0 of arduino Uno
int sensitivity = 185; // It varies (185mA/V for 5A,100mA/V for 20A,66mA/V for 30A)

int adcValue= 0; // ADC initial value is 0


int offsetVoltage = 2500;
double adcVoltage = 0; // This statement is for Voltage measuring
double currentValue = 0; // This statement is for current measuring
int voltageSensor_AC = A2;
int currentSensor_AC = A3;

double voltage_AC;
double current_AC;
double power_AC;

void setup()
{
//SD.begin(chipSelect);
//gpsSerial.begin(9600);
Serial.begin(9600);// Represent the baud ratewq
lcd.begin(16, 2); // 16 column and 2 rows of lcd
lcd.print(" Mini Project "); // print statement on display on first column and
first row
lcd.setCursor(0,1);
lcd.print(" with Arduino "); // print statement on display on first column and
second row
delay(1500); // delay of 1.5 sec
lcd.clear(); // This will clear the lcd screen

lcd.print(" Current Sensor "); // Same as above


lcd.setCursor(0,1);
lcd.print(" with Arduino ");
delay(1500);
}

void loop()
{
/*
////////////////////////////////////////////////////////////////////////////////
////////////////////// GPS_SENSOR /////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
if (gpsSerial.available()) {
char c = gpsSerial.read();
if (c == '$') {
String sentence = gpsSerial.readStringUntil('\n');
if (sentence.startsWith("$GPGGA")) {
String fields[15];
int fieldCount = 0;
int i = 0;
while (sentence.length() > 0) {
int index = sentence.indexOf(',');
if (index == -1) {
fields[fieldCount++] = sentence;
sentence = "";
} else {
fields[fieldCount++] = sentence.substring(0, index);
sentence = sentence.substring(index + 1);
}
}
float latitude = fields[2].toFloat() / 100;
float longitude = fields[4].toFloat() / 100;
float altitude = fields[9].toFloat();
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Lat: ");
lcd.print(latitude, 6);
lcd.setCursor(0, 1);
lcd.print("Lon: ");
lcd.print(longitude, 6);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Alt: ");
lcd.print(altitude);
delay(2000);
}
}
}
*/
////////////////////////////////////////////////////////////////////
/////////// DC_SENSOR /////////////////////
//////////////////////////////////////////////////////////////////
adcValue = analogRead(currentPin); // This is for reading the value from analog
pin A0
adcVoltage = (adcValue / 1024.0) * 5000; // Calculating a voltage in mV
currentValue = ((adcVoltage - offsetVoltage) / sensitivity); // Calculating a
current

Serial.print("Raw Sensor Value = " );// As it's a 10-bit ADC board so it's range
will be from 0-1024
Serial.print(adcValue); // print the adc value on lcd

lcd.clear();
delay(1000);
//lcd.display();
lcd.setCursor(0,0);
lcd.print("ADC Value = ");
lcd.setCursor(12,0);
lcd.print(adcValue);

delay(2000);

Serial.print("\t Voltage(mV) = "); // It shows the voltage measured


Serial.print(adcVoltage,3); // the '3' after voltage allows us to display 3
digits after decimal point

lcd.setCursor(0,0);
lcd.print("V in mV = ");
lcd.setCursor(10,0);
lcd.print(adcVoltage,1);

delay(2000);

Serial.print("\t Current = "); // It shows the current measured


Serial.println(currentValue,3); // the '3' after voltage allows you to display 3
digits after decimal point

lcd.setCursor(0,0);
lcd.print("Current = ");
lcd.setCursor(10,0);
lcd.print(currentValue,2);
lcd.setCursor(14,0);
lcd.print("A");
delay(2500); // delay of 2.5sec

int offset = 100;


int Volt = analogRead(A1); // This is for reading the
value from analog pin A1
double Vo = map(Volt,0,1024, 0, 2500) - offset; //
map(value,fromlow,fromhigh,tolow,tohigh)
Vo /=100;
Serial.print("\t Voltage = ");
Serial.print(Vo); // print measure voltage on serial monitor
Serial.print("V");

lcd.clear();
delay(1000);
lcd.setCursor(0,0);
lcd.print(" Voltage = ");
lcd.setCursor(10,0);
lcd.print(Vo,2); // Display the measure voltage with 2 digits after the decimal
point and mask the remaining
lcd.setCursor(14,0);
lcd.print("V");
delay(2000); // delay of 2 sec

double power = (Vo * currentValue); // To calculate power of the load when


connected

Serial.print("\t Power = ");


Serial.print(power); // This line shows to print measure power on erial monitor
Serial.print("W \t ");

lcd.setCursor(0,1); // Move the cursor to first position in second row


lcd.print("Power = ");
lcd.setCursor(8,1); // Move the cursor to 8th position in second row
lcd.print(power);
lcd.setCursor(12,1); // Move the cursor to 12th position in Secon row
lcd.print("W");
delay(2000); // delay of 2sec
///////////////////////////////////////////////////////////////////////////////////
///////////////////////
////////////////////
AC_SENSOR ///////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
//////////////////////
int sensorValue = analogRead(voltageSensor_AC); // read voltage sensor
voltage_AC = sensorValue * 5.0 / 1023.0; // convert to voltage (5V reference)

Serial.print("\t Voltage_AC = ");


Serial.print(voltage_AC); // This line shows to print measure Ac_Voltage on
Serial monitor
Serial.print("V \t ");

lcd.clear();
delay(1000);
lcd.setCursor(0,0);
lcd.print("Voltage_AC = ");
lcd.setCursor(13, 0); // go to voltage position
lcd.print(voltage_AC); // display voltage
delay(2000); // delay of 2 sec
//Measure Ac Current

sensorValue = analogRead(currentSensor_AC); // read current sensor


current_AC = (sensorValue - 512.0) * 5.0 / 1023.0 / 0.066; // convert to current
(66mV/A sensitivity)

Serial.print("\t Current_AC = ");


Serial.print(current_AC); // This line shows to print measure Ac_Voltage on
Serial monitor
Serial.print("A \t ");

lcd.setCursor(0,1);
lcd.print("Curr_AC = ");
lcd.setCursor(10, 1); // go to voltage position
lcd.print(current_AC,2); // display voltage
delay(2000); // delay of 2 sec

lcd.clear();
delay(1000);
power_AC = voltage_AC * current_AC; // calculate power
lcd.setCursor(0, 0); // go to beginning
lcd.print("Power: "); // clear previous power reading
lcd.setCursor(7, 0); // go to power position
lcd.print(power_AC); // display power

delay(2000); // update every second


///////////////////////////////////////////////////////////////////////////////////
/////////////// SD_CARD_MODULE ////////////////////
//////////////////////////////////////////////////////////////////////////////////
/* lcd.clear();
delay(1000);
lcd.setCursor(0,0);
lcd.print("SD_Card Module");

// Check if the SD card is present


if (!SD.begin(chipSelect)) {
lcd.clear();
lcd.print("SD Error!");
while (1);
}

// Open the file on the SD card


File file = SD.open("test.txt");

// Check if the file opened successfully


if (!file) {
lcd.clear();
lcd.print("File Error!");
while (1);
}

// Read the contents of the file


String contents = file.readString();

// Print the contents to the LCD


lcd.clear();
// lcd.print(contents);

// Close the file


file.close();

// Wait for 5 seconds before reading the file again


delay(2000);*/
}

You might also like