element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Design For A Cause 2021
  • Challenges & Projects
  • Design Challenges
  • Design For A Cause 2021
  • More
  • Cancel
Design For A Cause 2021
Blog VenTTracker #02 -  Analyzing window types.
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: javagoza
  • Date Created: 14 Mar 2021 8:02 PM Date Created
  • Views 2102 views
  • Likes 5 likes
  • Comments 3 comments
  • arduino iot
  • home automation
  • venttracker
  • iot system
  • school
  • stem education
  • design for a cause
  • arduino nano 33 iot
Related
Recommended

VenTTracker #02 -  Analyzing window types.

javagoza
javagoza
14 Mar 2021

During this week I have been looking for information on how windows work and what types are there and what strategies I can follow to know if a window is open or closed and how open it is.

VenTTracker's goal is to monitor natural ventilation routines. The design of the window has an impact on the effect of natural ventilation and also on the strategies to follow to know the state of the window.

The blog contains a summary of the types of windows and ideas to investigate to find out if the windows and doors are open and how open they are.

Many ideas in my head really wanting to try things. It's time to focus and not get too distracted.image

 

image

  Design for A Cause 2021 the VenTTracker project

  01 - Intro and motivation. | 02 - Analyzing Window Types (I) | 03 - Analyzing Window Types (II) | 04 - Playing with the IMU | 05-Sliding Window Mock-up | 06 -  Window Sensor Prototype | 07 - Adjusting the window sensor | 08 - Trying to make a measuring device with the accelerometer | 09 - Checking and updating WiFiNINA Firmware | 10 - Ventilation Monitor on Arduino IoT Cloud | 11 - Wireless Environmental Monitor on Arduino Nano 33 IoT | 12 - Window Anomaly Detection. Edge Impulse & Arduino Nano 33 IoT | 14 - Environmental Monitor Revisited - Version 2 | 13 - Project wrap-up and Lessons learned

 

Tracking System for Classroom Ventilation Routines

A STEM project for classrooms

 

the VenTTracker project - Blog #02 - Analyzing Window Types

 

imageimageimage

 

Common Terms and Window Types

Common terms

  • Operable vs. fixed. Windows that open are operable, while windows that do not open are fixed
  • Panes. A pane is a sheet of glass.
  • Sashes. The sash refers to a pane framed horizontally by rails and vertically by stiles. A window sash is the part of the window that you move when you want to open and close the window.
  • Glazing. This term may refer to the part of the window that's made of glass or the process used to secure the glass into a window frame.

 

Windows types

image

  • a. Fixed windows: are windows with a fixed frame that cannot be opened. The lack of window stiles and rails makes for a narrow frame and wide opening that lets in significantly more natural light.
  • b. Single-hung windows: feature a single movable sash, raised from the bottom for ventilation, while the top stays stationary.
  • c. Double-Hung windows: have two operating sash that move up and down allowing for ventilation on the top, bottom or both.
  • d. Sliding windows: glide open horizontally from one side, providing easy access to fresh air.
  • e. Casement windows: are windows that is attached to its frame by one or more hinges at the side. They are used singly or in pairs within a common frame, in which case they are hinged on the outside. Casement windows are often held open using a casement stay.
  • f. Awning windows: are hinged on the top and open outward from the bottom, allowing for ventilation and protection from the rain. Often placed higher on walls for privacy or in combination with large stationary windows for a better view.
  • g. Hopper window: is a small window that opens downward and inward. It is commonly installed as a bathroom or basement window. The upward tilt of the window glass pane blocks open dirt and debris from getting into your home. It usually can be opened with a crank or hinge.
  • h. Vertical Pivot Windows: windows having a sash which pivots about a vertical axis at or near its center; when opened, the outside glass surface is conveniently accessible for cleaning.
  • i. Horizontal pivot Window: The windows mechanism used allows the window to open both inwards and outwards to enable customers to benefit from optimum ventilation and light without compromising on security and heat conservation.

 

Measurement of door / window / shutter / blind opening ratios

 

