Wednesday, December 21, 2011

Lo tech decoding

Solution to optional exercise in Stanford's "Introduction to Artificial Intelligence". No need for computers...

Tuesday, November 01, 2011

Hot plate PI controller - Part 5: Boiling water and measuring with thermistor

I made a new mistake in my attempt to make a hot plate PI controller: The thermistor I selected from eBay was an unbranded China thermistor marked with "10k ohm 103 NTC Thermistor"with no datasheet. I thought it would be easy to obtain the datas for the thermistor, but so far I have not been able to find any other info than what the seller is saying:

Model: CP_RM_103 NTC Thermistor
Resistance: 10KΩ
Resistance tolerance: +/- 10%
Temperature: 30°C to +125°C

I have sent an email to the seller as a last effort to get a datasheet for the thermistor, but I have doubts that I will get it.

I wanted to set up a test to check the accuracy of the thermistor in combination with the pre set parameters in the arduino library for thermistors. I soldered a wire to the thermistor, filled a pot with 1 liter of spring water, submerged the thermistor and boiled the water. When boiling temperature 100°C is reached the chart for temperature with stabilize at 100 degrees as water is vaporized.

First some theory:
Thermodynamics has equations describing how a volume will be heated. When there is no flow in or out of the volume the heating equation reduce to:

Cp*ρ*V*dT/dt=P+h(T0-T)

Where
Cp is specific heat capacity. For water Cp=4181.3 J/(kg*K)
ρ is the density. For water ρ=1000 kg/m^3
V is the volume. For my experiment I use 1 liter=1e-3 m^3
T is the temperature in the volume.
T0 is the temperature of the neighboring. The air temperature is about 22°C
P is the power of the heating source. I use two different boiling plates with 1.4 and 1.5 kW
h is the heat conduction number

If no energy is transferred to the environment with no other losses whatsoever I get:
Δt=Cp*ρ*V*ΔT/P

I am using two different hot plates:
1. A 1.5 kW standard hot plate. Ideal time for boiling 1l water should be 262 seconds, about 4 minutes.
2. A 1.4 kW induction hot plate. Ideal time for boiling 1l water should be 281 seconds, about 4,5 minutes.

The ideal heating time is based on the tap water being 6°C.

After modifying the LabVIEW VIs used with the thermistor and servo to also save raw voltage data to disk and importing to excel I get these curves:





A couple of things can be observed from the charts:
  1. The heating curve for the induction hot plate is very erratic. This is likely because induction is basically fast alternating current through a coil. This creates a magnetic field that again induces current in the sensor wire. If better results are to be obtained with an induction cooker I need a shielded thermistor.
  2. Both measured heating curves for the induction and standard hot plate has a measured boiling temperature of about 110°C. This is probably due to wrong values for this sensor set for the Steinhart-Hart equation.
  3. The zero crossing with the y-axis is above the temperature of the tap water temperature. This is again probably due to wrong values in the Steinhart-Hart equation.
  4. Some drops are observed for the standard hot plate. This is due to different temperatures when the thermistor touched the pot and when it was only in contact with water.
  5. The slope for the induction cooker is very close to the ideal curve, thus the induction cooker is very efficient at transfering energy into cooking water.
  6. The induction hot plate and pot can be modeled as an integrator without time delay. The standard hot plate can probably be modeled as an integrator with a time delay included. When heating a larger amount of water I am expecting more energy to be transfered to the environment, and  the curves will probably take the shape of a "time-constant with time-delay" process.
Now I need to search a little more to try finding some information about the sensor specs. This in combination with the measured curves will probably give me everything I need to know to calibrate the thermistor.

Hot plate PI controller - Part 4: Playing with thermistor, RC servo and LabVIEW with arduino library


In my previous post I wrote that I wanted to use LabVIEW in combination with an additional Arduino library and the Arduino device to work as a controller. LabVIEW has library for both fuzzy and PID controllers.

I have been testing the LabVIEW PID library in combination with the Arduino library while waiting for my thermistors to arrive. My first test was to use a potmeter as an input for a PID controller setpoint and use a simulated plant to test the PID functionality. I tested the PID relay autotuner, which is a tuner that uses on/off signals to test the plant response. I have previously used relay autotuners successfully to set PID controllers with microcontrollers. The autotuner function in the LabVIEW PID library seems to be more sensitive to having a working PID controller before trying to excite the plant with on/off signals. My experience with the library is that this results in a poorly tuned controller. My plan is to use the step response for the plant to set the controller or make a relay based controller from scratch from my previous knowledge of the problem.

