Intermediate
30 min

Simplify complex control tasks with SRD-5VDC-SL-C and PIC18F57Q43

Silent, reliable, and efficient: The future of switching is here!

Relay 3 Click with Curiosity Nano with PIC18F57Q43

Published Feb 13, 2024

Click board™

Relay 3 Click

Dev. board

Curiosity Nano with PIC18F57Q43

Compiler

NECTO Studio

MCU

PIC18F57Q43

Enhance your automation and control projects with SPDT relays, perfect for managing complex switching scenarios with precision

A

A

Hardware Overview

How does it work?

Relay 3 Click is based on the SRD-05VDC-SL-C, a small-size relay from Songle Relays. These are reliable relays in a sealed plastic housing, offering good isolation. Despite its size, the SRD-05VDC-SL-C relay is able to withstand up to 7A and 220V AC/28V DC. It can endure up to 105 operations while loaded, and even up to 107 with no load applied. This relay is of a single-pole-double-throw type: when the coil is energized, it will attract the internal switching elements and close one of the contacts, while opening the other contact at the same time. Normally Closed contacts are usually labeled with NC, while Normally Open contacts are labeled as NO. These relays are designed so that their coils can be easily activated by relatively low currents and voltages. The SRD-05VDC-SL-C relay can be operated with 5V, making it a good choice for activating it by an MCU pin. However, to

provide sufficient current for the activation, an additional MOSFET has to be used. Gates of two MOSFETS (one for each relay) are controlled by the MCU pins, therefore are routed to the mikroBUS™. The gates are routed to RST and CS pins of the mikroBUS™ and are labeled as RE1 and RE2, respectively. There are two LEDs (yellow) which are used to indicate the activity state of the relay. When the current flows through the MOSFET, the coil will be energized, and the relay will be activated. This current also flows through these LEDs, indicating that the relay is active. The LEDs are labeled according to the relay they are connected to: REL1 for the Relay 1, and REL2 for the Relay 2. A Schottky diode is connected across the relay coil, preventing the back-EMF which can be generated because of the inert nature of the coil. The back EMF can have an adverse effect on

the circuit and can potentially damage the control circuit. The diode is connected in the inverse direction, allowing the back-EMF to discharge through the relay coil, instead. Each relay is equipped with the 3-pole screw terminal, rated for up to 6A. Therefore, the maximum current through the connected load should not exceed this value. However, as already mentioned above, high current negatively affects the life expectance of the relay itself, so switching large currents should be avoided. The middle pole of the screw terminal is connected to the common terminal of the relay (COM) while two other poles are the NC and NO contacts of the relay. Having both NC and NO contacts is useful, expanding the implementation possibilities of Relay 3 Click.

Relay 3 Click top side image
Relay 3 Click bottom side image

Features overview

Development board

PIC18F57Q43 Curiosity Nano evaluation kit is a cutting-edge hardware platform designed to evaluate microcontrollers within the PIC18-Q43 family. Central to its design is the inclusion of the powerful PIC18F57Q43 microcontroller (MCU), offering advanced functionalities and robust performance. Key features of this evaluation kit include a yellow user LED and a responsive

mechanical user switch, providing seamless interaction and testing. The provision for a 32.768kHz crystal footprint ensures precision timing capabilities. With an onboard debugger boasting a green power and status LED, programming and debugging become intuitive and efficient. Further enhancing its utility is the Virtual serial port (CDC) and a debug GPIO channel (DGI

GPIO), offering extensive connectivity options. Powered via USB, this kit boasts an adjustable target voltage feature facilitated by the MIC5353 LDO regulator, ensuring stable operation with an output voltage ranging from 1.8V to 5.1V, with a maximum output current of 500mA, subject to ambient temperature and voltage constraints.

PIC18F57Q43 Curiosity Nano double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

PIC

MCU Memory (KB)

128

Silicon Vendor

Microchip

Pin count

48

RAM (Bytes)

8196

You complete me!

Accessories

