Arduino + Power Switch Tail Fountain Controller
Syncing Things Up
My wife and I recently put in some new landscaping in our front yard, including low-voltage lighting controlled by a transformer/controller housed in our garage. The lighting controller had some nice features: you could turn the lights on at dusk via an optional photoelectric cell, and then turn the lights off with a timer, also an extra option. That was ideal for us, on at sundown, off at 10:00 PM.
At the same time we also purchased a granite, Japanese-style fountain that had embedded LED lights at the fountain throat. This looks dramatic at night as the lights are bright and the water reflects the light and, as our landscaper said, "looks like white fire".
We wanted the fountain and lights to sync with the landscape lighting controller, on at dusk, off at 10:00 PM. The fountain had a separate power cord for the lights and another for the pump. The landscape controller already had the timing we wanted, so it would have been ideal to connect it to the fountain/lights. However, neither our landscaper nor us wanted to try jacking the power for the fountain/lights directly into a $350 controller and watch it fry.
We tried using some digital timers, but these had some drawbacks. The cheap ones we looked at used extra-small fonts on their LCD display and a non-intuitive programming/setup process. If you ever had to reprogram the device, it was back to studying the instructions. The one we did buy offered a manual on switch, which we liked. We wanted to be able to turn on the fountain independently of the landscape lights, too. However, with the small font size and a confusing system for indicating when you were on manual, it was a painful device to use.
So, what to do?
At the same time we also purchased a granite, Japanese-style fountain that had embedded LED lights at the fountain throat. This looks dramatic at night as the lights are bright and the water reflects the light and, as our landscaper said, "looks like white fire".
We wanted the fountain and lights to sync with the landscape lighting controller, on at dusk, off at 10:00 PM. The fountain had a separate power cord for the lights and another for the pump. The landscape controller already had the timing we wanted, so it would have been ideal to connect it to the fountain/lights. However, neither our landscaper nor us wanted to try jacking the power for the fountain/lights directly into a $350 controller and watch it fry.
We tried using some digital timers, but these had some drawbacks. The cheap ones we looked at used extra-small fonts on their LCD display and a non-intuitive programming/setup process. If you ever had to reprogram the device, it was back to studying the instructions. The one we did buy offered a manual on switch, which we liked. We wanted to be able to turn on the fountain independently of the landscape lights, too. However, with the small font size and a confusing system for indicating when you were on manual, it was a painful device to use.
So, what to do?
Solution #1 - OptoIsolator
I felt confident I could cobble together a solution to the problem using an arduino and some other components. I just had to do some research. The problem definition has three parts:
OK, that takes care of power control. How to signal when the landscape controller was on?
The first thing I experimented with was an optoisolator. Very simply, this is an LED on one side of a gap, with a light detector on the other all encased in a tiny, light-proof shell. When the LED gets a voltage, it goes on, triggering the light detector. It's a way to isolate circuits from each other as you might want to do when one circuit is 12-15V AC (landscape controller) and one is operating on 5V DC (arduino).
I experimented with an optoisolator, hooking it up first to our old landscape controller. OK, seems to work fine. Let's try it out on the real deal, the new controller. Aaaaah! Turn it off, turn it off! A light pall of rubbery-smelling magic smoke appeared. Now I've done it. Check the controller. Whew! Still works....
What I had done was filched a circuit from the web and failed to read it carefully enough. I missed a ground. Oops. Time to review. Get it working, but it's cycling through on/off cycles while the controller remains constantly on. Hmn. Off to various forums for tips on how to use optoisolators. Found out that there are "double" optoisolators made just for AC current, and I had been using a "single" made for DC current. The landscape controller, while low voltage, was AC. The DC optoisolators can work, but you need to add some parts to the circuit. The optoisolators made to work with AC have two LEDs, each one picking up part of the AC cycle. The repeated on/off behavior I was seeing was the unmodified DC optoisolator only one phase of the AC cycle.
- Power control of the fountain
- Detect when the landscape controller is on/off
- Be able to turn on the fountain/LEDs independently of the landscape controller
OK, that takes care of power control. How to signal when the landscape controller was on?
The first thing I experimented with was an optoisolator. Very simply, this is an LED on one side of a gap, with a light detector on the other all encased in a tiny, light-proof shell. When the LED gets a voltage, it goes on, triggering the light detector. It's a way to isolate circuits from each other as you might want to do when one circuit is 12-15V AC (landscape controller) and one is operating on 5V DC (arduino).
I experimented with an optoisolator, hooking it up first to our old landscape controller. OK, seems to work fine. Let's try it out on the real deal, the new controller. Aaaaah! Turn it off, turn it off! A light pall of rubbery-smelling magic smoke appeared. Now I've done it. Check the controller. Whew! Still works....
What I had done was filched a circuit from the web and failed to read it carefully enough. I missed a ground. Oops. Time to review. Get it working, but it's cycling through on/off cycles while the controller remains constantly on. Hmn. Off to various forums for tips on how to use optoisolators. Found out that there are "double" optoisolators made just for AC current, and I had been using a "single" made for DC current. The landscape controller, while low voltage, was AC. The DC optoisolators can work, but you need to add some parts to the circuit. The optoisolators made to work with AC have two LEDs, each one picking up part of the AC cycle. The repeated on/off behavior I was seeing was the unmodified DC optoisolator only one phase of the AC cycle.
Exploiting Simplicity
While doing my research, I saw a forum posting where someone wanted to tell when a circuit powered on. One of the replies was "stick a night light in there and put a photocell on it to tell when the light comes on." Then it hit me: the landscape controller HAD a light inside of it, a power-on light that only operated when power was applied to the lights. Perfect!
Just had to do a little experimentation to calibrate the arduino to the returned photocell values. When I got values that unequivocally indicated the landscape controller was on, I turned on the power switch tail from the arduino.
The circuit on the left will use the presence of light as a trigger for the speaker to make a buzzing sound. As long as the photocell detects sufficient light, with sensitivity controlled by the 100k ohm potentiometer, the speaker will buzz. Using information from the circuit on the right, if you remove the 10u cap and speaker at pin 3 of the 555 in the Light Detector circuit and substitute in a 2.2k ohm resistor and an NPN transistor to drive your load, this modified circuit will work to trigger the Power Switch Tail. I tested this with a 2N3904 and it worked fine.
Just had to do a little experimentation to calibrate the arduino to the returned photocell values. When I got values that unequivocally indicated the landscape controller was on, I turned on the power switch tail from the arduino.
Photocell Mounted inside Landscape Controller
Fountain Controller I/O: from Photocell; to Power Switch Tail
Fountain Controller I/O: from Photocell; to Power Switch Tail
The only other thing needed was to mount the arduino in a project box. I added an LED to indicate power on for the fountain/LEDs, and an LED to show power on for the landscape controller. Finally, I added a pushbutton to be able to turn the fountain/LEDs on independently of the landscape lights.
Fountain/LED Power On Controller
Now, the Hack-a-Day crowd will argue that using an arduino for this is massive overkill. True!
But you can never have enough overkill. Seriously, if I had better skills I could have just used a 555 timer triggered by the photocell. It would have been much cheaper. However, I had taken too much time figuring out how to get this working, I had a wife to keep happy, and I already had familiarity with arduino and knew I could get it done with that.
But you can never have enough overkill. Seriously, if I had better skills I could have just used a 555 timer triggered by the photocell. It would have been much cheaper. However, I had taken too much time figuring out how to get this working, I had a wife to keep happy, and I already had familiarity with arduino and knew I could get it done with that.
Arduino Code:
#include
int photocellPin = 0; // the cell and 10K pulldown are connected to a0
int photocellReading; // the analog reading from the sensor divider
//int optoPin = 9; // input from optoisloator/transformer
int pwrLED = 13; // Power on/off indicator light 0 = OFF; 1 = ON
int fountLED = 7; // Fountain on/off indicator light 0 = OFF; 1 = ON
int pushbutton = 5; // PushButton switch: Normally Open (0), when closed sends HIGH (1)
int transistor = 3; // Transistor 2N3904 or similar NPN attached through 10K-22K resistor
int pwr = 1; // Transformer State: Logic LOW (0) indicates ON; Logic HIGH (1) indicates OFF!
int prev_pwr = 1; // Previous power state, to detect change in power. Same logic as pwr
int fountain = 0; // Is the fountain on/off? 0 = OFF; 1 = ON
int pb = 0; // PushButton State: 0 = OFF; 1 = ON
int prev_pb = 0; // Previous PushButton State, to detect change in on/off
// Instantiate a Debounce object with a 20 millisecond debounce time
Debounce debouncer = Debounce( 20 , pushbutton);
void setup()
{
// pinMode(optoPin, INPUT);
// digitalWrite(optoPin, HIGH); // need to set pull-up resistor or values float!
pinMode(pwrLED, OUTPUT);
pinMode(fountLED, OUTPUT);
pinMode(transistor, OUTPUT);
Serial.begin(9600);
Serial.print("Starting...\n");
}
void loop()
{
//pwr = digitalRead(optoPin);
photocellReading = analogRead(photocellPin);
if (photocellReading >= 510)
pwr = 0; // POWER ON
else
pwr = 1; // POWER OFF
// Update the debouncer
debouncer.update();
// Get the update value
pb = debouncer.read();
if (pwr) // Logic 1 = POWER OFF
if (pb) // Pushbutton was pressed, Logic 1
if (prev_pb) // If it was ON, turn it OFF
{fountUpd(0);
prev_pb = 0;
}
else
{fountUpd(1); // If it was OFF, turn it ON
prev_pb = 1;
}
delay(100);
Serial.print("Pushbutton value is: ");
Serial.print(pb);
Serial.print("\n");
Serial.print("Power Setting = ");
Serial.print(pwr);
Serial.print("\n");
if (pwr != prev_pwr) // A change in power state occured
{prev_pwr = pwr;
if (!pwr) // Power was turned on
{fountUpd(1);
Serial.print("Power Detected!\n");
digitalWrite(pwrLED, HIGH);
}
else // Power was turned off
{fountUpd(0);
Serial.print("NO POWER!\n");
digitalWrite(pwrLED, LOW);
}
}
//delay(2000);
}
void fountUpd(int state) {
fountain = state;
digitalWrite(fountLED, state); // turn on fountain status LED
digitalWrite(transistor, state); // activate transistor for Power Switch Tail
}
Here's another example of this idea of "Exploiting Simplicity" : turning on/off a computer remotely via arduino hooked up to the computer power switch, grounding it out appropriately. Video by Mr. Hasselhoff of www.ZomgStuff.netUpdate:
Checked into a 555 timer circuit that could do the same thing as the Arduino gadget I built:
Checked into a 555 timer circuit that could do the same thing as the Arduino gadget I built:
The circuit on the left will use the presence of light as a trigger for the speaker to make a buzzing sound. As long as the photocell detects sufficient light, with sensitivity controlled by the 100k ohm potentiometer, the speaker will buzz. Using information from the circuit on the right, if you remove the 10u cap and speaker at pin 3 of the 555 in the Light Detector circuit and substitute in a 2.2k ohm resistor and an NPN transistor to drive your load, this modified circuit will work to trigger the Power Switch Tail. I tested this with a 2N3904 and it worked fine.
Comments
Post a Comment