Embrace smarter living with our cutting-edge smart thermostat that optimizes energy usage while keeping you cozy.
A
A
Hardware Overview
How does it work?
Thermostat 4 Click is based on the TMP392, a resistor-programmable temperature switch from Texas Instruments that enable protection and detection of system thermal events from 30°C to 130°C. The device powers on when the supply voltage goes beyond 1.5V, and starts sampling the input resistance to set the two trip points and hysteresis value after power-on. Trip point for channel A can be set manually using onboard trimmer while trip point for channel B is set using TPL0501 digital potentiometer with 256 wiper positions used as as a two-terminal rheostat. With end-to-end resistance of 100 kΩ internal registers of the TPL0501 can be accessed using a SPI interface. The position of the wiper (W) terminal is controlled by the value in the 8-bit Wiper Resistance (WR) register. When the WR register contains all zeroes (zero-scale), the wiper terminal is closest to its L terminal. As the value of the WR register increases from all zeroes to all ones
(full-scale), the wiper moves from the position closest to the L terminal, to the position closest to the H terminal. At the same time, the resistance between W and L increases, whereas the resistance between W and H decreases. The relay is activated by the host MCU. The voltage for the coil activation is 5V, while the current through the coil is 40mA. The MCU is not able to drive the coil directly, therefore an N-chanel FET had to be added. Its gate is controlled by the host MCU, allowing the coil to drain enough current from the 5V mikroBUS™ power rail. A red color LED, labeled as ACTIVE is used to indicate that the transistor is in an open state and that the current is running through the relay coil. When the current through a coil (or any other inductor) is suddenly changed, the backEMF will be generated, opposing the changes of the current. This can sometimes lead to damage to the control circuit: in this case, the transistor will become inversely polarized. To
prevent this from happening, a flyback diode is added across the coil. During the normal operation, this diode does not conduct any current. However, when the coil is switched OFF, the inverse polarization will cause the current to pass through this diode with minimum resistance. This prevents inverse (flyback) voltage from building up, so the transistor remains safe. The Click board™ is equipped with all the necessary elements, required to provide a reliable operation: it has a varistor across the relay output contacts, preventing excessive voltage transients, it has a flyback diode for the backEMF generated within the relay coil, and a durable mechanical relay, that can withstand up to 20,000,000 mechanical cycles (no load connected). These features allow Thermostat 4 click to be used for a wide range of applications that have to be thermally controlled: various home appliances, air conditioners, cooling fans, small heaters, and more.
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.
Microcontroller Overview
MCU Card / MCU
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.
Used MCU Pins
mikroBUS™ mapper
Take a closer look
Schematic
Step by step
Project assembly
Track your results in real time
Application Output via Debug Mode
1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.
2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.
Software Support
Library Description
This library contains API for Thermostat 4 Click driver.
Key functions:
thermostat4_hot_alert_state
- This function read state from OA pin.thermostat4_relay_ctrl
- This function write desired state on RLY pin.thermostat4_set_warm_hysteresis
- This function write hysteresis data.
Open Source
Code example
This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.
/*!
* @file
* @brief Thermostat4 Click example
*
* # Description
* Thermostat 4 Click reads alert on the warm and hot channel, using standard SPI communication.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes Driver init, Relay test and
* sets hysteresis on the WARM channel ( channel B ), after that starts uploading new data.
*
* ## Application Task
* Reads Alert on the WARM and HOT channel.
*
* @note
* The user has the option of adjusting the hysteresis for channel B via the SPI module
* while for channel A it is adjusted via the potentiometer.
*
* @author MikroE Team
*
*/
#include "board.h"
#include "log.h"
#include "thermostat4.h"
static thermostat4_t thermostat4;
static log_t logger;
void application_init ( void )
{
log_cfg_t log_cfg;
thermostat4_cfg_t thermostat4_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.
thermostat4_cfg_setup( &thermostat4_cfg );
THERMOSTAT4_MAP_MIKROBUS( thermostat4_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == thermostat4_init( &thermostat4, &thermostat4_cfg ) )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
log_printf( &logger, " RELAY ON\r\n" );
thermostat4_relay_ctrl( &thermostat4, THERMOSTAT4_RELAY_ON );
Delay_ms ( 1000 );
log_printf( &logger, " RELAY OFF\r\n" );
thermostat4_relay_ctrl( &thermostat4, THERMOSTAT4_RELAY_OFF );
Delay_ms ( 500 );
thermostat4_set_warm_hysteresis( &thermostat4, 0 );
thermostat4_new_cfg_upload( &thermostat4 );
log_info( &logger, " Application Task " );
}
void application_task ( void )
{
if ( THERMOSTAT4_HOT_ALERT == thermostat4_hot_alert_state( &thermostat4 ) )
{
log_printf( &logger, " HOT ALERT\r\n" );
thermostat4_relay_ctrl( &thermostat4, THERMOSTAT4_RELAY_ON );
}
else if ( THERMOSTAT4_WARM_ALERT == thermostat4_warm_alert_state( &thermostat4 ) )
{
log_printf( &logger, " WARM ALERT\r\n" );
thermostat4_relay_ctrl( &thermostat4, THERMOSTAT4_RELAY_ON );
}
else
{
log_printf( &logger, " TEMPERATURE OK\r\n" );
thermostat4_relay_ctrl( &thermostat4, THERMOSTAT4_RELAY_OFF );
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
}
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
/*!
* @file
* @brief Thermostat4 Click example
*
* # Description
* Thermostat 4 Click reads alert on the warm and hot channel, using standard SPI communication.
*
* The demo application is composed of two sections :
*
* ## Application Init
* Initializes Driver init, Relay test and
* sets hysteresis on the WARM channel ( channel B ), after that starts uploading new data.
*
* ## Application Task
* Reads Alert on the WARM and HOT channel.
*
* @note
* The user has the option of adjusting the hysteresis for channel B via the SPI module
* while for channel A it is adjusted via the potentiometer.
*
* @author MikroE Team
*
*/
#include "board.h"
#include "log.h"
#include "thermostat4.h"
static thermostat4_t thermostat4;
static log_t logger;
void application_init ( void )
{
log_cfg_t log_cfg;
thermostat4_cfg_t thermostat4_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.
thermostat4_cfg_setup( &thermostat4_cfg );
THERMOSTAT4_MAP_MIKROBUS( thermostat4_cfg, MIKROBUS_1 );
if ( SPI_MASTER_ERROR == thermostat4_init( &thermostat4, &thermostat4_cfg ) )
{
log_error( &logger, " Application Init Error. " );
log_info( &logger, " Please, run program again... " );
for ( ; ; );
}
log_printf( &logger, " RELAY ON\r\n" );
thermostat4_relay_ctrl( &thermostat4, THERMOSTAT4_RELAY_ON );
Delay_ms ( 1000 );
log_printf( &logger, " RELAY OFF\r\n" );
thermostat4_relay_ctrl( &thermostat4, THERMOSTAT4_RELAY_OFF );
Delay_ms ( 500 );
thermostat4_set_warm_hysteresis( &thermostat4, 0 );
thermostat4_new_cfg_upload( &thermostat4 );
log_info( &logger, " Application Task " );
}
void application_task ( void )
{
if ( THERMOSTAT4_HOT_ALERT == thermostat4_hot_alert_state( &thermostat4 ) )
{
log_printf( &logger, " HOT ALERT\r\n" );
thermostat4_relay_ctrl( &thermostat4, THERMOSTAT4_RELAY_ON );
}
else if ( THERMOSTAT4_WARM_ALERT == thermostat4_warm_alert_state( &thermostat4 ) )
{
log_printf( &logger, " WARM ALERT\r\n" );
thermostat4_relay_ctrl( &thermostat4, THERMOSTAT4_RELAY_ON );
}
else
{
log_printf( &logger, " TEMPERATURE OK\r\n" );
thermostat4_relay_ctrl( &thermostat4, THERMOSTAT4_RELAY_OFF );
}
Delay_ms ( 1000 );
Delay_ms ( 1000 );
}
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