#include <ATtinySerialOut.h>;
// Pin Definitions
const int voltagePin = PB3; // Analog pin for battery voltage
const int ledPin = PB0; // Digital pin for LED
// Voltage Divider Resistor Values
const float R1 = 10000.0; // Resistor R1 in the voltage divider (10kΩ)
const float R2 = 5000.0; // Resistor R2 in the voltage divider (1kΩ)
// ADC Reference Voltage
const float ADC_REF_VOLTAGE = 5.0; // Assuming 5V reference for Arduino Uno
const int ADC_RESOLUTION = 1023; // 10-bit resolution
void setup() {
// Initialize pins
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
delay(6000);
// Initialize Serial Monitor for debugging
//Serial.begin(9600);
// Read battery voltage
float batteryVoltage = readBatteryVoltage();
// Print battery voltage to Serial Monitor
//Serial.print("Battery Voltage: ");
//Serial.println(batteryVoltage, 2);
// Wait 5 seconds
delay(5000);
// Check if the battery voltage is above 13.5V
if (batteryVoltage > 13.5) {
// Serial.println("Battery voltage sufficient. Turning on LED.");
digitalWrite(ledPin, HIGH);
delay(1000); // Keep the LED on for 1 second
digitalWrite(ledPin, LOW);
} else {
// Serial.println("Battery voltage too low. LED will not turn on.");
}
}
void loop() {
// No operation in loop
}
// Function to Read Battery Voltage
float readBatteryVoltage() {
int rawADC = analogRead(voltagePin);
float voltageDividerOutput = (rawADC / float(ADC_RESOLUTION)) * ADC_REF_VOLTAGE;
float batteryVoltage = voltageDividerOutput * ((R1 + R2) / R2);
return batteryVoltage;
}