For simplicity we are going to summarize the types of movements of door, window blind and shutter in two cases:

 

 

Sliding: Those doors, windows, shutters and blinds that slide: Single-hung, Double-hung and Sliding.

The moveable panels of sliding windows travel on rollers inside the bottom of the panels.

Horizontal slider: Consist of two sashes resting on rails that move left or right.

image

image

 

Pivoting: Those doors, windows, shutters and blinds that tilt on a pivot or hinge.

 

Casement: They open pivoting on a fixed axis, using the fittings located on one of the sides of the sash.

 

 

 

Problems to solve

The main problem is to know the actual state of the door, window, shutter or blind.

We are going to split the problem in three problems:

  1. Are the moving parts open or closed?
  2. How open are the moving parts?
  3. How to detect events as moving part changing state.

 

Is it the window open?

This is the simple part. We can use a plunger that activates a switch like in automatic door seals or something simpler like a reed sensor and magnet.

Our device can be on the moving part of the window, on the fixed part. If we are only concerned with whether the window is open or closed, as in an intrusion alarm, the fixed part is a good place for the device and the magnet would go in the moving part.

 

Device on window moving part:

image

Device on window fixed part

image

 

 

How open is the moving part?

 

For parts that slide, we need to know the amount of scrolling in the scroll direction to know how open it is.

For parts that tilt we need to know the tilt angle to know how open they are.

 

We define the open window opening ratio as the current opening percentage of the moving part, can be:

  • a percentage of the total sliding length of the moving part,
  • or a percentage of the maximum opening angle of the moving part .

 

As we don´t need to have precise measures but a ratio of the opening lets label our target opening ratios:

  • Completely closed: open ratio  = 0%
  • Almost closed: 0 % < open ratio < 33%
  • Semi-open 33% <= open ratio < 66%
  • Fully open 66% <= open ratio < 100%

 

Strategies for knowing  the moving part opening ratio.

 

My initial intention is to take advantage of the IMU chip included in the Arduino NANO 33 IoT development board to estimate the opening angle of the pivot, casement, and tilt-and-turn windows and the displacement of the sliding parts.

I know that I will not be able to obtain a precise measurement but I want to explore how far I can take advantage of the IMU.

Knowing if the moving part is in closed state will give us zero reference for our estimates.

 

In the strategies based on the accelerometer and / or on the gyroscope, the device must be on the moving part of the window in order to be able to detect the changes.

 

Let's explore some possible solutions. I will avoid those solutions that involve mechanical contact or modification of the structure of the window, door, blind or shutter to be monitored, as a linear resistive position sensor or a rotary encoder and a wheel.

 

Strategies for sliding parts:

 

  • Accelerometer and reckoning algorithm for positioning
  • A quadrature encoder made by two reed switches, or two hall sensors, aligned and several strategically placed magnets.
  • Machine Learning??? Use TinyML to teach the device to classify different degrees of opening. Very open, semi-open, semi-closed, closed. Makes sense?

 

Strategies for pivoting parts:

  • Accelerometer and gyroscope for window orientation, opening angle. Maybe with the aid of a complementary filter or a Kalman filter.
  • Machine Learning??? Use TinyML to teach the device to classify different degrees of opening. Very open, semi-open, semi-closed, closed. Makes sense?

 

 

Can we use the accelerometer to determine the position of the moving part in the situations with sliding displacement?

 

Let's take samo data to see how the LSM6D3 accelerometer responds to left and right displacements

 

image

The IMU is located near the USB connector.

image

 

The circuit model. Use a breadboard to hold the arduino aligned with a ruler and connect via USB port to capture data with a serial port monitor.

image

 

Arduino sketch to capture data. Uses SparkFunLSM6DS3 library.

 

#include <SparkFunLSM6DS3.h>

#define FREQUENCY_HZ 100
#define INTERVAL_MS (1000 / (FREQUENCY_HZ + 1))

signed long imuGetAccX();
void calibrateImu(void);
void setupIMU();

