This code uses a Atiny85 under Arduino gui:
#include <avr/sleep.h>
const int inputPin = 2; // replace with the input pin connected to the voltage divider
const int outputPin = 3; // replace with the output pin connected to the loadvoid setup() {
pinMode(inputPin, INPUT);
pinMode(outputPin, OUTPUT);
digitalWrite(outputPin, HIGH); // ensure the load is not grounded initially
}void loop() {
// Measure voltage on input pin
float voltage = analogRead(inputPin) * 0.0049; // convert from ADC value to voltage// If voltage is below 2V, ground the output pin and go into deep sleep
if (voltage < 2.0) {
digitalWrite(outputPin, LOW);
delay(100); // ensure the load is fully grounded before sleeping
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_mode();
sleep_disable();
}// Sleep for 1 day
delay(86400000); // 24 * 60 * 60 * 1000 = 1 day
}
this is ifor for the ATINY 85 programming