Relay Board with ZDev

This article is a follow-up of Relay Board, Getting Started article. In this article we are going to see how use Relay Board with the ZDev library.

Hardware Connectivity

  • ZKit-ARM-1343 board

  • Relay board

  • 12V power supply

/static/images/relay-connection.png
Figure 1. Relay board connection
  • The Relay Board provides 4 optically isolated relays. So we can control 4 external circuits by a low-power signal.

  • ZKit-ARM-1343 and Relay Board connected through DIO(Digital Input Output) port.

  • Connect 12V power supply to relay board.

Software

The DIO header and Relay board pin connectivity is shown below.

GPIO pins Relay

GPIO2_0

Relay 1

GPIO2_1

Relay 2

GPIO2_2

Relay 3

GPIO2_3

Relay 4

Following code will drive the 4 relays periodically on and off.

#include <board.h>
#include <gpio.h>
#include <delay.h>

int pin[] = {GPIO2_0, GPIO2_1, GPIO2_2, GPIO2_3};

void relay_init(void)
{
        int i;
        for (i = 0; i <= 3; i++) {
                gpio_enable_pin(pin[i]);
                gpio_direction_output(pin[i], 0);
        }
}

int main()
{
        int i;

        board_init();
        gpio_init();
        delay_init();
        relay_init();

        while (1) {
                for (i = 0; i <= 3; i++) {
                        gpio_set_pin(pin[i], 1);
                        mdelay(1000);
                        gpio_set_pin(pin[i], 0);
                        mdelay(1000);
                }
        }
}

/static/code/relay-zdev.c[Download the source file]

  • In relay_init(), the pins are configured for GPIO functionality, GPIOs direction is set to output.

  • In the infinite while loop in main(), all relay is continuously driven in periodic time.

Credits