LSM6DS3Core myIMU(I2C_MODE, 0x6A);

signed long sstatex, sstatey;

void setup() {
  Serial.begin(115200);
  delay(1000); // relax...
  Serial.println("Started");
  setupIMU();
  calibrateImu();
}
void loop() {
  static unsigned long lastIntervalMs = 0;
  if (millis() > lastIntervalMs + INTERVAL_MS) {
    lastIntervalMs = millis();
    signed long sampleX = imuGetAccX();
    Serial.println(sampleX - sstatex);
  }
}
signed long imuGetAccX() {
  int16_t temp;
  myIMU.readRegisterInt16(&temp, LSM6DS3_ACC_GYRO_OUTX_L_XL) ;
  return temp;
}
void calibrateImu(void) {
  unsigned int count1;
  count1 = 0;
  do {
    signed long sampleX = imuGetAccX();
    sstatex = sstatex + sampleX; // Accumulate Samples
    count1++;
  } while (count1 != 0x0400); // 1024 times
  sstatex = sstatex >> 10;    // division between 1024
}
void setupIMU() {
  if (myIMU.beginCore() != 0) {
    Serial.print("Error at beginCore().\n");
  } 
  uint8_t dataToWrite = 0; // Temporary variable
  //Setup the accelerometer******************************
  dataToWrite = 0; // Start Fresh!
  dataToWrite |= LSM6DS3_ACC_GYRO_BW_XL_100Hz;
  dataToWrite |= LSM6DS3_ACC_GYRO_FS_XL_2g;
  dataToWrite |= LSM6DS3_ACC_GYRO_ODR_XL_104Hz;
  // Now, write the patched together data
  myIMU.writeRegister(LSM6DS3_ACC_GYRO_CTRL1_XL, dataToWrite);
  // Set the ODR bit
  myIMU.readRegister(&dataToWrite, LSM6DS3_ACC_GYRO_CTRL4_C);
  dataToWrite &= ~((uint8_t)LSM6DS3_ACC_GYRO_BW_SCAL_ODR_ENABLED);
}

 

Moving the device to the left.

 

image

 

First the acceleration on the x-axis is positive and its absolute value increases with time. The velocity of the part is also positive and its absolute increases with time. The moving part moves to the left.

Then the acceleration decreases and changes sign braking the device until the speed becomes zero and the device stops.

 

Moving the device to the right

image

First the acceleration on the x-axis is negative and its absolute value increases with time. The velocity of the part is also negative and its absolute value increases with time. The moving part moves to the right.

Then the acceleration increases and changes sign braking the device until the speed becomes zero and the device stops.

 

Some clarification about the sketch

What is doing calibrateImu() method?

A 'no movement' state is critical to obtain correct data. A calibration routine is needed at the beginning of the application. This calibration value must be as accurate as possible.

 

void calibrateImu(void) {
  unsigned int count1;
  count1 = 0;
  do {
    signed long sampleX = imuGetAccX();
    sstatex = sstatex + sampleX; // Accumulate Samples
    count1++;
  } while (count1 != 0x0400); // 1024 times
  sstatex = sstatex >> 10;    // division between 1024
}

 

The force of gravity is always influencing the measured acceleration. Therefore, to measure the real acceleration of the device, the contribution of the force of gravity must be removed from the accelerometer data. This can be achieved by applying a high-pass filter.

 

calibrateImu method obtains the x component of the acceleration when there is a no movement condition.

If the module is perfectly parallel to the earth's surface, the calibration value should be very close to 0.

 

Let's check the influence of the gravity for the board plane, x and y axes

 

Reading data in no movement condition

AX AY AZ

0.040410000 0.018800000 1.008420000

0.041020000 0.019650000 1.007320000

0.041380000 0.020750000 1.008420000

0.041990000 0.019650000 1.006840000

0.041630000 0.020750000 1.007810000

 

image

 

The accelerometer at resting on a table, it measure s 1G ( 9.81 m/s2) for the z-axis straight upwards.

 

