Go Down

Topic: button and switch (Read 883 times) previous topic - next topic

shivathedestroyer

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!

PaulS

Quote
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++.

Quote
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?

Quote
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.

Quote
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.

Quote
Pushbutton1 sets relay1 as switch

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

Quote
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.

shivathedestroyer


Quote
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


Quote
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

Quote
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
....


Quote
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




Quote
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


Dr_Ugi

#3
Feb 04, 2013, 01:51 pm Last Edit: Feb 04, 2013, 03:22 pm by Dr_Ugi Reason: 1
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):

Code: [Select]
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.


PeterH


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.
I only provide help via the forum - please do not contact me for private consultancy.

JimboZA

Quote
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....

Roy from ITCrowd: Have you tried turning it off an on again?
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Arrch

What does

Quote
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.

ash901226

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
Code: [Select]
digitalWrite(Out,digitalRead(IN1);
if you want a relay to be turn off when switch is press. and turn on soon after that
Code: [Select]
digitalWrite(Out,!digitalRead(In1);

janjoris


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):

Code: [Select]
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

PaulS

Quote
How would a boolean for a toggle switch look like?

Code: [Select]
boolean toggled = false;

Quote
Anyone got experience with this??

Yes..

Go Up