Shop OBEX P1 Docs P2 Docs Learn Events
Controlling 12V DC motor w/ sht11 temp. humidity sensor — Parallax Forums

Controlling 12V DC motor w/ sht11 temp. humidity sensor

Matt KMatt K Posts: 6
edited 2007-05-31 19:42 in BASIC Stamp
I need help turning a 12 V dc fan on once the sht11 reads a desired temperature and humidity.· I can light a LED but not at the desired range.· Can anyone help me with this?

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-05-31 02:00
    Show us what you have and maybe we can help. You would do this the same way you switch any load, with a relay, transistor or a mosfet.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Matt KMatt K Posts: 6
    edited 2007-05-31 12:58
    I am using a transistor.· I took the code from the parallax web page and the sht11 works fine.· I plan on using an IF temp. < x THEN HIGH statement but Im not sure what to use for X.· I want the fan to come on at 75 deg. and 45% humidity.· Am I going about this wrong?· Also when I hook the dc motor to my homework board, I'll need a 12V power source.· Will this affect my board? It just has the one 9 v battery.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-31 14:14
    Matt,

    If you want to switch when both the temperature and humidity are past a set point then your conditional will have to be more like:

    IF temp > SetTemp AND humidity > SetHumidity THEN

    As for the 12V, you will need the power source for the motor and it will need a common ground with the H/W Board. The transistor or MOSFET will handle the switching of the load so it shouldn’t interfere with your board as long as the current is not unusually high. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Matt KMatt K Posts: 6
    edited 2007-05-31 15:07
    I want the fan to switch on when the temp either/or the humidity reaches a setpoint.· Ive been testing the setpoints with LEDs, but Im having problems.· I cant just enter a temp or humidity reading, such as tF <·80 or rhLin < 45.
    If I had a LED hooked to pin 14, what should my code consist of to turn the LED on at say·80 degrees or higher?
    This is the first time Ive ever used the basic stamp so Im a little confused.· Thanks for the help.
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-31 15:18
    Matt,

    IF tF < 80 OR rhLin < 45 THEN
      HIGH 14
    ELSE
      LOW 14
    ENDIF
    

    This is, of course, assuming that the variable tF provides an integer·temperature such as 80 and that rhLin provides the relative humidity in percent as a whole number as well.· If not these values would have to be conditioned before this point.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Matt KMatt K Posts: 6
    edited 2007-05-31 18:45
    My If Then statement looks like the one you sent me but I wasnt sure where to insert it.· Once I placed it in the code that I have included the LEDs would come on when the temp or humidity was below the setpoint rather than above it.· I must be placing it in the wrong location.· I place it after· "tF....... ", DEC (tF / 10), ".", DEC1 tF, DegSym, " "· and after "rhTrue... ", DEC (rhTrue / 10), ".", DEC1 rhTrue, "% ".· Is this wrong?
    [font=Arial,Bold]BASIC Stamp Application
    [/font]The following BASIC Stamp application will read the SHT11 sensor module and display sensor counts,
    converted temperature and calibrated humidity. When running, the program output will appear as
    shown below:
    ' =========================================================================
    '
    ' File...... SHT11_Demo.BS2
    ' Purpose... Interface to Sensirion SHT11 temperature/humidity sensor
    ' Author.... Parallax
    ' E-mail.... support@parallax.com
    ' Started...
    ' Updated... 19 JUL 2003
    '
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    '
    ' =========================================================================
    '
    ' Program Description
    '
    '
    Parallax, Inc. • Sensirion SHT11 Sensor Module (#28018) • 07/2003 3
    ' This program demonstrates the interface and conversion of SHT11/15 data
    ' to usable program values. This program uses advanced math features of
    ' PBASIC, specifically the ** operator.
    '
    ' For detailed application information on the use and application of the
    ' ** operator, see Dr. Tracy Allen's web page at this link:
    '
    ' -- http://www.emesystems.com/BS2math1.htm
    '
    ' For SHT11/15 documentation and app notes, visit:
    '
    ' -- http://www.sensirion.com
    '
    ' Revision History
    '
    '
    ' I/O Definitions
    '
    ShtData PIN 1 ' bi-directional data
    Clock PIN 0
    '
    ' Constants
    '
    ShtTemp CON %00011 ' read temperature
    ShtHumi CON %00101 ' read humidity
    ShtStatW CON %00110 ' status register write
    ShtStatR CON %00111 ' status register read
    ShtReset CON %11110 ' soft reset
    Ack CON 0
    NoAck CON 1
    No CON 0
    Yes CON 1
    DegSym CON 186 ' degrees symbol for DEBUG
    '
    ' Variables
    '
    Parallax, Inc. • Sensirion SHT11 Sensor Module (#28018) • 07/2003 4
    ioByte VAR Byte ' data from/to SHT11
    ackBit VAR Bit ' ack/nak from/to SHT11
    toDelay VAR Byte ' timeout delay timer
    timeOut VAR Bit ' timeout status
    soT VAR Word ' temp counts from SHT11
    tC VAR Word ' temp - Celcius
    tF VAR Word ' temp - Fahrenheit
    soRH VAR Word ' humidity counts
    rhLin VAR Word ' humidity; linearized
    rhTrue VAR Word ' humidity; compensated
    status VAR Byte ' status byte
    '
    ' EEPROM Data
    '
    '
    ' Initialization
    '
    Initialize:
    GOSUB SHT_Connection_Reset ' reset device connection
    PAUSE 250 ' let DEBUG window open
    DEBUG CLS,
    "SHT11 Sensor Demo", CR,
    "
    ", CR
    '
    ' Program Code
    '
    Main:
    DO
    GOSUB SHT_Measure_Temp
    DEBUG CRSRXY, 0, 3,
    "soT...... ", DEC soT, CR,
    "tC....... ", DEC (tC / 10), ".", DEC1 tC, DegSym, " ", CR,
    "tF....... ", DEC (tF / 10), ".", DEC1 tF, DegSym, " "
    GOSUB SHT_Measure_Humidity
    DEBUG CRSRXY, 0, 7,
    "soRH..... ", DEC soRH, CR,
    Parallax, Inc. • Sensirion SHT11 Sensor Module (#28018) • 07/2003 5
    "rhLin.... ", DEC (rhLin / 10), ".", DEC1 rhLin, "% ", CR,
    "rhTrue... ", DEC (rhTrue / 10), ".", DEC1 rhTrue, "% "
    PAUSE 1000
    LOOP
    END
    '
    ' Subroutines
    '
    ' connection reset: 9 clock cyles with ShtData high, then start sequence
    '
    SHT_Connection_Reset:
    SHIFTOUT ShtData, Clock, LSBFirst, [noparse][[/noparse]$FFF\9]
    ' generates SHT11 "start" sequence
    ' _____ _____
    ' ShtData |_______|
    ' ___ ___
    ' Clock ___| |___| |___
    '
    SHT_Start:
    INPUT ShtData ' let pull-up take high
    LOW Clock
    HIGH Clock
    LOW ShtData
    LOW Clock
    HIGH Clock
    INPUT ShtData
    LOW Clock
    RETURN
    ' measure temperature
    ' -- celcius = raw * 0.01 - 40
    ' -- fahrenheit = raw * 0.018 - 40
    '
    SHT_Measure_Temp:
    GOSUB SHT_Start ' alert device
    ioByte = ShtTemp ' temperature command
    GOSUB SHT_Write_Byte ' send command
    GOSUB SHT_Wait ' wait for measurement
    ackBit = Ack ' another read follows
    GOSUB SHT_Read_Byte ' get MSB
    soT.HighByte = ioByte
    ackBit = NoAck ' last read
    GOSUB SHT_Read_Byte ' get LSB
    Parallax, Inc. • Sensirion SHT11 Sensor Module (#28018) • 07/2003 6
    soT.LowByte = ioByte
    ' Note: Conversion factors are multiplied by 10 to return the
    ' temperature values in tenths of degrees
    tC = soT ** $1999 - 400 ' convert to tenths C
    tF = soT ** $2E14 - 400 ' convert to tenths F
    RETURN
    ' measure humidity
    '
    SHT_Measure_Humidity:
    GOSUB SHT_Start ' alert device
    ioByte = ShtHumi ' humidity command
    GOSUB SHT_Write_Byte ' send command
    GOSUB SHT_Wait ' wait for measurement
    ackBit = Ack ' another read follows
    GOSUB SHT_Read_Byte ' get MSB
    soRH.HighByte = ioByte
    ackBit = NoAck ' last read
    GOSUB SHT_Read_Byte ' get LSB
    soRH.LowByte = ioByte
    ' linearize humidity
    ' rhLin = (soRH * 0.0405) - (soRH^2 * 0.0000028) - 4
    '
    ' for the BASIC Stamp:
    ' rhLin = (soRH * 0.0405) - (soRH * 0.002 * soRH * 0.0014) - 4
    '
    ' Conversion factors are multiplied by 10 to return tenths
    '
    rhLin = (soRH ** $67AE) - (soRH ** $83 * soRH ** $5B) - 40
    ' temperature compensated humidity
    ' rhTrue = (tc - 25) * (soRH * 0.00008 + 0.01) + rhLin
    '
    ' Conversion factors are multiplied by 10 to return tenths
    ' -- simplified
    '
    rhTrue = (tC - 250) * (soRH ** $34) + rhLin
    RETURN
    ' sends "status"
    '
    SHT_Write_Status:
    GOSUB SHT_Start ' alert device
    ioByte = ShtStatW ' write to status reg cmd
    Parallax, Inc. • Sensirion SHT11 Sensor Module (#28018) • 07/2003 7
    GOSUB SHT_Write_Byte ' send command
    ioByte = status
    GOSUB SHT_Write_Byte
    RETURN
    ' returns "status"
    '
    SHT_Read_Status:
    GOSUB SHT_Start ' alert device
    ioByte = ShtStatW ' write to status reg cmd
    GOSUB SHT_Read_Byte ' send command
    ackBit = NoAck ' only one byte to read
    GOSUB SHT_Read_Byte
    RETURN
    ' sends "ioByte"
    ' returns "ackBit"
    '
    SHT_Write_Byte:
    SHIFTOUT ShtData, Clock, MSBFirst, [noparse][[/noparse]ioByte] ' send byte
    SHIFTIN ShtData, Clock, LSBPre, [noparse][[/noparse]ackBit\1] ' get ack bit
    RETURN
    ' returns "ioByte"
    ' sends "ackBit"
    '
    SHT_Read_Byte:
    SHIFTIN ShtData, Clock, MSBPre, [noparse][[/noparse]ioByte] ' get byte
    SHIFTOUT ShtData, Clock, LSBFirst, [noparse][[/noparse]ackBit\1] ' send ack bit
    INPUT ShtData ' release data line
    RETURN
    ' wait for device to finish measurement (pulls data line low)
    ' -- timeout after ~1/4 second
    '
    SHT_Wait:
    INPUT ShtData ' data line is input
    timeOut = No ' assume no timeout
    FOR toDelay = 1 TO 250 ' wait ~1/4 second
    IF (ShtData = 0) THEN EXIT
    PAUSE 1
    NEXT
    IF (toDelay = 250) THEN timeOut = Yes ' loop completed = timeout
    RETURN
    Parallax, Inc. • Sensirion SHT11 Sensor Module (#28018) • 07/2003 8
    ' reset SHT11/15 with soft reset
    '
    SHT_Soft_Reset:
    GOSUB SHT_Connection_Reset ' reset the connection
    ioByte = ShtReset ' reset command
    ackBit = NoAck ' only one byte to send
    GOSUB SHT_Write_Byte ' send it
    PAUSE 11 ' wait at least 11 ms
    RETURN
    In high humidity applications, the SHT11 heater can be switched on briefly to prevent condensation.
    Another use of the heater is to test the operation of the sensor: by reading before enabling the heater
    and immediately after the sensor can be verified by noting a higher temperature and lower humidity.
    The following subroutines can be used to switch the SHT11 heater on and off.
    Heater_On:
    status = %00000100 ' heater bit = On
    GOSUB SHT_Write_Status
    RETURN
    Heater_Off:
    status = %00000000 ' heater bit = Off
    GOSUB SHT_Write_Status
    RETURN
  • Matt KMatt K Posts: 6
    edited 2007-05-31 18:50
    The If Then code that I told you earlier was wrong.· I meant If tF > 80 or rhLin > 45.· The LEDs would come on when the temp or humidity was below 80 or 45%.·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-05-31 19:42
    Matt,

    In the future please attach larger programs like this one rather than pasting them. As for the conditional I was simply copying your example with the less than…Certainly if you want greater than you would change those symbols. The values you’re comparing against are not necessarily what you want as they include the integer and floating point parts of the value. You will need to convert the value to an integer or calculate the conditional in a different way.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
Sign In or Register to comment.