Elevate your systems and devices with our magnetic field-activated dual-relay solution, offering seamless control and efficiency in a connected world
A
A
Hardware Overview
How does it work?
Hall Switch 2 Click is based on the MHA100KN, a high-performance, low-power Hall-Effect sensor from MEMSIC. This Click board™ detects the presence and magnitude of a magnetic field using the Hall effect. It consists of two high-quality relays, which the MHA100KN activates. When the north pole magnetic field is introduced to the sensor, one of the relays will be activated; otherwise, the other relay will be activated. The outputs of the MHA100KN are routed to the LM358 operational amplifier, which works as the inverting comparator. When the output of the MHA100KN is activated and pulled to a low logic level, the output from the comparator will be set to 5V,
which will cause biasing of the BJTs, allowing current flow through the relay coil and thus forming a magnetic field necessary for closing the relay contacts. A Schottky diode across the relay coils prevents the reverse kickback voltage, which forms due to the inert nature of the coils. Hall Switch 2 Click communicates with MCU using two GPIO pins labeled S and N. The north pole output is routed to the CS pin, while the south pole output is routed to the INT pin of the mikroBUS™ socket so that the MCU can monitor the status of the MHA100KN. Activation of the relay coils is also visually indicated by the yellow and red LEDs, respectively. Two varistors, VR1 and VR2,
prevent voltage peaks when the load is connected or disconnected on the relay output contacts. However, the relays allow up to 5A for 250VAC / 30VDC, so the connected load should be at most of these power ratings. This Click board™ can operate with either 3.3V or 5V logic voltage levels selected via the VCC SEL jumper. This way, both 3.3V and 5V capable MCUs can use the communication lines properly. Also, this Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used as a reference for further development.
Features overview
Development board
Clicker 2 for PIC32MX is a compact starter development board that brings the flexibility of add-on Click boards™ to your favorite microcontroller, making it a perfect starter kit for implementing your ideas. It comes with an onboard 32-bit MIPS M4K core PIC32 microcontroller, the PIC32MX460F512L from Microchip, two mikroBUS™ sockets for Click board™ connectivity, a USB connector, LED indicators, buttons, a mikroProg programmer connector, and two 26-pin headers for interfacing with external electronics. Its compact design with clear and easily recognizable silkscreen markings allows you to build gadgets with unique functionalities and features quickly. Each part of
the Clicker 2 for PIC32MX development kit contains the components necessary for the most efficient operation of the same board. In addition to the possibility of choosing the Clicker 2 for PIC32MX programming method, using a USB HID mikroBootloader, an external mikroProg connector for PIC32MX programmer, or through an external ICD2/3 programmer, the Clicker 2 board also includes a clean and regulated power supply module for the development kit. It provides two ways of board-powering; through the USB Mini-B cable, where onboard voltage regulators provide the appropriate voltage levels to each component on the board or using a Li-Polymer battery via an
onboard battery connector. All communication methods that mikroBUS™ itself supports are on this board, including the well-established mikroBUS™ socket, reset button, and several user-configurable buttons and LED indicators. Clicker 2 for PIC32MX is an integral part of the Mikroe ecosystem, allowing you to create a new application in minutes. Natively supported by Mikroe software tools, it covers many aspects of prototyping thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.
Microcontroller Overview
MCU Card / MCU

Architecture
PIC32
MCU Memory (KB)
512
Silicon Vendor
Microchip
Pin count
100
RAM (Bytes)
32768
Used MCU Pins
mikroBUS™ mapper
Take a closer look
Click board™ Schematic

Step by step
Project 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 Hall Switch 2 Click driver.
Key functions:
hallswitch2_check_state
- This function checks the S and N pin states, which indicates a magnetic field poles
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 main.c
* @brief Hall Switch 2 Click Example.
*
* # Description
* This example demonstrates the use of Hall Switch 2 Click board.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes the driver and logger and makes an initial log.
*
* ## Application Task
* Displays the corresponding message on the USB UART based on the switches state,
* i.e. based on the magnetic field presence.
*
* @author Stefan Filipovic
*
*/
#include "board.h"
#include "log.h"
#include "hallswitch2.h"
static hallswitch2_t hallswitch2; /**< Hall Switch 2 Click driver object. */
static log_t logger; /**< Logger object. */
static uint8_t print_state = 0xFF; /**< Starting case, any number above 2 should be good for our example. */
void application_init ( void )
{
log_cfg_t log_cfg; /**< Logger config object. */
hallswitch2_cfg_t hallswitch2_cfg; /**< Click config object. */
/**
* 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 );
Delay_ms ( 100 );
log_info( &logger, " Application Init " );
// Click initialization.
hallswitch2_cfg_setup( &hallswitch2_cfg );
HALLSWITCH2_MAP_MIKROBUS( hallswitch2_cfg, MIKROBUS_1 );
if ( hallswitch2_init( &hallswitch2, &hallswitch2_cfg ) == DIGITAL_OUT_UNSUPPORTED_PIN )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
log_info( &logger, " Application Task " );
}
void application_task ( void )
{
switch ( hallswitch2_check_state( &hallswitch2 ) )
{
case HALLSWITCH2_NO_MAGNET_DETECTED:
{
if ( HALLSWITCH2_NO_MAGNET_DETECTED != print_state )
{
log_printf( &logger, " No magnet detected\r\n" );
log_printf( &logger, " Switches - disabled\r\n\r\n" );
print_state = HALLSWITCH2_NO_MAGNET_DETECTED;
}
break;
}
case HALLSWITCH2_S_POLE_DETECTED:
{
if ( HALLSWITCH2_S_POLE_DETECTED != print_state )
{
log_printf( &logger, " South pole detected\r\n" );
log_printf( &logger, " Switch 1 - enabled\r\n\r\n" );
print_state = HALLSWITCH2_S_POLE_DETECTED;
}
break;
}
case HALLSWITCH2_N_POLE_DETECTED:
{
if ( HALLSWITCH2_N_POLE_DETECTED != print_state )
{
log_printf( &logger, " North pole detected\r\n" );
log_printf( &logger, " Switch 2 - enabled\r\n\r\n" );
print_state = HALLSWITCH2_N_POLE_DETECTED;
}
break;
}
default:
{
break;
}
}
}
int main ( void )
{
/* Do not remove this line or clock might not be set correctly. */
#ifdef PREINIT_SUPPORTED
preinit();
#endif
application_init( );
for ( ; ; )
{
application_task( );
}
return 0;
}
// ------------------------------------------------------------------------ END