#include <Adafruit_GFX.h> // Adding display libraries
#include <Adafruit_SSD1306.h>
/**
* Made with Marlin Bitmap Converter
* https://marlinfw.org/tools/u8glib/converter.html
*
* This bitmap from the file 'picture (1).webp'
*/
#pragma once
#define UE3F2R_BMPWIDTH 128
const unsigned char bitmap_ue3f2r[] PROGMEM = {
// Your bitmap data here
};
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int frequencyPin = 2; // Digital pin for simulating frequency
const int currentSensor = A0;
const int voltageSensor = A1;
float vOUT = 0.0;
float vIN = 0.0;
float R1 = 10000.0;
float R2 = 1980.0;
float Vdata = 0;
float V, I, I1;
float Cdata;
float value;
float frequencyMultiplier = 1.0; // To convert frequency to kHz
void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.display();
// Set the display to show the bitmap image
display.drawBitmap(0, 0, bitmap_ue3f2r, UE3F2R_BMPWIDTH, SCREEN_HEIGHT, SSD1306_WHITE);
display.display();
delay(2000);
// Clear the display for the next screen
display.clearDisplay();
// Display your name
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(20, 10);
display.println("ANOSH PATHARE");
display.setCursor(20, 30);
display.println("KAILAS SHINDE");
display.setCursor(20, 50);
display.println("SHUBHAM ADAKE");
display.display();
delay(4000);
display.clearDisplay();
}
void loop() {
//float vIN = 0.0;
int simulatedFrequency = digitalRead(frequencyPin); // Simulated frequency input (HIGH or LOW)
int frequency = simulatedFrequency == HIGH ? 60 : 0; // Convert HIGH to 60Hz, LOW to 0Hz
frequency *= frequencyMultiplier; // Convert frequency to kHz if greater than 1000 Hz
for (int i = 0; i < 300; i++) // read 300 times to get a more stable average result
{
Cdata = Cdata + analogRead(currentSensor);
Vdata = Vdata + analogRead(voltageSensor);
delay(1);
}
Cdata = Cdata / 300;
V = (Cdata / 1024.0) * 5000;
I = ((V - 2500) / 96);
Vdata = Vdata / 300;
vOUT = (Vdata * 5.0) / 1024.0;
vIN = (vOUT / (R2 / (R1 + R2)));
// Writing to OLED Screen
display.setTextColor(WHITE);
/// Calculate watts and print to screen
display.setTextSize(1);
display.setCursor(87, 0);
//display.print("W");
display.setCursor(0, 0);
//display.setTextSize(float(2.5));
display.print("Power: ");
value = I * vIN;
/* int iCnt = 2222;
value = iCnt;*/
if (value < 1000) {
display.print(value, 2); // Display value with two decimal places
display.print(" W");
} else {
value /= 1000; // Convert to kW
display.print(value, 2); // Display value with two decimal places
display.print(" kW");
}
// Print the amperage value to the screen
display.setTextSize(1);
display.setCursor(87, 18);
display.print("mA");
display.setCursor(0, 18);
//display.setTextSize(1);
display.print("Curr: ");
if (I < 0.1) {
display.println("0.0");
} else {
display.print(I, 2); // Display value with two decimal places
}
// print the voltage value to the screen
display.setTextSize(1);
display.setCursor(87, 36);
display.print("V");
display.setCursor(0, 36);
//display.setTextSize(1);
display.print("Volt: ");
display.println(vIN);
display.setTextSize(1);
display.setCursor(82, 54);
if (frequency >= 1000) {
display.print(" kHz");
frequency /= 1000;
} else {
display.print(" Hz");
}
display.setCursor(0, 54);
display.setTextSize(1);
display.print("Freq: ");
display.print(frequency);
display.display();
display.clearDisplay();
// reset values
Cdata = 0;
I = 0;
V = 0;
Vdata = 0;
vIN = 0;
value;
}