The need for calibration is clear. The calibration will remove the acceleration offset component in the sensor output due to the earth's gravity (static acceleration).

 

Let's see the effect of the calibration. Make a new sketch the same as calibrateImu but for the two axes and with the Arduino LSM6DS3 library

The Arduino library is easier to use but lacks many of the methods needed to get more out of the IMU.

 

void calibrate(void)
{
  uint32_t count1 = 0;
  float samplex = 0;
  float sampley = 0;
  float samplez = 0;
  do {
    if (IMU.accelerationAvailable()) {
      IMU.readAcceleration(samplex, sampley, samplez);
      staticx += samplex;              // Accumulate Samples
      staticy += sampley;
      count1++;
    }
  } while (count1 < 10000);                  // 10 000 times
  staticx = staticx / 10000.0;               // mean value
  staticy = staticy / 10000.0;
}

 

The calibration routine averages samples when the accelerometer is in a no movement condition. The more samples that are taken, the more accurate the calibration results will be.

 

After applying the high pass filter, we simply subtract the values obtained during the calibration process. Notice that we are only applying the filter to x and y acceleration components.

 

image

 

After calibrating our values  have been improved getting rid of earth's gravity but we can still see errors due to vibration and noise.

The real value of the acceleration is the sample minus the calibration value; it can be either positive or negative.

 

 

How can we obtain the velocity and the position from the accelerometer data?

 

Acceleration is the rate of change in the velocity of an object.

Velocity is the rate of change in the position of that same object.

In math we say that velocity is the derivative of position and acceleration is the derivative of velocity, like this:

 

  a=ddt v   and  v=ddt x

 

Integration is the opposite of the derivative. If the acceleration of an object is known, we can obtain the position data by applying a double integration (assuming that the initial conditions are zero):

 

v=∫aba(t)dt+v0    x=∫abv(t)dt =  ∫ab∫aba(t)dt

 

The integral computes the area below the curve, where the integration is the sum of very small areas whose width is almost zero.

In other words, the sum of the integration represents the magnitude of a physical variable.

 

Let makes some numbers to see how this work.

Sampling a signal gives us instantaneous values of its magnitude, so small areas can be created between two samples. This method introduces errors

 

velX(t)=velX(t−1)+a(t)·△t

 

PosX(t)=PosX(t−1)+v(t).△t

 

For this method to be correct, the time increment between samples would have to be zero. To reduce the error a bit we can divide the rectangular area into another rectangle and a triangle. The good news is that we can reduce the error by increasing the sampling frequency, but the bad news is that the velocity error accumulates and what is worse the position error increases quadratically.

 

velX(t)=velX(t−1)+(a(t−1)+a(t)−a(t−1)2 )×△t

 

posX(t)=posX(t−1)+(v(t−1)+v(t)−v(t−1)2 )×△t

 

 

image

Let's see what it looks like.

 

Moving the device to the left:

image

Moving the device to the right:

image

How to obtain movement direction

Average velocity < 0 going to the right

Average velocity >0 going to the left

Velocity = 0 stopped

 

Using a quadrature encoder to determine the position of the moving part in the situations with sliding displacement

Encoders

An encoder is a sensor which turns a position into an electronic signal. There are two forms: Absolute encoders give an absolute position value. Incremental encoders count movement rather than position.

With detection of a datum position and the use of a counter, an absolute position may be derived.

 

What is a quadrature encoder?

A quadrature encoder is an incremental encoder with 2 out-of-phase output channels used in many general automation applications where sensing the direction of movement is required. Each channel provides a specific number of equally spaced pulses per revolution (PPR) and the direction of motion is detected by the phase relationship of one channel leading or trailing the other channel.

 

The idea is very intuitive and when I came up with it, I didn't even know that they were called this way.

These blogs from element14 masters are a good introduction to understanding how it works.

  • The Logical Project by dougw
  • Rotary Encoders - Part 5: Capturing Input on an FPGA  by Jan Cumps

 

Making a custom magnetic encoder for sliding windows.

 

