I am trying to generate a pulse with an attiny85.
Situation as follows:
Amplifier switches on, gives 5 volts on P2 of attiny
Amplifier switches off, 5 volts on P2 drops out.
Now I want P3 to have 1 pulse of 0.5 seconds, digitalwrite = HIGH, as soon as 5v comes on P2, and also 1 pulse of 0.5 seconds as soon as 5v drops out. This is to control a bc547 + relay.
This relay then switches the 433mhz remote control of my ceiling fan with lighting
I tried something myself, but unfortunately it doesn't work.
When attiny is switched on, the relay switches on and stays on regardless of input.
Someone who sees what I am doing wrong and can help me get the correct code?
My code:
// constants won't change. They're used here to set pin numbers:
const int amplifierPin = 3; // the number of the input pin
const int remotePin = 2; // the number of the transistor pin
// variables will change:
int amplifierState = 0; // variable for reading the input status
void setup() {
// initialize the output pin as an output:
pinMode(remotePin, OUTPUT);
// initialize the input pin as an input:
pinMode(amplifierPin, INPUT);
}
void loop() {
// check if the amplifier is on:
amplifierState = digitalRead(amplifierPin);
// check if the amplifier is on. If it is, the amplifierState is HIGH:
if (amplifierState == HIGH) {
// pulse remote:
digitalWrite(remotePin, HIGH);
delay (500);}
// check if the amplifier is off. If it is, the amplifierState is LOW:
if (amplifierState == LOW) {
// pulse remote
digitalWrite(remotePin, HIGH);
delay (500);}
}