Mesuring height of Burj Khalifa using Pressure Sensor
BY GOPI PATEL
Vacation inspires all of us; it recharges our mental batteries and open opportunity to reflect on true purpose of the professional work and perhaps connect our actions with real life. Every journey motivates me, especially when flying high - a burst of idea is obvious to most of us; welcome on board long-haul flight to Dubai, a city with hundreds of world record including the tallest building on the planet – Burj Khalifa. Tallest, how tall? How to measure it? It there a simpler way to estimate altitude? Etc… you can imagine one idea and several questions, all about heights and altitude at 42,000 feet in a one of the largest aircraft. I am a design engineer with 30 years of experience and able to build most prototypes by hand, so it was obvious that I always carry some gadgets to satisfy my curiosity. Do you remember a quote something like…
“Altitude is determined by your attitude”.
In this article, you will learn how simple it is to measure altitude using Arduino and the most simple pressure sensor. WSEN-PADS is smallest I2C or SPI pressure sensor with integrated temperature sensor operating temperature range -40°C to +85°C. Calibrated pressure data output via 128 FIFO buffer that can update up to 200 time a second (not that I was ascending at a fighter-jet speed). Measureable pressure range 126kPa to 26kPa and relative accuracy ±2.5 Pa; which mean you could potentially measure atmospheric pressure up to 10km above or 1km below sea level; just perfect to do what I wanted to do. By the way Burj Khalifa the tallest building in the world is 160 stories tall, has fastest lift in the world and several other Guinness world records. This experiment was done without any calibration; neither temperature compensated, nor sea level zero balance. Miraculously it worked well in the maiden attempt up to 126th floor; now you will read how did I do that. Of-course it was not that easy to carry bare electronic circuits through security, I had to get special approvals and assure no disturbance or hazard of any sort. If you think of doing something like this, then you must consider all aspects of risk, safety, compliance and convenience to others around you. Vantage point 360⁰ Dubai view from top of Burj Khalifa is pretty spectacular. Once you are on the top, do yourself a favour and invest in very inspiring book “Flashes of Thought” by Sheikh Mohammed bin Rashid Al Maktoum. This book is now one of my favourite collection.
Sensor Shield for Arduino:
First, I took a sensor shield and mounted on to Arduino Uno to make-sure blink LED works on its own, then I inserted PADS and ITDS Eval boards in to I2C headers. I got their examples from GitHub and made sure both sensors are working well. Good thing about this is that they are quick connect without any tools. Though you will not need to worry about I2C connections, I have also provided a pinout detail in the table. At the beginning, my Arduino code started to read pressure, temperature and values of acceleration of X, Y and Z-axis on the serial terminal. I could just modify few lines of program to convert pressure in to altitude and keep reading on a serial terminal; well, being an engineer, I challenged myself to go beyond this. I wanted to see all these data on my mobile phone, so I created bespoke app using MIT App Inventor, took me about three hours to make all that working. Are you excited to know what challenges I had to overcome?
Second, I needed to mount a Proteus-III BLE module on a Sensor Shield, fortunately, there was already a placeholder and I only soldered FOUR pins (VCC, GND, TX and RX). In my hand-assembled prototype, you will see two wires (TX + RX) mounted on a pin header rather than soldered permanently, that is because Arduino UNO only have single UART that is shared between programming and BLE, so during firmware upload I lift two pins and during normal operation I insert them on the socket. If you do not do this then it will not allow to program or not work at all. Okay, we also need to consider the TX of BLE must join to RX of Arduino and vice versa. At this point, my job was only 25% done, I still needed to write firmware for Arduino, make android app and then debug all hardware + firmware + appware. You may be surprised how easy it was once I set my mind to do this adventure, time was ticking as I only had couple of days left in my vacation before catching return flight to UK. Third, I tackle firmware, here you can find working codes, they are not scrutinized and never verified by any other professional so expect scope for improvements, feel free to modify to your taste. Original PADS Sensor example was downloaded from GitHub, I did modified example just to get absolute pressure data in mbar and temperature in degree Celsius.
Almost any mcu firmware can be split into FOUR chunk: 1) include, 2) setup, 3) main loop and 4) call sub-routines. Writing code is an art, you can never perfect and always evolves as you debug or progress. To get sensor data and calculate distance and then send over to BLE required some modifications to the original PADS example. I started with including Würth Elektronik PADS header file to quick start, then define some global variables as in the lines 1:9 below. Arduino likes float, byte and int as numeric variable and it works well. On STM32 or PIC micro you might need to use uint8, uint16, char or int8 style of RAM. If answer you expect contains decimal point then you should use float, else keep it positive integer. Buffer for UART transmission is named as tx mean there are 100 spaces [0 to 99 inclusive] for UART data. In line #30 you will see I am using 90 bytes a payload and about 7 other add-on, which mean I am within my allocation RAM buffer size. Checksum variable is important in secure BLE data exchange; I have defined as ‘csum’ on line #7 and used it on lines 43 and 45.
Of-course these way of coding is my short cut for private use, professionally I have much different style of writing firmware with lot more meaning and colleague-friendly. It is better to create your own file.h so that you can keep re-using the same library.
Setup() is a one-off routine, required by Arduino compiler. Let’s keep UART 115200 baud rates and initiate serial communication along with usual checkpoints in steps 13:21. Throw error messages if no sensor was detected, here you could blink LED if you wish. Since I used readymade SDK example from GitHub I never needed to worry about address, however if you like to know more, see chapter 4.3.6 depicts slave address mechanism. SAO pin helps alternating address selection.
Before we move to next topic, I recommend looking at the AppNote ANM003 to learn how pressure to altitude can be done professionally. Lot of my practice run was done on a “Smart Commander”, download free. This proves that there are many road leads to Rome, and Rome was not built in one day.
“The fortune is for those who dare to dream and find the courage to pursue their dreams”
– Flashes of Thought, page 34.
Main program executes in a Loop between lines 51:74 to get raw I2C reading, then convert pressure to actual millibar and Pascal in a 16bit, then split in to LSB and MSB for easy transmission via BLE. In Arduino there is a nice command called map, I used that to convert pressure in to meters. I accepted temperature reading as it is because it is factory calibrated according to datasheet. Line 65:68 are optional and very useful to see all the data on an Arduino or other serial terminal using Serial.print command. You can imagine not much happening in this loop, so it could repeat hundreds of time per second. By adding deliberate 1000ms (1 second) delay #73, I can avoid overloading the TX buffer.
Image below is a screenshot of Arduino serial monitor; you can see one new packet each second. Timings could be accurate if interrupts were used, never mind, we are on different agenda here. Did you know that there is a ticket to go to the top of the world - floor 126 of Burj Khalifa, and there are usually long que and all lifts are fully loaded with people? So to avoid risk of firmware-crashing, sensor-malfunction or out-of-range data, I used my hotel lift as a calibration laboratory and I trialled few times up and down 16 floors. Fortunately, hotel lift had no queue at early morning 5am nor any ticket. I was enjoying sensor board, Arduino, android phone and laptop. Launch day we arrived early at the Burj Khalifa, security checkpoint told me that laptops are not allowed in the world’s fastest lift. Well, in order not put myself in trouble, I politely informed concierge manager and couple of receptionist, in emirates everyone are very cooperative.
MSB x 256 + LSB = 16 Bit data so that … 3 x 256 + 237 = 1005 mbar
Proteus-III BLE Send Data:
Proteus module can exchange bidirectional data in two different mode 1) transparent mode and 2) command mode. Transparent is easy, but I am not here for easy ride, so I chose command mode. In command mode you can do lot more complex things securely, read more in the Proteus-III user manual. sendProteus() is my own call sub-routine lines 25:49 that sends data over the air to a mobile app via Proteus-III BLE. #26 pre-fills every byte with 0 to 99, I found it useful when developing android app, and it keeps placeholder of each byte. #27 is a simple counter that increases every time I send data, mind that I have no requirement to read acknowledgement so we will not talk in this experiment. #28 is a first tx buffer, always 0x02 for all Würth Elektronik radio modules. #29 is a command byte (can be any command e.g. change BLE name, change PIN, stop advertising, go to sleep etc), command 0x04 mean I need to send some payload. In addition, the length of payload is defined by 16 bit in #30/31 because Proteus-III can handle up to 964 byte, which is more than one byte. Fill the buffers (4 to 93) with actual payload and then last byte 94 is checksum byte made using exclusive or of all the previous bytes (0 to 93). That’s it, my program successfully sent send data to BLE or computer.
The difference between actual 452m at level 124 and 590m on my android mobile app is 138 meter, can be down to three main factors, a) I forgot to consider ZERO at the start of the test on ground level, b) I did not account temperature calibration formula, the relationship between pressure and altitude is not straight line, and c) I enjoied roof-top lunch with my wife then took express lift through Emporio Armani suite to level 126 where I stopped my app but the plack “You are here – Level 124 – 452m” was on of-course on two level below which is open air balcony for tourist.
Check their dessert, cakes are super delicious. The more tastier item was “Tennis Ball” which has five sensors (Temperature, Pressure, Acceleration, Humidity and Light), STM32, long range 600m BLE combined with 2.4GHz MESH radio (Setebos-I) and powered by single coincell which could last few years; seems amazing isnt it!! Keep an eye on another publication, I have done several experiments with it in Dubai, London and few places in Europe; it is going to be the best ever tool for IoT engineer. Hey, I am willing to publish how to develop best IoS or Android app, please comment your feedback.
You must understand that this was just curiosity experiment and not a final product in any shape; nevertheless, you may be able to invent commercially viable design for application of your imagination, I wish very best on that. I, my colleagues, Würth Elektronik, publisher or other names mentioned in this draft take no responsibility for loss or damage of any type. Idea here is to show you possibilities and capabilities, I chose Burj Khalifa because not only it is the tallest building in the world and pressure sensor is on the extreme the tiniest in the electronic industry; but I chose this venue to respect their creators, visionary management and ambitious builders who risk their lives. I enjoy doing challenging experiment entirely on my own risk, self-funding and self-learning; I did not get any sponsor and this is not a paid marketing advertisement. Honestly, I do this for the electronic engineering brains across the world. Please like and share if you found this useful. Write your comments and feedback along with what else you curiously expect. Massive thank goes out to my wife Ragini, she carried gadgets in her backpack and tolerated my frequent change of direction.