Tuesday, October 25, 2011

InduinoX and wireless relays: Part I

It has been a while since I received my wireless relay and I finally got some time this weekend to put them to good use.

The connections were really simple. I connected a 5V DC power supply (check polarity, the center pin should be positive) to the wireless transmitter and a 12V DC power supply to the relay board (which also has the receiver).

To control the relays using InduinoX, I connected the wireless transmitter board ground to the InduinoX board's ground. Connected the relay 0 pin on the board to digital pin 7 on InduinoX.


Finally connecte the light bulb to mains neutral, the live from mains to the common pin on the relay and "normally closed" (NC) pin on the relay to the light bulb.


Generally you would connect the "Normally open" (NO) pin to the light bulb instead of NC, but I will explain in a minute why I had to connect NC. Now to the coding part. The specification for the relay tells us that when the relay pin is open (high impedance), the relay is active. And when the relay pin is connected to the ground, the relay is inactive.

On the InduinoX board, when a digital pin is set to input mode, the input impedance is very high causing it to act like an open switch. So setting the pin 7 to input mode will cause the relay to be active. Now the InduinoX board always starts with all the digital pins set to input mode which means the relay will start off being active. Which is why I connected the NC pin to the light bulb otherwise with NO connected to the light bulb, the light will be on when the InduinoX starts up.

To turn off the relay I have to connect the relay pin to ground. The way it is done with InduinoX is by setting the pin to output mode and then send low signal. Here is the code for all this logic.

#define TRUE  1
#define FALSE 0

int LIGHT_PIN = 7;
int SLEEP_TIME = 1000;

int isLightOn = FALSE;

void setup() {
  turnOffDevice(LIGHT_PIN);
  digitalWrite(LIGHT_PIN, LOW);
}

void turnOffDevice(int pin) {
  pinMode(pin, INPUT);
}

void turnOnDevice(int pin) {
  pinMode(pin, OUTPUT);
}

void loop()
{
  delay(SLEEP_TIME);
  if (isLightOn) {
    turnOffDevice(LIGHT_PIN);
    isLightOn = FALSE;
  } else {
    turnOnDevice(LIGHT_PIN);
    isLightOn = TRUE;
  }
}

A more exciting project with the light bulb and LDR in my next post.

When light bulb is off

When light bulb is on

Post a Comment