I had this working on an UNO but for some reason does not work on Attiny85 as it should. What am I doing wrong?
int PIR_Sensor_Pin0 = 0; // PIR_Sensor1_Pin from passive Infra red 1
int PIR_Sensor_Pin1 = 1; // PIR_Sensor2_Pin from passive Infra red 2
int Piezo_Pin = 2;
int inputPin = A2; //Pin 3, to read 0-5volts
int inputValue = 0; //the value of the LDR pin
int val = 0; // variable for reading the PIR_Sensor_Pin status
int val1 = 0; // variable for reading the PIR_Sensor_Pin status
int LED3 = 3; // On when Passives armed
boolean alreadyBeepedon = false;
boolean alreadyBeepedoff = false;
void setup() {
pinMode(Piezo_Pin, OUTPUT); // declare Piezo_Pin as output
pinMode(PIR_Sensor_Pin0, INPUT_PULLUP); // declare PIR_Sensor_Pin as input
pinMode(PIR_Sensor_Pin1, INPUT_PULLUP); // declare PIR_Sensor_Pin as input
pinMode(LED3, OUTPUT);
}
void loop(){
inputValue = analogRead(inputPin);
if (inputValue < 380){ //380 default
digitalWrite(LED3, HIGH);
}
else {
digitalWrite(LED3, LOW);
//BEEP WHEN ON//
if(digitalRead(LED3) == HIGH )
{
if(!alreadyBeepedon){
digitalWrite(Piezo_Pin, HIGH);
delay(80);
digitalWrite(Piezo_Pin, LOW);
delay(500);
alreadyBeepedon = true;}
}
else {
alreadyBeepedon = false;}
//BEEP WHEN OFF//
if(digitalRead(LED3) == LOW )
{
if(!alreadyBeepedoff){
digitalWrite(Piezo_Pin, HIGH);
delay(80);
digitalWrite(Piezo_Pin, LOW);
delay(500);
alreadyBeepedoff = true;}
}
else {
alreadyBeepedoff = false;}
}
////////////BEEP WHEN PASSIVE ACTIVATED////////////
inputValue = analogRead(inputPin);
val = digitalRead(PIR_Sensor_Pin0);
if (val == HIGH && digitalRead(LED3) == HIGH) {
digitalWrite(Piezo_Pin, HIGH);
delay(80);
digitalWrite(Piezo_Pin, LOW);
delay(80);
digitalWrite(Piezo_Pin, HIGH);
delay(80);
digitalWrite(Piezo_Pin, LOW);
delay(80);
digitalWrite(Piezo_Pin, HIGH);
delay(80);
digitalWrite(Piezo_Pin, LOW);
delay(10000);
}
val1 = digitalRead(PIR_Sensor_Pin1);
if (val1 == HIGH && digitalRead(LED3) == HIGH) {
digitalWrite(Piezo_Pin, HIGH);
delay(80);
digitalWrite(Piezo_Pin, LOW);
delay(80);
digitalWrite(Piezo_Pin, HIGH);
delay(80);
digitalWrite(Piezo_Pin, LOW);
delay(10000);
}
}