A few days back I finally got my 10k thermistors from eBay. The 10kohm value seems to be rather flexible with the LabVIEW Arduino library, and I cannot really understand why. I thought that the equation used, the Steinhart-Hart thermistor equation, needs three parameters A, B and C set that is allready fixed in the Arduino thermistor read function.



I hooked up the thermistor as shown in the library included thermistor example and one servo as shown in the servo example. Pretty simple:




Next I mixed the two examples together so that the temperature from the thermistor would set the output for the servo. I multiply the temperature with 1.8 so that when I have 100 degrees C input I get a 180 degrees rotation of the servo. I also tested with different delays in the loop to remove some of the "spastic" behaviour you can get when the realtime signal is used.


I experienced a bit with moving the thermistor over a candle to check the system. Below is a video of the system in action:

Here is the output in LabVIEW with and without delay:

I am quite happy with setting this system up so quickly and with both input and output working as planned on the first run.

One thing I experience is that when I stop the LabVIEW program and restart it i get erratic behaviour of the servo. Perhaps because of the PWM output from the Arduino being out of sync with the servo. I need to pull out the USB plug from the computer a couple of times in order to make it work again. This all might have to do with me having an old Arduino or that I got black smoke coming out of it the last time I used it.

Coming up I will be soldering a wire to the thermistor, put it in boiling water and see if I get a reading of 100 degrees celcius. Otherwise I need to get better parameters for the thermistor function.

Hot plate PI controller - Part 3: Arduino and LabVIEW


It's been about three years since I last used the Arduino in any project. The reason for this is that I usually find it equally easy to implement simple things in the AVR microcontroller, rather than spending more money on the arduino. The second reason is that I have usually been working on projects requiring faster throughput time for realtime control of fast acting systems (sound/vibration).

When I now came back to look at the arduino I see that a lot has changed since the last time I used it. The obvious thing being that more modern arduinos and shields for all different kinds of purposes have come to life. The community for Arduino has grown exponentially fast and Arduino is now probably the number one gadget for electronic hobbyists. Software for Arduino has become even more easy to use and make it possible to test arduino code without a physical arduino attached with VirtualBreadboard. National Instruments has recently made it possible to include Arduino in LabVIEW with an additional library, which I will come back to later in the post.

The book "making things talk" learned me a lesson in how to work with microcontroller projects, or any other problem. Rather than trying to attack the complete problem in one chunk I now try to break down the problem in small problems that can be tested one at a time. Some things that you take for granted are usually missed if you try to include the complete set of functionality at once, and even the best debugger/emulator cannot test for every kind of outcome. This is why it is critical to test each problem one at a time.

To test the reading of a sensor, in this project a thermistor, you need a system able to show the input from the sensor to the user. With early versions of the arduino this was best done by using the programming language processing and displaying the input to the computer screen. The only difficulty with this solution was that a fraction of the code you wrote was reusable and you thus needed to write routines each time you had a new kind of problem.

Now LabVIEW, the measurement system that I as a programmer loved to hate, has come up with a complete range of pre built modules to comunicate with the arduino. So you can put all the logics in labVIEW and the input/output can be handled by arduino. This makes everything even more simple. The only problem I see with this solution is that you need a computer with LabVIEW or the labview built application to run the algorithms. I will start working with the labview modules, and later see if I want to move the whole controller and logics to the arduino.

Setting up Arduino with LabVIEW was done in a breeze. The examples and ready made functions for sensors are absolutely amazing.

Full instructions for installing Arduino with LabVIEW can be found here.
National Instruments web page for LabVIEW with Arduino

Here is even a geeky video of what the combo can be used for:

Monday, October 10, 2011

Hot plate PI controller - Part 2: The temperature sensor

The thermometer I am using is the typical stove thermometer that you can buy from any kitchenware store. Mine came with our IKEA / Whirlpool kitchen stove.



I have no idea of the resistance of the thermistor probe that came with the thermometer so I had to set up a little experiment to find the resistance range.

I put 1 litres of water in a pot on an induction plate, turn on the heat for a while, turn it off to let the temperature settle and then measure temperature with the thermometer. Next I measure the resistance with a multimeter.