Curiosity Nano Base for Click boards is a versatile hardware extension platform created to streamline the integration between Curiosity Nano kits and extension boards, tailored explicitly for the mikroBUS™-standardized Click boards and Xplained Pro extension boards. This innovative base board (shield) offers seamless connectivity and expansion possibilities, simplifying experimentation and development. Key features include USB power compatibility from the Curiosity Nano kit, alongside an alternative external power input option for enhanced flexibility. The onboard Li-Ion/LiPo charger and management circuit ensure smooth operation for battery-powered applications, simplifying usage and management. Moreover, the base incorporates a fixed 3.3V PSU dedicated to target and mikroBUS™ power rails, alongside a fixed 5.0V boost converter catering to 5V power rails of mikroBUS™ sockets, providing stable power delivery for various connected devices.

Curiosity Nano Base for Click boards accessories 1 image

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
Relay 1 Control
PA7
RST
Relay 2 Control
PD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
NC
NC
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Click board™ Schematic

Relay 3 Click Schematic schematic

Step by step

Project assembly

Curiosity Nano Base for Click boards front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Curiosity Nano with PIC18F57Q43 as your development board.

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Curiosity Nano with PICXXX Access MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
PIC18F57Q43 Curiosity MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for Relay 3 Click driver.

Key functions:

  • relay3_relay_on - This function turns on either the 1st or the 2nd relay on the click.

  • relay3_relay_off - This function turns off either the 1st or the 2nd relay on the click.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file 
 * \brief Relay 3 Click example
 * 
 * # Description
 * This example starts off with the initialization and configuration of the click and logger
 * modules and later on showcases how to turn specified relays ON/OFF using the output pins. 
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * This function initialises and configures the logger and click modules.
 * 
 * ## Application Task  
 * This function turns on the 1st and the 2nd relay and then turns them both off.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "relay3.h"

// ------------------------------------------------------------------ VARIABLES

static relay3_t relay3;
static log_t logger;

static int case1_switch = 0;
static int case2_switch = 0;
static int case3_switch = 0;

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

static void case_1 ( )
{
    if ( case1_switch == 0 )
    {
        relay3_relay_on( &relay3, RELAY3_RELAY_1 );
        log_printf( &logger, "   Relay_1 ON.   \r\n" );

        case1_switch++;
    }
    else if ( case1_switch == 1 )
    {
        relay3_relay_off( &relay3, RELAY3_RELAY_1 );
        log_printf( &logger, "   Relay_1 OFF.   \r\n" );

        case1_switch--;
    }
}

static void case_2 ( )
{
    if ( case2_switch == 0 )
    {
        relay3_relay_on( &relay3, RELAY3_RELAY_2 );
        log_printf( &logger, "   Relay_2 ON.   \r\n" );
        
        case2_switch++;
    }
    else if ( case2_switch == 1 )
    {
        relay3_relay_off( &relay3, RELAY3_RELAY_2 );
        log_printf( &logger, "   Relay_2 OFF.   \r\n" );

        case2_switch--;
    }
}

static void case_3 ( ) 
{
    if ( case3_switch == 0 )
    {
        relay3_relay_on( &relay3, RELAY3_BOTH_RELAYS );
        log_printf( &logger, "   Both relays ON.   \r\n" );

        case3_switch++;
    }
    else if ( case3_switch == 1 )
    {
        relay3_relay_off( &relay3, RELAY3_BOTH_RELAYS );
        log_printf( &logger, "   Both relays OFF.   \r\n" );

        case3_switch--;
    }
}

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( )
{
    log_cfg_t log_cfg;
    relay3_cfg_t cfg;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info(&logger, "---- Application Init ----");

    //  Click initialization.

    relay3_cfg_setup( &cfg );
    RELAY3_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    relay3_init( &relay3, &cfg );
}

void application_task ( )
{
    case_1( );
    Delay_ms( 1000 );

    case_2( );
    Delay_ms( 1000 );

    case_3( );
    Delay_ms( 1000 );
}

void main ( )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.