Humidity sensor simulation

Hi everyone,

I have a university project to realize. I design a circuit to realize humidity measure with HIH4000 sensor. I want in output a variation between 0V for 0% HR to 1V for 100% HR. It’s okay for that but I would like to simulate the circuit but I’m a little bit confuse whit how to do that.

I don’t know how to configure the sensor to have the value wanted and how visualize Vs correctly, I don’t know if it’s even possible.
Thank you for your help and sorry for my English, I’m a French Student.

This is what i had with simulation:

First thing to remember is you need to use PSPICE parts when you are simulating. As a result your simulation model will not match your schematic capture model

Once you have updated the circuit using PSPICE parts the next problem is the sensor and the best solution is to use a PWL voltage source with an appropriate output impedance to mimic the sensor

Once that is done the simulation will work

foo

There are a couple of problems with your circuit

  1. HIH4000 requires a minimum of 80k terminating resistor
  2. I am guessing you are attemping to bias the signal due to 0% = 0.75V, this won’t work as it stands
  3. the resistors associated with the OMPAMP are low… really low
  4. the output response as it stand does mot match your design intent
2 Likes

Your circuit can be simulated, for sure. But it will need some efforts.

In designing the circuit diagram, you have used KiCAD symbols. The simulation up to now has spitted a lot of error messages, most dealing with missing models.

To do a simulation, each symbol will need a Spice model. For resistors, this is included. For OpAmps and Sensors it is not. So you have to take care. For the OpAmp LM321 you might google for a suitable vendor’s Spice model. Then you have to add this model to your OpAmp symbol. Please have a look at http://ngspice.sourceforge.net/ngspice-eeschema.html#OpAmp how to do that. This tutorial will give you also some hints on establishing PSPICE compatibility, typically needed for using commercial OpAmp models. Concerning the power supply, better choose ngspice compatible symbols as you may find in the Simulation_Spice symbol library.

More difficult will be handling the sensor. There seems to be no Spice model available from the vendor. So you have to create one yourself. The reliable source available is the data sheet from Honeywell. You correctly have shown 3 electrical pins in your sensor symbol. But that’s not all. A sensor has another connection to the environment, the humidity entrance. Of course KiCAD and ngspice don’t have any notion of humidity nodes. But why not replace them by an electrical node, say a voltage input with 0V for 0% and 100V for 100% humidity? If you want to follow this idea (very common in sensor design), you have to add another pin (e.g. named ‘humidity’) to your symbol. The humidity then may be represented by a voltage source.

You definitely have to look at the data sheet. One point is that the power supply voltage is 5V. In your circuit with ±5V on the sensor, it probably would ‘explode’. The -VE should better be connected to 0V.

How to create a model? Unfortunately this will need some knowledge of ngspice netlists. As you (hopefully) have recognized, the OpAmp model is a subcircuit model. So you have to create a ngspice subcircuit description, put it into a file and then add it to your sensor symbol as you have done with the OpAmp. Inside of the subcrcuit we will need an (electrical) equivalent of the sensor’s behavior. This may be found by again looking at the data sheet. There you will find the output versus humidity equation, that is Vout=Vsupply*(0.0062*RH + 0.16). In ngspice there is a B source availabe that allows to describe such functions. The subcircuit starts with a title, then the .subckt line with subcircuit name and nodes, then the internal description, followed by the .ends line. I will give you a hint (not tested):

* HIH-4000 simple subcircuit model
.subckt HIH-4000 -VE OUT +VE RH
Bout OUT -VE V = (v(+VE) - v(-VE)) * (0.0062 * v(RH) + 0.16)
.ends

So node 1 is -VE, node 2 is OUT, node 3 is +VE, and node 4 is RH, the humidity input. If you firstly just put the sensor, an output resistor to ground and a voltage source as humidity input, you may do a .dc simulation to check if the sensor model is doing what the data sheet says. Then you may add your OpAmp circuit to obtain the final output between 0 and 1V.

2 Likes

Hi Holger,

Thanks for this explanation, it’s help me a lot but now, i have some problem about the sensor model, i don’t know where i should enter the humidy equation. I don’t find the “B source”.

Thank you for your contribution.

This is the B source (line starting with B, a Non-linear Dependent Source or Behavioral
Source, ngspice manual chapt. 5.1) readily implemented in the sensor subcircuit model.

I’m sorry, i don’t understand.
I did this schematic

I have imported the HIH-4000 library, but during simulation, i had this message:
“warning, can’t find model n
warning, can’t find model n
warning, can’t find model n
warning, can’t find model n
warning, can’t find model n
warning, can’t find model n
warning, can’t find model n
warning, can’t find model n
Circuit: KiCad schematic
Error: unknown subckt: x -ve 1 100 -200 100 l 40 40 0 0 w
Error: there aren’t any circuits loaded.”

Thanks

Put the subcircuit into a file HIH-4000.mod.

This is what the tutorial that I recommended above (and you probably did not look at it) says, here LF356 replaced by HIH-4000:

How to add the ngspice model? Double click on the HIH-4000 symbol in the circuit drawing. The ‘Symbol Properties’ window opens. Call ‘Edit Spice Model’. Select ‘Model’ -> ‘File Select’. Enter path/name of HIH-4000.mod. Select ‘Type’ -> ‘Subcircuit’. The description of the subcircuit is shown in the window.

The subcircuit should not be placed into the eeschema window textbox.

If then the simulation fails again, please post the netlist here:
Tools->Simulator->Run Simulation->Simulation->Show SPICE netlist

Ok, sorry, the file was .lib not .mod

Simulation doesn’t work yet. I have this message:
Fatal error: DCtrCurv: source / resistor not in circuit
doAnalyses: no such device
run simulation(s) aborted

Here the spice netlist:
".title KiCad schematic
.include “C:\Users\benja\OneDrive\Bureau\Simulation KiCad\Test_HIH\HIH-4000.mod”
XU1 GND vs +VE IN HIH-4000
R1 vs GND 80k
V1 +VE GND 5V
V2 IN GND 100V
.save @ r1[i]
.save @ v1[i]
.save @ v2[i]
.save V(+VE)
.save V(IN)
.save V(vs)
.dc
.end
"

It does not matter if it is lib or mod.

Your .dc command is not complete (manual chapt. 15.3.2 .DC: DC Transfer Function)!

.dc V2 0 100 5

would be o.k. We have to improve the ngspice error message.

Thanks a lot, it’s working !

Very sorry, it was my first time with kicad & ngspice.

Hi,

I have an other question, should i use this to modelize an other sensor ?

  • HIH-4000 simple subcircuit model
    .subckt HIH-4000 -VE OUT +VE RH
    Bout OUT -VE V = (v(+VE) - v(-VE)) * (0.0062 * v(RH) + 0.16)
    .ends

Not really. You don’t need to re-define the HIH-4000 subcircuit a 2nd time. You can just copy U1 and paste to U2, U3, U4, etc…i.e. as many HIH-4000 instances as you want. As long as they still reference the same .lib or .mod file containing the .subckt command, then you shouldn’t need to create more commands or more lib/mod files. Basically, you can make as many HIH-4000 you want in your schematic as long as they all point to the same lib/mod file.