With four measurements I got this curve:


Excel shows the fitted linear curve and the nice little formula:

Rt=0.2*T-2.7

Where Rt is the termistor resistance and T is the temperature measured in centigrades.

I want to use the thermistor with a resistor and measure the temperature by setting them up as a voltage divider. Input voltage will be 5V:


By setting the second resistor to the value of 5 ohm I get the greatest difference between the lowest and highest measured voltage (2,85V) and thus the best resolution. The curve for voltage measured over the thermistor for the optimal resistor is shown below: 


Defining:
F=Vout/Vin=Rt/(Rt+R)

Calculating for Rt:
1) Rt=R*F/(1-F)

From previous excel linear fitting for measured temperature:
2) T=(Rt+2.7)/0.2

1) and 2) put together:
T=25*F/(1-F)+13.5, where F=Vout/Vin

Finishing with an example:
What is the temperature when you are suppling the voltage divider with 5V and you get an ADC reading is 511?

A reading of 511 in the ADC is a measured voltage of 5V*511/1023=2.5V with a supplied voltage of 5V.

F=2.5V/5V=0.5

T=25*F/(1-F)+13.5=25*0.5/(1-0.5)+13.5=38.5 degrees celcius, which corresponds very well with the curve above.


The real excitement begins when I get a 5 ohm resistor, set up a measurement system and start measuring realtime temperature data. Is boiling temperature still measured to 100 degrees celcius?

_____________________________

Update:

Yesterday I tried setting up the voltage divider with the arduino. I found a 4.7 ohm resistor to use with the thermistor and was ready for measuring temperature with the arduino. 

I had thought very little about the consequences of using such small resistors: When I hook up a 4.7 ohm resistor with a thermistor that has close to zero ohm resistance at room temperature I get a current of 5V/5ohm=1A!! So when I set up the bridge and inserted the USB I got smoke coming out of the arduino or resistor. The arduino seems to be working fine afterwords, though, so I learned my lesson.

So I should rather find a resistor that has as low as possible reistance, without destroying the arduino. How low can it be?

Here are some of the limits:
- The USB 2.0 standard has a maximum current limit of 500 mA. 
- In the summary for the arduino UNO the I/O ports are rated for 40 mA. 
- In the data sheet for the Voltage regulator (LM340) I see a maximum current of 1 A at 5 V.
- I think the resistors I am using is 0,25 W type based on the thickness => Maximum current 50 mA.

I think the input impedance of the ADC pins are quite high, so there will not be much current going through to the ADC. That makes the resistors I am using the weakest link with maximum current 50 mA.

My new resistor will have to be at least 5 V / 0.05 A=100 ohm.

The new temperature chart will be like this:

The voltage range is too low, which means I get bad resolution (about 0.7 deg C) . I either need a different thermistor or a resistor with higher power rating.

In summary: Don't try to reuse the measurement probe from a thermometer. It's cheaper and easier to buy a thermistor with an available datasheet.

Hot plate PI controller - Part 1: The start

I want to make a hot plate controlled by a PI controller. The reasons are primarily to master the PI controller practically with the bonus of being able to control the boiling process when making home made beer.

Yesterday I boiled my first batch of wort and got the feeling of what it takes to control the temperature with several liters of wort (about 30 litres) on a small 1,5 kW old fashioned hot plate. The process was pretty slow, so it is absolutely possible to control it manually, but I want to set it at a specific temperature and let a home made controller do the rest of the job.

The parts I want to use for the project is:

  1. Controller: An old Arduino NT that I got lying around. This will be permanently used for brewing purposes in the future.
  2. Actuating element: A 1,5 kW hot plate of the old kind with built in on/off controller and stepless adjustment of power.
  3. Actuator: A 180 degrees adjustable Hitec HS-325HB RC servo for attaching to the power knob.
  4. Temperature sensor: A termistor type termometer that I want to reverse engineer and use the probe from.

Wednesday, January 05, 2011

How to set up VirtualBox shared folders with Windows 7

Start by adding shared folders in settings before starting the VM:

Next install guest additions after windows 7 VM has started:

If you are using autoruns you will be asked to install guest addition. Otherwise open the cd rom drive and run installation. You will be asked to restart the VM when finished.

After restarting you should now find your shared folders under Network\VBOXSVR within the Explorer (windows key+E).