Doorbell receiver module had it's speaker removed, does not produce sound. Instead, the signal generated is read through A0 and is used to turn a LED block ON for a few minutes.
It´s working as a wireless lamp, so I can light my way to the bathroom at night.
When the powerbank is turned on, the arduino runs at 5V, the LED block is connected to 5V and the doorbell receiver is running at 3.3V. The output of the audio chip is being listened through A0 and, when I press the transmitter, the audio chip output goes higher, which turns the LED block on through D3 by PWM. I would like to:
- Press one time, LEDs turn on for OnTime=2min
- Press again immediately and OnTime becomes Ontime=4min
- Press again, etc...
- I go to the bathroom, come back and it's still on? I decide to press again and D3 goes LOW.
I wrote this simple code using delays to test the overall setup. I guess I have to use milis() or a Timer library but for that I need your help.
It´s working as a wireless lamp, so I can light my way to the bathroom at night.
When the powerbank is turned on, the arduino runs at 5V, the LED block is connected to 5V and the doorbell receiver is running at 3.3V. The output of the audio chip is being listened through A0 and, when I press the transmitter, the audio chip output goes higher, which turns the LED block on through D3 by PWM. I would like to:
- Press one time, LEDs turn on for OnTime=2min
- Press again immediately and OnTime becomes Ontime=4min
- Press again, etc...
- I go to the bathroom, come back and it's still on? I decide to press again and D3 goes LOW.
I wrote this simple code using delays to test the overall setup. I guess I have to use milis() or a Timer library but for that I need your help.
Code:
/* Wireless doorbell modified to turn ON a block of LEDs instead of playing a melody.
When the switch is pressed on the transmitter, a voltage change occurs in the audio
chip output of the receiver, which corresponds to the playing of the melody. This voltage
change is read through and analog pin. When the voltage rises over a defined threshold,
pin D3 outputs a PWM signal for a certain interval of time. The base of a 3904 transistor
is connected to D3 through a 1K Ohm resistor; the collector is connected to the load and the emitter do GND.*/
const int analogPin = A0; // A0 connected to audio chip output
const int ledPin = 3; // D3 to resistor to transistor base to trigger LED block
const int threshold = 650; // an arbitrary threshold level that's in the range of the analog input
unsigned long interval = 2 * 60 * 1000UL; //2 minutes ON time
void setup() {
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
// Serial.begin(9600); // initialize serial communications:
}
void loop() {
int analogValue = analogRead(analogPin);
//Serial.println(analogValue); // print the analog value:
//delay(10); // delay in between reads for stability
/*When the switch in pressed, analogValue rises over threshold, it's time to turn LED ON for interval */
if (analogValue > threshold) {
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
}
delay(interval);
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
}
}
}