Ic For Fun: Humidity and temperature sensor (SHT1x/7x) |
Humidity and temperature sensor (SHT1x/7x) Posted: 24 May 2012 09:40 AM PDT Sensirion's SHTxx is a digitally interfaced humidity and temperature sensor. Accurate humidity measurements usually require careful analog design, but the SHTxx moves all that complicated stuff into a single chip. Through-hole (SHT7x) and surface mount (SHT1x) versions are available, we used the surface mount SHT11 with +/-3% accuracy. We'll show you how to use the SHTxx below.
This isn't a cheap sensor. Octopart lists a few places to buy it. Several smaller hobby electronics stores carry it; Hobby Engineering has it for $29 (#H01509-01C). We found compatible PCB footprints in sht10_11_15.lbr and sht11.lbr on the Cadsoft library download page. Pin connections for the different package types are in the datasheet: SHT1x (PDF), SHT7x (PDF). The SHTxx has a two-wire serial interface that requires pull-up resistors (R1,2), values between 2K and 10K should work. Sensirion recommends a decoupling capacitor (C1) only if the sensor is powered over a length of wire, but we think it's always a good idea to include one. We'll demonstrate the SHTxx using the Bus Pirate universal serial interface in raw2wire mode with Hi-Z outputs. The SHTxx is powered from the Bus Pirate's 3.3volt supply. The Bus Pirate's on-board pull-up resistors hold the bus high, eliminating the need for external resistors R1 and R2. Interface The SHTxx communicates over two wires using a simple serial protocol. The protocol isn't compatible with I2C, but a single SHTxx can exist on a bus with I2C peripherals.
Five commands control the SHTxx, these are outlined in the table. The first 3 bits are the address (always 000), the remaining 5 bits are a unique command code. Reset Start a transaction by clearing any partial commands or data from a previous use. A minimum of nine clock ticks while data is high will clear the SHTxx interface. The Bus Pirate syntax to for this is -^:9; data high (-), 9 clock ticks (^:9). Commands to the SHT11 begin with a unique start condition. Like an I2C start condition, this is the only time when the data signal changes with the clock signal high. This illegal condition causes the chip to prepare for a new command. The SHTxx start condition is different than I2C, allowing both types of devices to exist on the same bus. The Bus Pirate code to generate an SHTxx style start condition is -/_/- ; data starts high (-), clock up (/), data goes low (_), clock low (), clock high (/), data goes high (-), and a final clock low transition () ends the sequence. A soft reset is a good idea because it puts the chip in a default state. Prior to the first temperature or humidity conversion, we send the soft reset command.
First, we clear the interface (-^:9), then send the start condition (-/_/-). The reset command (0b00011110=0x1E) follows. The SHTxx acknowledges (acks) commands by pulling the data line low for one bit after a command is transmitted. We read one bit (!) to get the acknowledgment status; 0 is success, 1 signals an error. Temperature Now we can read the temperature. This happens in two steps, with a delay for the temperature conversion.
First, we send a start condition and the temperature conversion command (00000011=0×03). The SHTxx replies to a successful command by pulling the data line low for one bit (ack). After the ack bit, the data line goes high until the conversion finishes.
When the data line goes low, the temperature conversion is finished. '.' is the Bus Pirate command to read the data state without a clock tick. Now we can grab the result.
Each byte read (r) requires an I2C style acknowledgment bit with the data low. We do this with the _^ sequence; data low (_), one clock tick (^). The first two bytes are the temperature reading (0x17cc), followed by a CRC (0x0c). The raw value (0x17cc=6092) is converted to degrees Celsius using the equation and coefficients on page 9 of the datasheet. Temperature readings are 14bits by default: T = -39.7 + 0.01*X 21.22C = -39.7 + (0.01*6092) Humidity Humidity conversions are started with code 00000101 (0×05 hex).
As before, a ninth acknowledgment bit is low if the SHTxx processed the command.
The data line goes high and then returns low when the humidity conversion is done.
A complete conversion generates a three byte response. The first two bytes are the raw humidity reading (0×0580=1408), the final byte is a CRC (0×46) that can be used to verify data integrity. Humidity readings have 12bits of resolution by default, convert to humidity using this equation: RH = -2.0468 + 0.0367(X) + (-0.0000015955*(X^2)) 46.46%RH = -2.0468 + 0.0367(1408) + (-0.0000015955*(1408^2)) Conclusion This isn't a cheap sensor, but it doesn't require careful analog design like the Honeywell HIH series. Have you worked with a humidity sensor? Related posts:
This posting includes an audio/video/photo media file: Download Now | ||||||||||||||||||||||||||||||||||||||||||||||||||
Posted: 24 May 2012 09:33 AM PDT PIC interface with ACS712 Current Sensor
ACS712 is precise current measurement for both AC and DC signals Device bandwidth is set via the new FILTER pin Ratiometric output from supply voltage Low-noise analog signal. This blog will not give details of ACS712 because its specification can be obtained from www.allegromicro.com . Moreover it needs few capacitors and resisters for constructing current sensor circuit but you can buy completed circuit as for your convenient.
The information you have been collected will tell you how to interface with electrical devices and Microcontroller. Understanding ACS712 is essential for the later parts in this blog. Some calculus that you will see are based on ACS712 electrical characteristic for example Supply Voltage, Zero Current Output Voltage
For my microcontroller projects I used ACS712 – the model that has Optimized Accuracy Range is 5 A and Sensitivity is 185 mV/A This means voltages will increate 185mV per 1 Amp. The output voltage when there is no load (Zero Current Output Voltage) is Vcc (Supply Volatage of ACS712) x 0.5. For me I use PIC Microcontroller using 3.3 Volt VCC so I use this source for VCS712 as well. My first calculus is [1] Zero Current Output Voltage = 3.3 x 0.5 = 1.65 The next calculus is for calculating output voltage [2] Vout = ( 0.185 x Current) + 1.6 Vout: output voltage of ACS712 Sensitivity: 185mV/A (0.185 in calculus [2]) Zero Current Output Voltage: 1.65V (calculus [1]) Current: Current usage by electrical devices. From calculus 2, we can find current usage as [3] Current = (Vout – Zero Current Output Voltage) / Sensitivity Current = (Vout – 1.65) / 0.185 Once we have calculus 3, we can calculate electrical power as [4] Power = V(rms) x I(rms) Power = 220 x (Vout – 1.65) x 0.707 / 0.185 I(rms) = I(max) x 0.707 I(max) : Current from calculus 3 V(rms) = 220V (Some countries use 110V) From the calculus above, we can give an example of power calculation of electrical device that consume 2 Amp as below. Because of AC current, we need to calculate current in both directions positive and negative. Current Positive side: (0.185 x 2) + 1.65 = 2.02 V Current Negative side: - (0.185 x 2) + 1.65V = 1.28 V Therefore electrical device consuming 2 Amp, output voltage would be between 1.28 and 2.02 as sine wave below. From the example I(max) = 2.02V, from calculus 4 we can have Power = 220 x (2.02 – 1.65) x 0.707 / 0.185 = 311.08 Watt
For my microcontroller project – Home Automation Control System, there are two parts Home Automation Control Central and Home Automation Control Endpoint. The current sensor is in Home Automation Control Endpoint that use PIC18F45K20. Microcontroller PIC18F45K20 has 10 bit ADC Module that compose of register ADRESH Bit 1-0 and ADRESL Bit 7-0
The registers will keep voltage (in digital) from ACS712 output Since it is 10 bit ADC and use 3.3 Vcc as reference voltage (PIC18F45K20 uses 3.3Vcc), we can have voltage in ADC as the calculus below [5] V(out) = 3.3 / 210 x ADC Value V(out) = 3.3 / 1024 x ADC Value For example ADC value = 512 ( ADRESH=0×01 และ ADRESL= 0xFF) V(out) = 3.3/1024 x 512 = 1.65V
In order to measure power consumption of AC, we need to know maximum of voltage in each sine wave for calculating average current I(rms). We need signal sampling 1000 times/second. That is AC 50Hz composes 50 sine wave per second. If we do the sampling 1000 times/second, it is 20 sampling per a sine wave. That would be enough for getting accurate AC current measurement. For the sampling signal as mentioned, I used Timer Interrupt module of PIC 18F45K20. I set timer interrupt every 1msec so there will be 1000 interrupts per a second for the sampling. From ADC value that sampling 1000 times per second, we separate it into 2 calculations as The first calculation is to get maximum voltage from every 20 sampling Vout(max) = Max( Vout1,Vout2…,Vout20) The second calculation is to get average voltage from the maximum voltage above. For this there will be 50 times a second Vout(avg) = Average( Vout(max)1, Vout(max)2 …. ,Vout(max)50 ) At this point we get average voltage. Then we calculate power consumption as Power = 220 x ( Vout(avg) – 1.65) x 0.707 / 0.185 The power that we get from the calculation will be displayed on LCD and sent to Home Automation Control Center. These will be used for coding Home Automation Control Endpoint for ADC and Power measurement. Related posts: |
You are subscribed to email updates from WORLD OF ELECTRO To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |