hello all,
I just got my new ATtiny85 to shrink down a current project I am working on. Essentially I am presetting a voltage threshold to monitor a 12V battery and trigger a relay when it gets below the threshold. I used a simple voltage divider circuit. Please note that I know I programmed my ATtiny85 correctly because I first did it with the blink sketch on an LED, so my wiring to program it is correct. Whenever I upload this to the board, the relay just comes on and stays on, and doesn't behave as it should. Please forgive my programming as it is probably not the most efficient and logical haha..
Is this a programming issue or a hardware issue or something else? I am trying to utilize pin 3 on the ATtiny (A3) to read the voltage from the voltage divider.
Thanks!
-Adam
float vIn = 0;
float voltage = 0;
int val = 0;
int relay = 4;
float threshold = 12.3; // ----------------SET VOLTAGE THRESHOLD HERE------------------------
void setup() {
// put your setup code here, to run once:
pinMode(3, INPUT);
pinMode(relay, OUTPUT);
digitalWrite(relay, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
//R1 = 9.93k || R2 = 4.7k
val = analogRead(3);
vIn = map(val, 0, 1023, 0, 4.819);
voltage = map(vIn, 0, 4.819, 0, 15);
if(voltage <= threshold){
digitalWrite(relay, LOW);
delay(3000);
}
val = analogRead(3);
vIn = map(val, 0, 1023, 0, 4.819);
voltage = map(vIn, 0, 4.819, 0, 15);
if( voltage > threshold){
digitalWrite(relay, HIGH);
delay(1000);
}
}