Go Down

Topic: help code relay (Read 958 times) previous topic - next topic

tarekza3tari

i have 2 relays: the first relay connect to pin 2 (interrupt)(220v) and the second connect to pin 5 (control a lamp)(5v) , i want when the 2 relays connect to electricity the lamp turn on and when disconnect the first relay to electricity the lamp turn off and when reconnect the lamp turn off.
i write a code but does not work if you have someone help me thank u.

Note: it's Necessary to use interrupt

code:

#define relay2  5;
#define relayx 2
//int x=0;


void setup()

  Serial.begin(9600);
  pinMode(relay2, OUTPUT);
  attachInterrupt(0,ETAT,FALLING);
   
}

void loop()
{
 
}

void ETAT(){
      digitalWrite(relay2,HIGH); //Pull ledPin to high

 
}



Cookies

From what I understand you want the 220V mains to turn on a relay which will turn on a lamp via the arduino, in which case you only need a single relay - connect the coil to 220V (make sure the relay coil is meant for 220V AC) and the switch contacts to the lamp & power source of the lamp.

If that's not what you meant then a circuit diagram may help.

Arrch

but does not work


"It does not work" is not a valid way of describing the problem you are having.

rockwallaby

#3
Feb 08, 2013, 01:50 am Last Edit: Feb 08, 2013, 12:15 pm by rockwallaby Reason: 1
You would be better served if you posted this topic in 'General Electronics' or 'Programming Questions' section of the forum, possibly more people will notice it there.

Also, please try to be as descriptive and clear as possible, spend a few extra minutes to do this and provide code in the code section brackets so it is displayed correctly. It is provided there for you as a button on the online editor.

You can also help yourself much more by making use of serial print statements to see what is happening with your code.
That way you will learn.

Quote
tarekza3tari wrote:
Note: it's Necessary to use interrupt

Is that a statement or a question?
Please explain why.

Paul

tarekza3tari

My project is a controller lamp (did ??from the control relay 5v) and used two other relays.

one relay plays the role of a (motor electricity) and the other relay plays the role of (the state electricity).

Relay 5 V: Connect to pin 5 arduino and connect to lamp that connects to electricity
relay 220v (State): Connect to pin 2 (interrupt 0) and connect  cable to electricity
relay 220v (motor):  connect pin 3 (interrupt 1) and connect  cable to electricity
and a sensor measuring the lamp current

I'm there when (the state electricity) the fluorescent lamp when I remove the cable of electricity (turn off the lamp) and at the same time must measure the current and if the current> 0.2 light the lamp nor Turns off the lamp from relay pin 3

if anyone can help with, thank you.


code



#define relayx 2
#define relay2 5
#define relayy 3

volatile int x=LOW;


void setup()

  Serial.begin(9600);
  pinMode(relay2, OUTPUT);
  attachInterrupt(0,ETAT,FALLING);
  attachInterrupt(1,relaymoteur,RISING);
}

void loop()
{
  measure current ( x)
}

void ETAT(){
  digitalWrite(relay2,HIGH);
  }
 
void relaymoteur(){
  if (x>0.2)
  {
    digitalWrite(relay2, HIGH);
    while(1){}
  }
   else
   {
     digitalWrite(relay2, LOW);
     while(1){}
   }
 
}

Go Up