Mittwoch, 4. Dezember 2013

Finished Project

A lot of stuff happened here! Take a look!

Final look of the graphical user interface

 

Implementation of the I²C Sensor HIH6130 - Temperature & Humidity

This little thing was tougher then thought! The Wire library allows you to simply communicate with any I²C device given you have the native adress of the sensor and know how it provides data!
So the sensor give framework had to be defined at first place.
The data was given in this little pdf.      COMMUNICATION DATA SHEET - HIH6130
Long story short the native adress is 0x27 and the sensor provides 4 Bytes of Data.
The first 2 Bytes are for the Humidity and the last 2 Bytes are for the Temperature.
Whereas the 2 most significant bits in the first Byte are displaying the status of the sensor, the 2 least significant bits from the last Byte are "do not care" bits.

"When reading the full 14 bit resolution temperature output, the
two least significant bits of the fourth data byte are “Do Not
Care” and should be ignored"

With this in mind it was still challenging to extract the actual data from the sensor. Here is the solution:

address = 0x27;  // adress of the HIH6130
      Wire.beginTransmission(address); // greet the HIH6130 as Master
      Wire.endTransmission(); 
      delay(10);
     
      Wire.requestFrom((int)address, (int) 4);  // request 4 Bytes from the HIH
      humiHigh = Wire.read();
      humiLOW = Wire.read();
      tempHIGH = Wire.read();
      tempLOW = Wire.read();
      Wire.endTransmission();
     
      status = (
humiHigh >> 6) & 0x03;   // Status is in the 2 most significant bits of the first Byte &       //Control Bitwise

     
humiHigh= humiHigh & 0x3f;            // Get rid of the status Bits
      Humidi = (((unsigned int)
humiHigh) << 8) | humiLOW;   // higher Bytes get shifted 8 Bits to the left

      Temp = (((unsigned int)tempHIGH) << 8) |  tempLOW;  // to make place for the lower Byte being ord

      Temp = Temp / 4; // divide by 4 to implement "do not care Bits"
    

Those Values Humidit and Temp then have to be put into the equations given in the Datasheet and can be send via the serial connection afterwards.

Correction of the MQ-3 Ethanol Sensor output using Humidity and Temperature

The Etahnol sensor is being affected by its surrounding tempereature and humidity. This effect is especially visible when breathing into the sensor when there are no drinks being drank whatsoever. To evolve a correction formula it was needed to have a closer at the data sheet which provides a "visual" solution.

Putting those visualised points into a table it gives us:



Humidity 33% Humidity85%
Temperature °C Factor*Rs/R0 Factor*Rs/R0
-10 1,6 1,36
0 1,35 1,15
10 1,15 1
20 1 0,9
30 0,92 0,84
40 0,89 0,8
50 0,87 0,79

 Those values where putted into Matlab to create  polynomial regressions with those values.
The outcome of the regression shows us that a polynom of 2nd order is sufficient of covering those valuse.

 However we get different polynomial factors for diferent humidities. Which brought me to the idea to calculate the correcting factor Rs/R0 by linearising the polynomial factors dependant on the humidity. 
The regression for each polynomial factor was again done with Matlab. The final equation looks like this:




With x,y,z being:









To correct the values finally we have to invert the outcome of the eqation and multiply it with the sensor output.

Sensor Calibration

The normal procedure to calibrate the MQ-3 Sensor includes a labratory and an amount of 0,4mg/l ethanol in clean air (as said in Datasheet - whatever clean air means). Since the lack of time i dicided to calibrate the sensor on my own using my breath a bottle of wine with 13%. While drinking i took a certain amount of samples in a certain amount of time after drinking a certain amount!
The outcoming table looks like this:


Legend:
*1 = Start drinking the new drink
*2 = sample immediately after finishing the drink
0 Test = running a sample without breathing into the sensor

Looking at this table it is visible that the sensor outcomes are not very stable. This results in different distances and angles of breathing as well as the changing room condition and the inconsistent amount of alcohol in my breath. However it seems like the sensor outcome raises with the increasing Blood alcohol conecetration (BAC) which was calculated using the website: promillerechner.net. All we need now is a formula that transforms the sensor counts into the BAC. Since the Breath alcohol concentration (BrAC) is connected to the BAC via a very simple formula, having one means having the other.

Putting the values into a graph and putting a regression polynomial through it looks like this:

It does not look to bad!
Using the formula given in the graph we are now able to calculate the BAC given the counts of the sensor.
Furthermore with the formula BAC = 2100* BrAC (Source: Report from the Transportation Departement UK)  we also have the BrAC which means the project is finished!

ToDO:
-Project Presentation
-Project Report

Worked: (25h30min) + 20h = 45h30min

Not included in the worktime :
-Lectures
-Meetings with the Supervisor
-Preparation of Meetings