We can make a quadrature encoder with two magnetic sensor to detect the out-phase and another one for detecting closed and open state.

But we are trying to do the same thing with only two reed sensors.

 

Let's try to design a quadrature encoder with open close detection.

 

image

The first two magnets are close enough to have the two magnetic sensors in phase so we can detect the open closed state, after that after the sensor 1 detects the second magnet the quadrature encoder will start.

 

In this case, the device can be located both on the mobile part and on the fixed part.

 

image

 

The encoder in action

When closed both switches are closed.

After switch 1 transitions from off to on without a switch 2 transition, the quadrature encoder is activated.

 

image

 

Timing diagrams

 

image

image

Breadboard diagram for testing.

The two push button switches in parallel with the reed sensors will allow us to simulate the transitions without the magnets.

 

image

 

Designing a model to make tests

I start to need a model to carry out the tests in a controlled environment.

I am going to have to design a wooden model to simulate sliding windows.

It should have

  • a single degree of freedom,
  • simulate small vibrations,
  • have friction similar to a sliding window
  • and some rollers to facilitate movement
  • a surface where the device and / or magnets can be placed both on the fixed part and on the mobile part, enough to place a medium-sized breadboard

 

image

 

Next steps

  • Continue with the study of the windows, strategies for the measurements in the pivoting parts.
  • Design and build a mockup to simulate the behavior with the sliding parts.
  • Design and build a mockup to simulate the behavior with the pivoting parts.
  • Investigate what ML can contribute to our goals.
  • Create a game to get familiar with the accelerometer and have fun along the way.

 

VenTTracker Blogs
VenTTracker #01 - Intro and motivation.
VenTTracker #02 - Analyzing window types.
VenTTracker #03 - Analyzing window types II
VenTTracker #04 - Playing with the IMU
VenTTracker #05 - Sliding Window Mock-up
VenTTracker #06 - Window Sensor Prototype
VenTTracker #07 - Adjusting the window sensor
VenTTracker #08 - Trying to make a measuring device with the accelerometer
VenTTracker #09 - Checking and updating WiFiNINA Firmware
VenTTracker #10 - Ventilation Monitor on Arduino IoT Cloud
VenTTracker #11 - Wireless Environmental Monitor on Arduino Nano 33 IoT
VenTTracker #12 - Window Anomaly Detection. Edge Impulse & Arduino Nano 33 IoT
VenTTracker #14 (aka #11 bis) - Environmental Monitor Revisited - Version 2
VenTTracker #13 - Project wrap-up and Lessons learned

 

<< Previous VenTTracker BlogNext VenTTracker Blog  >>
VenTTracker #01 - Intro and motivation.VenTTracker #03 -  Analyzing window types II
  • Sign in to reply

Top Comments

  • aspork42
    aspork42 over 4 years ago +1
    This is pretty slick. A custom, low resolution encoder. It’ll be inexpensive and work.
  • aspork42
    aspork42 over 4 years ago in reply to javagoza +1
    You could do a hardware debounce with R/C filter or Schmitt trigger; or just software debounce. Signal must maintain for ~20ms before considered valid.
  • aspork42
    aspork42 over 4 years ago in reply to javagoza

    You could do a hardware debounce with R/C filter or Schmitt trigger; or just software debounce. Signal must maintain for ~20ms before considered valid.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • javagoza
    javagoza over 4 years ago in reply to aspork42

    Thanks aspork42

    That's the idea. Have an inexpensive design so that students can experiment in the classroom easily. I had considered other options such as hall sensors or magnetoresistive sensors that might be good to use in a commercial version of the detector.

     

    I have had to modify the design that is in this blog because it does not detect transactions well. The reed switch sensors that I am using respond differently from each other and in the position that I thought would work better it does not work. In the next blog I will tell you how I have solved it. VenTTracker #03 -  Analyzing window types II

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • aspork42
    aspork42 over 4 years ago

    This is pretty slick. A custom, low resolution encoder. It’ll be inexpensive and work.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube