This repository provides an MPLAB® X project that showcases a smart retractable roof application. The project uses the MTCH9010 Evaluation Kit for rain detection and the Stepper Driver Reference Design Board featuring the AVR16EB32 MCU to extend or retract the roof. The application uses a customised version of this code example to drive the stepper motor and an AVR®-adapted version of this code example for MTCH9010 configuration. It is recommended to review these examples before moving forward with the application featured on this page.
The Stepper Driver Reference Design is based on the Multiphase Power Board.
- MTCH9010 Product Page
- MTCH9010 Data Sheet
- MTCH9010 Evaluation Kit
- MTCH9010 Evaluation Kit User Guide
- Getting Started with the MTCH9010 Evaluation Kit
- MTCH9010 Code Examples on GitHub
- MTCH9010 Resources on MPLAB Discover
- AVR EB Product Page
- AVR16EB32 Product Page
- AVR16EB32 Data Sheet
- AVR16EB32 Code Examples on GitHub
- AVR16EB32 Resources on MPLAB Discover
- AVR16EB32 Stepper Example Code on GitHub
- Stepper Driver Reference Design
- MPLAB X IDE v6.25 or newer
- MPLAB® XC8 v3.00 or newer
- AVR-Ex DFP v2.11.221 or newer
- MPLAB Code Configurator (MCC) v5.6.2 or newer
-
NEMA 17 Bipolar Stepper Motor (such as XY42STH34-035A)
-
Power Supply (12-24V nominal and 1-3A current capability, depending on the chosen motor)
-
Linear Guide Assembly
-
Frame (wood/metal)
-
Tarp (waterproof)
-
Mechanical endstop switches
To program the MCU with this MPLAB X project, follow the steps provided in the How to Program the Microcontroller section.
The Stepper Driver Board featuring the AVR16EB32 MCU is used as the host for the MTCH9010 Liquid Detector. The power supply is set to 24V and the motor is driven in Half-Step mode. The MTCH9010 is operating in Capacitive mode and Enhanced Configuration is enabled. At start-up, the host MCU sends the configuration parameters to the MTCH9010 via USART. The reference value (600) is set based on the dry-state sensor measurement and setup (sensor wires length) at normal room temperature and humidity. The threshold value (50) is set based on the sensor reading when a single water droplet is present on it. After the configuration sequence has ended, the host MCU monitors the state of the DETECT signal provided by the MTCH9010. When water (rain) is present on the sensor, the DETECT signal transitions to logic-high and the host MCU initiates the clockwise driving sequence for the stepper motor, extending the roof (tarp). If no liquid is present on the sensor, the DETECT signal transitions to logic-low and the MCU initiates the counter-clockwise driving sequence, retracting the roof. Two mechanical endstop switches are used to determine if the roof is completely extended or retracted. The motor is stopped as soon as either of the switches is activated.
The Stepper Driver Board also features two push buttons. The first button (SW1) allows the user to switch control of the system between the MTCH9010 and manual control using the second button (SW2). A short press on SW1 will switch the control to Manual mode while a long press will allow the MTCH9010 to take control of the system. In Manual mode, a short press on SW2 will initiate a clockwise driving sequence, extending the roof and a long press will initiate a counter-clockwise driving sequence, retracting the roof. The driving sequence can be interrupted at any time by another short press on SW2.
MTCH9010 Evaluation Kit settings:
- LOCK: OFF
- ECFG: ON
- USB Bridge: OFF
Note: In Enhanced Configuration mode, the slide switches for OUTPUT, MODE and Sleep Period are bypassed, as these parameters are configured through serial communication.
Note: When powering the board externally through the I/O header (top left corner of the board), the jumper cap on the power header (bottom left corner of the board) must be removed to prevent potential damage to the board.
AVR16EB32 MCC settings:
Photo of the complete assembly, front side:
Photo of the complete assembly, back side:
Photo of the mounting bracket:
Close-up of the MTCH9010 Evaluation Kit next to the stepper motor:
Close-up of the Stepper Driver Board:
Close-up of the liquid detection sensors:
The project shows how to create a smart roof application using the AVR16EB32 MCU and MTCH9010 Liquid Detector.
This chapter demonstrates how to use the MPLAB X IDE to program an AVR device with an Example_Project.X. This is applicable to other projects, too.
-
Connect the board to the PC.
-
Open the
Example_Project.X
project in MPLAB X IDE. -
Set the
Example_Project.X
project as main project.
Right click the project in the Projects tab and click Set as Main Project. -
Clean and build the
Example_Project.X
project.
Right click theExample_Project.X
project and select Clean and Build. -
Select PICkit 5 in the Connected Hardware Tool section of the project settings:
Right click the project and click Properties.
Click the arrow under the Connected Hardware Tool.
Select PICkit 5 (click SN), click Apply and then click OK:
Note: Other PICkit versions can be used as well. -
Program the project to the board.
Right click the project and click Make and Program Device.