Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
Hi, I would of thought this is quite a simple project but as I am new I would like some help on what to buy and then the programming to go with it.
My problem is that to do this it costs me £150 using SPDT timer relays. So I have decided to start a new project using Arduino.
I have a basic 3 gang light switch with 12v running through it and this will need to send a 12v pulse signal to a light driver (lumishore) to turn on. To turn the light off another pulse signal at 12v is needed.
So each switch will provide a separate signal to their own driver.
I'm not familiar with Lumishore, but that may not be important 😉
I have to admit that I'm not quite understanding what you're asking, so forgive me if I understood things wrong. Do I get this right?
You have 3 lights (with each their own driver). To turn an individual light on, a 12V pulse needs to be send to the driver. Turning the light off again works the same way? And the timer relays are used to keep the signal "up" long enough for the driver to switch (on or off, so keeping the 12V pulse long enough for the driver to pick it up).
In that case I'd get a simple Arduino Uno, or something like that. Next I'd get one of these 4 relay blocks: Amazon.de, Amazon.com - you'll have one spare relay, but this way the relays are nicely kept together. You can of course pick other relay options (Amazon.de, Amazon.com). Obviously you'll need 3 simple push buttons.
I'd start with experimenting with one switch and one relay. If you look at guides like this one (replace the PIR with the push button, as shown here), then the Arduino only has to respond to the button being pushed. When the button is pushed, the Arduino has to hold the relay for a certain time before it lets go again.
The schematics should look something like this (for one button and one relay - don't forget to connect +5V and GND to the Arduino):
The Arduino code could look something like this (I haven't tested it);
#define Button1Pin 2
#define Relay1Pin 8
int Button1State = 0; // variable for reading the pushbutton status
void setup() {
// initialize the Relay pin as an output:
pinMode(Relay1Pin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(Button1Pin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
Button1State = digitalRead(Button1Pin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (Button1State == HIGH) {
// turn relay on:
digitalWrite(Relay1Pin, HIGH);
// keep the relay on for a second (1000 = 1 second)
delay(1000);
// turn relay off again
digitalWrite(Relay1Pin, LOW);
}
}
Once you have that working, you can assign each button their own pin on the Arduino, and the same for the relays. The code should be easy to adjust as well, something like this (again: untested):
#define Button1Pin 2
#define Button2Pin 3
#define Button3Pin 4
#define Relay1Pin 8
#define Relay2Pin 9
#define Relay3Pin 10
int Button1State = 0; // variable for reading the pushbuttons status
int Button2State = 0;
int Button3State = 0;
void setup() {
// initialize the Relay pin as an output:
pinMode(Relay1Pin, OUTPUT);
pinMode(Relay2Pin, OUTPUT);
pinMode(Relay3Pin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(Button1Pin, INPUT);
pinMode(Button2Pin, INPUT);
pinMode(Button3Pin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
Button1State = digitalRead(Button1Pin);
Button2State = digitalRead(Button2Pin);
Button3State = digitalRead(Button3Pin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (Button1State == HIGH) {
// turn relay on:
digitalWrite(Relay1Pin, HIGH);
// keep the relay on for a second (1000 = 1 second)
delay(1000);
// turn relay off again
digitalWrite(Relay1Pin, LOW);
}
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (Button2State == HIGH) {
// turn relay on:
digitalWrite(Relay2Pin, HIGH);
// keep the relay on for a second (1000 = 1 second)
delay(1000);
// turn relay off again
digitalWrite(Relay2Pin, LOW);
}
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (Button3State == HIGH) {
// turn relay on:
digitalWrite(Relay3Pin, HIGH);
// keep the relay on for a second (1000 = 1 second)
delay(1000);
// turn relay off again
digitalWrite(Relay3Pin, LOW);
}
}
Alternatives to using an Arduino:
If you know somebody more technical than me, you could make your own timer relay. I believe, but could be wrong, a good capacitor may be able to hold the relay long enough for the signal to have the driver switch.
I would not be surprised to see the relays you mentioned on AliExpress for cheap.
If the switch should latch (eg. stay connected or stay disconnected) then you can accomplish that with this small change. I'm saving the previous button state, to avoid that when a button was pressed for say a second or two, the code won't keep triggering the relay (which is probably harmless, but I'd rather be sure).
Note: Push buttons can have a so called "bounce" effect, where the Arduino sees a single press potentially as multiple button presses. The resistor should prevent this from happening. However, if this still happens in your setup, then we can use a timer to catch this.
#define Button1Pin 2
#define Relay1Pin 8
int Button1State = 0; // variable for reading the pushbutton status
int Button1PreviousState = 0; // remember last change, so we do not keep repeating
void setup() {
// initialize the Relay pin as an output:
pinMode(Relay1Pin, OUTPUT);
// Start with relay off, this may not be required
digitalWrite(Relay1Pin, LOW);
// initialize the pushbutton pin as an input:
pinMode(Button1Pin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
Button1State = digitalRead(Button1Pin);
// check if the pushbutton is pressed and changed (to avoid repeats)
if (Button1State <> Button1PreviousState) { // button state changed
if (Button1State == HIGH) {
digitalWrite(Relay1Pin, HIGH); // turn relay on
}
else {
digitalWrite(Relay1Pin, LOW); // turn relay off
}
}
Button1PreviousState = Button1State;
}
I do not fully know why the resistor trick works, as I'm unaware of some of the internals of the microcontroller. What it in essence does, is cleanup the "noise" when pressing a button, which may been seen more than once as a button press.
There are quite a few solutions to debounce, either in hardware or in software. In software you could do something like this: if a button is pressed again within a certain time, then ignore that it was pressed. In hardware the resistor approach is the easiest, but there are more precise and more complex solutions.
In function 'void loop()': Lumishore_Switches:22:21: error: expected primary-expression before '>' token if (Button1State <> Button1PreviousState) { // button state changed ^ exit status 1 expected primary-expression before '>' token
Photopea A free alternative to Photoshop (pretty close anyway), and runs in your browser - this works surprisingly good!
Frizting Free tool to design schematics and PCB's - they even offer a very affordable PCB production service.
Robots.txt Analyzer Very simple and effective tool for online checking of your robots.txt file without having to use Google Webmaster Tools.
0xED - Hex Editor Compact, fast and very flexible Hex (hexadecimal) editor for MacOS.
GTMetrix Awesome tool to analyze the speed of your website!
Osceola, WI My other home-town ... love living there! Osceola rocks!
Links Page These and more of our favorite links can be found on the Links Page.
New Downloads
ConnectMeNow4-v4.0.18-macOS-x86-64.dmgDate: 2024-04-24 - Size: 3.5 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Intel version which works on Intel and Apple Silicon Macs.
ConnectMeNow4-v4.0.18-macOS-arm64.dmgDate: 2024-04-24 - Size: 3 MBVersion 4 of ConnectMeNow - A tool for more convenient mounting of network shares under macOS. This is the Apple Silicon version (not suitable for Intel).
MiniWOL2 MacOS (64 bits Apple Silicon)Date: 2023-08-01 - Size: 1.2 MBminiWol is a simple, but effective application to send Wake On LAN to network devices. This is the signed 64 bit MacOS ARM (Apple Silicon) version.
MovieScanner2-2.2.3-Windows-32bit-setup.exeDate: 2023-04-12 - Size: 18.6 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 32 bit Windows version.
MovieScanner2-2.2.2-Linux-GTK-64bits.tar.gzDate: 2023-04-11 - Size: 29.2 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for GTK.
MovieScanner2-2.2.2-Linux-QT5-64bits.tar.gzDate: 2023-04-11 - Size: 29.1 MBA small application that uses FFProbe to scan your video files and logs these details in a small database. This is the 64 bit Linux version for QT5.
Downloads Page Find these and more Downloads on the Downloads Page, where you will also find articles references, operating system requirements and categories.
Amazon Ads
Support us by doing your shopping at Amazon.com, either click the link, or click one of the links below …
You can also sponsor us through these Amazon offerings:
Please consider disabling your ad blocker for our website.We rely on these ads to be able to run our website.You can of course support us in other ways (see Support Us on the left).