Hello,
I hope that I am posting this in the correct place.
I am working on a project that involves a radio controlled doorbell. When I press a button on the transmitter, the doorbell chimes and an LED turns on for 10 seconds before fading out.
I have some radio triggers that are used to trigger off-camera flashes from a DSLR. When a button is pressed on the transmitter, the receiver completes the circuit between the two connection wires. This part is working fine and I do not think it is relevant to my problem.
The doorbell is a solenoid-actuated mechanical doorbell. If you have not seen one before, this article explains it well: Ding Dong! - How Doorbells Work | HowStuffWorks
I am using a 5V logic level MOSFET to apply voltage to the doorbell when I want to make the sound. Applying voltage to the solenoid on the doorbell causes a piston to move up and down to make a chime.
Everything works great when I am powering the Arduino from the USB port and the solenoid with a 9V battery. The doorbell chimes when I trigger the transmitter.
However, I am experiencing some strange behavior if I power the Arduino by the same source that powers the doorbell. This is how I have wired it: Dropbox - Error - Simplify your life
I tried it first with a 9V battery. In this case, the white LED became very dim momentarily as the bell rung. Everything else worked fine. Next I tried a 12V wall wart. As before, the doorbell works when I trigger the transmitter. However, the Arduino appears to completely turn off momentarily (all of the onboard LEDs turn off) when the doorbell chimes.
I cannot tell if the Arduino is turning off when the solenoid is turned on or off. My current theory is that the collapsing magnetic field from the solenoid is producing a large voltage spike that is affecting the Arduino. This makes sense, but I haven't really been able to think of a way to protect the Arduino.
Does anyone have any thoughts or suggestions for this?
Thanks for reading!
I don't really think it is relevant, but here is the code I am using:
// Pins
const byte signal = A5; // If this goes HIGH, a signal has been received
const byte soundPin = 12; // Door bell trigger
const byte ledPin = 11; // LED trigger// Options
const byte ring_number = 1; // Number of rings
const int ring_time = 180; // Time between the "ding" and the "dong"
const int ring_delay = 180; // If multiple rings are set, time (in milliseconds) between rings
const long indicator_time = 10000; // How long (in milliseconds) to keep on the indicator light// Setup
unsigned long last_ring; // Stores the last time (in milliseconds) that the bell was rung
boolean indicator = false; // Records whether or not the indicator light is onvoid setup() {
// Setup Pins
pinMode(signal, INPUT);
pinMode(soundPin, OUTPUT);
pinMode(ledPin, OUTPUT);
}void loop() {
// If a signal is detected, ring the bell
if(digitalRead(signal) == HIGH) {
for(int rings = 1; rings <= ring_number; rings++) {
digitalWrite(soundPin, HIGH); // Turn on the sound
digitalWrite(ledPin, HIGH); // Turn on the LED
delay(ring_time);digitalWrite(soundPin, LOW);
// If this is not the final ring, turn off the indicator LED
if(rings != ring_number) {
digitalWrite(ledPin, LOW);
delay(ring_delay);
}
}
last_ring = millis(); // Record the last time the bell was rung
indicator = true; // Record the fact that the LED is on
delay(150); // Prevents the bell from being rung immediately after
}
// If the indicator LED has been on for a certain amount of time, fade it out
if(indicator == true && (millis() - last_ring >= indicator_time) ) {
for(int level = 255; level >= 0; level = level - 5) {
analogWrite(ledPin, level);
delay(50);
}
indicator = false;
}
}