button and switch

Hello,
I'm 20 and just bought my first house, i'm completely rebuilding it
and would like to install domotics. I have a diploma in electronics and chose for Arduino because I belive in the Open Source idea.

I'm using push buttons in my house who power 24VDC relays, those relays give signal to a Arduino Mega 2560.
The Arduino exits are connected to 5V relays who power 230V AC lights or 230V AC dimmer modules

So I basicly only need the button and the switch programs, I can find both in the libarys
The problem is i never learned how to program using .html
If I use the button and switch program and rename everything I can get my Arduino to work
But if I use 2 working programs with diffrent names they don't work, do I need to end a program somehow before I type the next program?

Also does anyone have a idea how I would realise the following:
Pushbutton1 sets relay1 as switch
Pushbutton2 sets relay1 as switch but when relay1 is powered Push button 2 has no effect.

and

Pushbutton3 sets relay2 as switch
Pushbutton4 sets relay2 as switch but only for 2 minutes then relay2 gets turned off. (If relay2 was already turned on it stays on for 2 minutes)

I have been trying to make this work since november but no luck so far. I would really like Open Source domotics, if someone who understands Arduino programming would be able to get me on the right track I'd be for ever greatful. If someone would like a small tip for his help we could work something out too.

Thanx so far!

The problem is i never learned how to program using .html

Not a problem. You don't program the Arduino in html. You program it using C++.

If I use the button and switch program and rename everything I can get my Arduino to work

What "button and switch program"? What did you change?

But if I use 2 working programs with diffrent names they don't work, do I need to end a program somehow before I type the next program?

Not at the same time, they won't. You can only have one program (we call them sketches) on the Arduino at once.

do I need to end a program somehow before I type the next program?

Yes. Generally, that means saving the current sketch and starting a new one.

Pushbutton1 sets relay1 as switch

The relay is either switching voltage/current or it isn't. Pushing a switch won't change that.

I have been trying to make this work since november but no luck so far.

Programming is not like winning the lottery. There is no luck involved.

PaulS:

Not a problem. You don't program the Arduino in html. You program it using C++.

reffering to c++ as html, thats how newbie I am lol

What "button and switch program"? What did you change?

i'm using these programs http://www.arduino.cc/en/Tutorial/Switch and http://arduino.cc/en/tutorial/button

Not at the same time, they won't. You can only have one program (we call them sketches) on the Arduino at once.

then how would you program 20 different pushbuttons using the switch and button program?

for example
pushbutton1 sets pinA0 / pinA1 sets relay1 as button
pushbutton2 sets pinA2 / pinA3 sets relay2 as switch
pushbutton3 sets pinA4 / pinA5 sets relay3 as button
....

The relay is either switching voltage/current or it isn't. Pushing a switch won't change that.

this is how my project should work with relays

Programming is not like winning the lottery. There is no luck involved.

to learn something the easyest way for me has always been, feeling lucky and experementing

It sounds like you need to implement a single sketch which checks several inputs and then changes several outputs depending upon their status. With the Arduino running at 16 MHZ, it has plenty of time to check and update many pins thousands of times a second.

The cunning and elegant way to do this would probably be to use a couple of arrays to hold your pin definitions but you have plenty of space so the brute-force way will work perfectly well.

I'm not sure whether you want the output to simply reflect the state of the input (ie to be on when the input relay is closed) or whether you want it to toggle (ie to change state each time there is a short pulse from the relay) For the former you want a sketch that goes along these lines (obviously this is only an outline and not a real sketch):

int inputA = 3;
int inputB = 4; 
....
int inputX = X;

int outputA = 9;
int outputB = 10;
...
int outputX = Y;

void setup(){
pinMode(inputA, INPUT);
....
pinMode(inputX, INPUT);

pinMode(outputA, OUTPUT);
...
pinMode(outputX, OUTPUT);

}

void loop(){

if(digitalRead(inputA))digitalWrite(outputA, HIGH);
else digitalWrite(outputA, LOW);
....
if(digitalRead(inputX))digitalWrite(outputX, HIGH);
else digitalWrite(outputX, LOW);

delay(100) // Delay to avoid burning out your relays by switching a thousand times a second! Change this as you wish.

}

For a toggle sketch, you would declare a boolean (true/false) variable for each switch and change the state of that variable (stateA=!stateA;) each time the HIGH and then LOW was detected.

shivathedestroyer:
I'm using push buttons in my house who power 24VDC relays, those relays give signal to a Arduino Mega 2560.

I'm confused by your description of switches and relays - and your circuit diagrams haven't helped much because you seem to have switches labeled as relays.

If the purpose of the push button (switch) is to provide a signal to the Arduino then I would have thought you could just connect the switch to the Arduino - the relay doesn't seem to be adding anything.

to learn something the easyest way for me has always been, feeling lucky and experementing

Experimenting doesn't strike me as compatible with mains power....

What does

set relay as button
set relay as switch

... mean? A relay is already a digital "switch", and I'm not aware of any way to make it act as a button.

you need to debounce and state change detection, then you need to know how you would like to control the main
whats the diff of switch and button?

anyway some hint for you
if you want a relay to be switch on as long as a switch is press

 digitalWrite(Out,digitalRead(IN1);

if you want a relay to be turn off when switch is press. and turn on soon after that

 digitalWrite(Out,!digitalRead(In1);

Dr_Ugi:
It sounds like you need to implement a single sketch which checks several inputs and then changes several outputs depending upon their status. With the Arduino running at 16 MHZ, it has plenty of time to check and update many pins thousands of times a second.

The cunning and elegant way to do this would probably be to use a couple of arrays to hold your pin definitions but you have plenty of space so the brute-force way will work perfectly well.

I'm not sure whether you want the output to simply reflect the state of the input (ie to be on when the input relay is closed) or whether you want it to toggle (ie to change state each time there is a short pulse from the relay) For the former you want a sketch that goes along these lines (obviously this is only an outline and not a real sketch):

int inputA = 3;

int inputB = 4;
....
int inputX = X;

int outputA = 9;
int outputB = 10;
...
int outputX = Y;

void setup(){
pinMode(inputA, INPUT);
....
pinMode(inputX, INPUT);

pinMode(outputA, OUTPUT);
...
pinMode(outputX, OUTPUT);

}

void loop(){

if(digitalRead(inputA))digitalWrite(outputA, HIGH);
else digitalWrite(outputA, LOW);
....
if(digitalRead(inputX))digitalWrite(outputX, HIGH);
else digitalWrite(outputX, LOW);

delay(100) // Delay to avoid burning out your relays by switching a thousand times a second! Change this as you wish.

}




For a toggle sketch, you would declare a boolean (true/false) variable for each switch and change the state of that variable (stateA=!stateA;) each time the HIGH and then LOW was detected.

I see that this is very similar to my problem (http://arduino.cc/forum/index.php/topic,149665.0/topicseen.html), How would a boolean for a toggle switch look like? Anyone got experience with this??
Thanx anyway
janjoris

How would a boolean for a toggle switch look like?

boolean toggled = false;

Anyone got experience with this??

Yes..