I'm so glad you have patience.... I didn't notice the resistor sizes and they make perfect sense setting the VREF to the same as what VCC will be at 11v. I moved the cap to the neg side, Was that the problem? I'll add the hysteresis too...No!Check pin8 and C2 on the LM393.
I gave the correct values for R11 and R12.

Thank you sir!!AO3401 works as well.


//8 mghz
// ***MAIN LED AT 91.7% BRIGHTNESS WITH LOW BATT ALERT***
// THIS SKETCH IS THE LATEST FOR THE NEW 2026 PCB WITH THE FORUM TEAM
// THIS SKETCH IS CONFIGURED FOR EASY TESTING (QUICK FADE UP AND DOWN)
// REVISE FADE TIMING WHEN TESTING IS COMPLETE
const int ledPin = 0;
const int sensorPin = 2;
const int alertPin = 1;
const int battPin = 5;
const int darkPin = 3;
int delayTime = 30000;
int sensorValue = LOW;
unsigned long lastmotion;
// ATMEL ATTINY85
//
// +-\/-+
// BATT (D 5) PB5 1| |8 Vcc
// DARK (D 3) PB3 2| |7 PB2 (D 2) SENSOR
// (D 4) PB4 3| |6 PB1 (D 1) ALERT
// GND 4| |5 PB0 (D 0) LED
// +----+
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
pinMode(alertPin, OUTPUT);
pinMode(battPin, INPUT_PULLUP);
pinMode(darkPin, INPUT_PULLUP);
for (int i = 0; i < 10; i++) {
digitalWrite(alertPin, HIGH); // turn the LED on
delay(50); // wait for 500 milliseconds (half a second)
digitalWrite(alertPin, LOW); // turn the LED off
delay(2000); // wait for 500 milliseconds
}
//digitalWrite(sensorPin, LOW);//CHANGE TO LOW AFTER TESTING
//digitalWrite(battPin, HIGH); //CHANGE TO LOW AFTER TESTING
//digitalWrite(darkPin, HIGH);//CHANGE TO LOW AFTER TESTING
delay(60000); //UNCOMMENT AFTER TESTING
}
void loop() {
while (digitalRead(darkPin) == HIGH) {
digitalWrite(ledPin, LOW);
digitalWrite(alertPin, LOW);
}
while (digitalRead(darkPin) == LOW) { //CHANGE TO LOW AFTER TEST
//digitalWrite(sensorPin, LOW);
analogWrite(ledPin, 1);
analogWrite(alertPin, 25);
//delay(3000);
if (digitalRead(sensorPin) == HIGH) {
for (int i = 0; i < 5; i++) {
digitalWrite(alertPin, HIGH); // turn the LED on
delay(500); // wait for 500 milliseconds (half a second)
digitalWrite(alertPin, LOW); // turn the LED off
delay(500); // wait for 500 milliseconds
}
analogWrite(alertPin, 25);
// fade in from min to max 550 mA:
for (int fadeValue = 1 ; fadeValue <= 234; fadeValue += 1) {
// sets the value (range from 2 to 234):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(384); //CHANGE TO 384 AFTER TEST
}
delay(120000);
// lastmotion = millis();
//
//
// while (millis() < lastmotion + delayTime) {
// if (digitalRead(sensorPin) == HIGH) { // should this be LOW??
// lastmotion = millis();
// }
// }
// fade out from max to min 40 mA:
for (int fadeValue = 234 ; fadeValue >= 1; fadeValue -= 1) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(193); //CHANGE TO 193 AFTER TEST
}
delay(1000);
if (digitalRead(battPin) == HIGH) { //CHANGE TO LOW AFTER TEST??
for (int i = 0; i < 10; i++) {
digitalWrite(alertPin, HIGH); // turn the LED on
delay(50); // wait for 50 milliseconds (20th of a second)
digitalWrite(alertPin, LOW); // turn the LED off
delay(300);
} // wait for 100 milliseconds (10th of a second)
analogWrite(ledPin, 1);
analogWrite(alertPin, 25);
//delay(5000);
}
}
}
}
The comparator is applying 12v to the ATtiny pin 2...thats a bad thing. The ATtiny is not 12v tolerant.To isolate the 5 volt micro circuit.
Yes, I agree. It is what it is.There are always several ways to do things.
This project and circuit have been evolving as features have been added.
Using what has already been working rather then a complete redesign.
I'll admit running the LM393 off the 5 volt regulator is more practical.
Not following the meaning of that statement, is there a problem?One of my batteries is showing 12.99v, but my light restarts as soon as it draws >130 mA approx. I tested the same unit with another good battery that is at 11.7v and it worked just fine.
I was assuming my battery is bad and wanted opinion.Not following the meaning of that statement, is there a problem?
Actually it's pin1 that goes low for low battery detect.Should pin 2 on attiny go LOW when battery falls below 11.7v?