Hey guys, I have just gotten an ATtiny85 and figured out how to program it and everyhting, but my simple program i'm trying to use isn't working. The code is suppost to read the voltage of pin #2 and then turn an LED on if it below 3.5 volts. What it is doing however, is as soon as it gets power it just turns the led on. Any ideas why it isn't working? Thanks
int batteryPin = 2;
int ledPin = 3;
float batteryVoltage = 0.0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(batteryPin, INPUT);
}
void loop() {
batteryVoltage = (analogRead(batteryPin)) * (5.0 / 1023.0);
delay(5);
if (batteryVoltage <= 3.5){
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
EmanEric:
Hey guys, I have just gotten an ATtiny85 and figured out how to program it and everyhting, but my simple program i'm trying to use isn't working. The code is suppost to read the voltage of pin #2 and then turn an LED on if it below 3.5 volts. What it is doing however, is as soon as it gets power it just turns the led on. Any ideas why it isn't working? Thanks
int batteryPin = 2;
int ledPin = 3;
float batteryVoltage = 0.0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(batteryPin, INPUT);
}
void loop() {
batteryVoltage = (analogRead(batteryPin)) * (5.0 / 1023.0);
delay(5);
if (batteryVoltage <= 3.5){
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}
You're sure that the pin supports analog input?
Rupert909:
You're sure that the pin supports analog input?
Wow I am dumb, yeah I realized that I was calling the 7th pin on the Attiny pin 2 instad of A1, so it was not working properly, thanks.