Page 1 of 1
AHT21 & ENS160 Temperature, humidity and air quality
Posted: Sun May 04, 2025 11:56 am
by mnfisher
Someone asked about this addon board a while ago.
I got one of them - and thought to make a component. To start (and not a component yet) - the AHT21.
This could use the AHT10 component - and I went it alone for a few reasons.. Mostly I like to understand the device by some low level work (but that's probably just me).
There are also a couple of issues with the AHT10 component - it uses floating point. Here we have the choice (and not using fp saves about 1k on an Arduino)
The component can (theoretically) lock up in a couple of places - it's unlikely, but you wouldn't want your car to fail because it can't read the outside temperature.
It doesn't allow for the CRC check - nor do most of the libraries out there - but in the sake of completeness
So - stage 1) Can read temp and humidity!
Martin
Re: AHT21 & ENS160 Temperature, humidity and air quality
Posted: Mon May 05, 2025 10:33 pm
by mnfisher
I managed to get the ENS160 working too.
Still not a component - any suggestions as to better naming conventions?
This reads the temp / humidity and sets the compensation for the ens160. It then enters a loop displaying AQI (Air Quality), TVOC (Volatile organic particles), CO2, Temp and humidity - using the ens160's data ready interrupt (this generates samples every 1s)
I'd wired the board over the interrupt pins on my Arduino - so I just busy wait on a pin (in properties - I used pin 12) going to 0 - which isn't ideal but works as a test. Figures look sensible
It is also possible to test the integrity of the ENS160 data (using a CRC) - but I haven't looked into this yet.
The board I have is
https://www.amazon.co.uk/dp/B0DLVDTY9D
Martin
Re: AHT21 & ENS160 Temperature, humidity and air quality
Posted: Tue May 27, 2025 6:38 am
by Viktor74
Hi Martin. I asked earlier about this ENS160 sensor that measures air quality. I have a module with BME280 and ENS160 together on one board. It is a bit difficult for me to understand the code you wrote. Maybe there will be a macro for BME280 and ENS160, it would be better for me. OK thanks for your work, it will be interesting to understand your code for ENS160.
Re: AHT21 & ENS160 Temperature, humidity and air quality
Posted: Wed May 28, 2025 8:10 pm
by mnfisher
There is a component for the BME280.
It would be possible to create 'combined' code (as here) or (probably better) to have a separate bme and ens160 component.
What board are you using (do you have a link?)
Martin
Re: AHT21 & ENS160 Temperature, humidity and air quality
Posted: Thu May 29, 2025 7:20 am
by Viktor74
Hi Martin! I use a board like this. But in my opinion, it is better to make a macro separately for the ENS160 as these sensors can be used separately from each other. And the measurement intervals of their values may not always be the same, because temperature or humidity can be measured more often than air purity, and in other cases it may be the other way round.
Re: AHT21 & ENS160 Temperature, humidity and air quality
Posted: Thu May 29, 2025 11:03 am
by mnfisher
Stripped the aht21 out - and made into a (very basic) component. There is no simulation / image / etc but runs okay on hardware....
To test - put the component into a directory pointed to by build->customise->locations->search for components in.
There is a very simple test program that display AQI, TVOC and EC02.
Guilty confession time -> testing I couldn't get i2c to read correctly.... I'd actually connected a gyroscope board instead of the ens160 board. Such little writing
Martin
Re: AHT21 & ENS160 Temperature, humidity and air quality
Posted: Thu May 29, 2025 3:02 pm
by Viktor74
Unfortunately, I can't use this component in the free version.

Re: AHT21 & ENS160 Temperature, humidity and air quality
Posted: Thu May 29, 2025 3:05 pm
by mnfisher
You could use the source - add code to main (and more macros) to suit...
Martin