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






Dienstag, 19. November 2013

Energy Effiency and Powerpoint

The time has come to revise the work and have an eye on the power consumption also the apperance of the program was slightly changed.

Due to the face that the original program on the Arduino was sampling all the time the microcontoller consumed a lot of energy. It sucks 22mA in a normal operational status which is quiet heavy for the operation we are doing. In order to save energy the Arduino is now set to sleep when he is no needed. This reduced the current input to 14mA, a huge save!
When the "Take a sample" button is pressed in the C# GUI, the PC sends a byte via the serial connection to the Arduino which wakes him up. He then responds with a 100 samples of the A/D converter (Ethanol Sensor) and falls back to sleep immediately.
In addition the Overall appearance of the GUI was changed and i learned how to merge cells which increases the visibility of the chart.

A short Video shows the operational program below

It was also necessary to create a little slideshow for the lecture. It can be found below if interested.

Alcodino Presentation 20.11.2013


Worked: (21h) + 4h30m = 25h30m

Dienstag, 12. November 2013

Serial Connection + Chartfilling

Serial connection established and data shown with C# Chart control

The connection is now established and the Alcodino GUI is able to receive data from the Arduino. Therefore the data  is shown in a chart using C# Chart control.
The current solution is not more then a prototype showing the possiblies of the future program. Still a lot of nasty errors occured on the way there. For example when trying to use Serial commands in C# the message "Serial port is already open" occured and froze the PC. The modification was then to insert more Serial.Close commands which led to the problem of data corruption. It took some time until a nice and clean working serial environment was established.
The Data collection was then only time consuming but not challenging. Still there are some problems: while collecting the data the program is not controllable and the user has to wait until the sampletaking is finished.

Next steps are:
- Make it possible to abort the sampletaking
- Introduce the I2C Sensor
- Rework the C# GUI

Alcodino Prototype - Serial connection + Data in Chart
Worked: (16h) + 5h = 21h

Montag, 4. November 2013

C# Chart Control

Chart Control -- Problems


Using the C# Chart Control i stumbled across a lot of problems. For example i can`t divide between X and Y values the data will always be displayed at both the x Axis and the y Axis even though i used 3 different methods.

  
 

private void fillButton_Click(object sender, EventArgs e)
        {
            Random rnd1 = new Random();

            int[] xaxis1;
            int[] xaxis2;
            int[] xaxis3;
            xaxis1 = new int[10];
            xaxis2 = new int[10];
            xaxis3 = new int[15];

            for (int i = 0; i < 5; i++)

            {
                xaxis1[i] = i*2;
            }

            toprightChart.DataSource = xaxis1;
            toprightChart.Series[0].XValueMember = "Y";
            toprightChart.Series[0].YValueMembers = "X";
            toprightChart.ChartAreas["ChartArea1"].AxisX.Interval = 1;
            toprightChart.DataBind();

            for (int j = 0; j < 10; j++)
            {
                xaxis2[j] = rnd1.Next(0, 10);
            }

            bottomleftChart.DataSource = xaxis2;
            bottomleftChart.Series[0].XValueMember = "Y";
            bottomleftChart.Series[0].YValueMembers = "X";
            bottomleftChart.ChartAreas["ChartArea1"].AxisX.Interval = 1;
            bottomleftChart.DataBind();

            List<double> chartData = new List<double>();

            for (int k = 0; k < 5; k++)
            {
                chartData.Add(rnd1.Next(0, 10));
            }

            bottomrightChart.DataSource = chartData;
            bottomrightChart.Series[0].XValueMember = "Y";
            bottomrightChart.Series[0].YValueMembers = "X";
            bottomrightChart.ChartAreas["ChartArea1"].AxisX.Interval = 1;
            bottomrightChart.DataBind();
        }


After those problems are solved there should be a focus at real time charts and the serial connection to the Arduino.

Worked (13h) + 3h = 16h

Freitag, 25. Oktober 2013

Project Plan

The Project Plan is finished

Click here to see the project plan

Since all the planning is finally done and all the parts have arrived i will start with technical issues next week.


Worked: (9h) + 4h = 13h

Donnerstag, 17. Oktober 2013

Project Management

Creating the Gantt, networking diagram, timeline and include resources to the project.


According to the module description at the CIT homepage for the project module the electrical engineering department planned with 3h40m independent project work for the student for each week.
Regarding the 14 weeks the semester has it sums up to 51h20m for the whole semester.

However I calculated with 91h for the whole project. This is the result of the agreement that was made with my supervisor. We decided that my project will planned and realised in the same semester since my semester abroad will after Christmas. Normally the project is planned in one semester and realized in the next semester.

The diagrams below were all done with Microsoft Project 2010 ver. 14.0.6 (32 Bit)


 Timeline


Timeline Project Alcodino - Microsoft Project 2010

 



Gantt- Chart
 
Resources


The Network Diagram is sadly to big!

Learend:
-How to use Microsoft Project (First steps)

ToDo:
-digitalize the Block Diagram
- Define the goals of the project according to the milestones
- make a table that shows the

Worked: (6h) + 3h = 9h

Montag, 14. Oktober 2013

The Order

The Requisition Form

First order:
1. Arduino Mega 61,44€
2. Linear Active Thermistor (Analogue) 4€
3. Humidity Sensor (Analogue) 16,95€
4. MQ-3 Ethanol Sensor 4,95 €
Sum: 87,34€ + Porto (high porto for the MQ-3 since its from USA)

After the first order form was declined due to high expenses a cheaper way had to be found.
The solution is to order the MQ-3 sensor from a store in the UK which is called cool components this will will result in cheaper porto costs. The second step was to combine the temperature sensor and the humidity sensor into a cheap all together sensor. The sensor is called DFN6 and is an I2C sensor this will require more work and research but the Arduino is capable of handling the I2C bus.

New order:
1. Arduino Mega 61,44€
2. Sensor Humidity & Temp DFN6 (I2C) 19,05€
3. Ethanol Sensor MQ-3 5,92£ = 6,97€
Sum : 87,46€ + Porto ( porto for the MQ-3 will be cheaper and faster)