This project uses the TLE493D magnetic sensor and the MAX32620FTHR for a portable home security system. You can monitor when windows, doors, or pretty much any open/close system's state change.
You will need to test both the magnetic sensor and the MAX32620FTHR microcontroller.
If you have the TLE493D 2GO kit, you can use the Arduino IDE to test your board: https://github.com/Infineon/TLE493D-W2B6-3DMagnetic-Sensor
When you view the serial monitor, you should expect values like the ones shown below depending on how you're printing them:
2.73 ; 2.73 ; 0.52
2.47 ; 2.73 ; 0.52
2.60 ; 2.86 ; 0.52
2.47 ; 2.47 ; 0.52
You should play around with the sensor separately to determine the ranges for when the magnet is near the sensor (closed state for the door/window) vs when the magnet is farther way. Depending on where you apply this, this will have different results.
For the MAX32620FTHR, you can find the Mbed page here. Try the blinky example as that will get you started and the board tested. Make sure you select the right board on the top right corner:
Sometimes you need to unplug and replug the microcontroller or hit the reset button to get something like this:
You can either try i2c by breaking off the magnetic sensor from the TLE493D board at the break line or use the UART pins on the XMC. The pinout for the TLE493D sensor is available here.
Here's the potential schematic for i2c (connect the MAX to a battery):
For the magnet sensor, you can read the values off Bx, By, or Bz. I suggest to use one of these registers and rely on that to figure out when your window/door is opened or closed. Here's the register diagram take from the manual:
Here's some example code that will blink the onboard led on the microcontroller:
#include "mbed.h"
I2C i2c(I2C1_SDA, I2C1_SCL);
DigitalOut myled(LED1, 1);
int main()
{
char buff[2];
float OPEN_STATE_THRESHOLD = 0.33; // Value that you find as open state
int magnetRegister = 0x01; // register you want to read from
for (;;) {
i2c.read(magnetRegister << 1, buff, 2);
float reading = float((buff[0]<<8)|buff[1]);
if (reading < OPEN_STATE_THRESHOLD) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
Thread::wait(1000);
}
}
Comments