measure ohm of HS15P
Fork of Frequency_counter by
This test program measures ohm of HS15P, humidity sensor.
C(micro F) with LMC555 | 0.1 | 0.15 | 0.22 | 0.33 | 0.47 | 0.68 | 1 |
CONV_KILO_OHM | 0.0072 | 0.0048 | 0.0033 | 0.0022 | 0.0015 | 0.0011 | 0.00072 |
If you get 2500 microseconds as interrupt time interval , it means 18 kilo ohm when 0.1 micro F. ( = 2500 * 0.0072 )
- ohm of HS15P is calculated from pulse interval of LMC555.
- CONV_KILO_OHM will be used.
- this program reads interval time.between interrupt in the P8.
- takes ON the P9 to oscillate LMC555 as short as enough to measure interval time
- last several interval times will be used for calculation.
- the time is defined as READ_TIMER .
- In current circit, VDD of LMC555 is about 1.55V, AC 0.4V between pins of HS15P.
- LMC555 consumes 120 micro A while oscillation, 90 micro A when level of P9 is OFF. (reset is ON)
- Total 1-2mA is consumed in the circit.
Related nootbook : https://mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/
main.cpp@1:e2034bcdb101, 2013-06-01 (annotated)
- Committer:
- strysd
- Date:
- Sat Jun 01 05:44:10 2013 +0000
- Revision:
- 1:e2034bcdb101
- Parent:
- 0:c5bcf643a8b1
- Child:
- 2:c4d4f0f9d77c
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Neel | 0:c5bcf643a8b1 | 1 | #include "mbed.h" |
Neel | 0:c5bcf643a8b1 | 2 | |
strysd | 1:e2034bcdb101 | 3 | //see mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/ |
strysd | 1:e2034bcdb101 | 4 | #define ohm_constant 7.2 //if use 0.1 micro F |
strysd | 1:e2034bcdb101 | 5 | |
Neel | 0:c5bcf643a8b1 | 6 | Serial pc(USBTX, USBRX); |
Neel | 0:c5bcf643a8b1 | 7 | InterruptIn in(p8); |
strysd | 1:e2034bcdb101 | 8 | DigitalOut vcc555(p9); |
Neel | 0:c5bcf643a8b1 | 9 | DigitalOut led(LED1); |
Neel | 0:c5bcf643a8b1 | 10 | Timer t1; |
Neel | 0:c5bcf643a8b1 | 11 | |
strysd | 1:e2034bcdb101 | 12 | float t_period = 0;//between interrupts in microseconds |
strysd | 1:e2034bcdb101 | 13 | float my_freq = 0;//Hz |
strysd | 1:e2034bcdb101 | 14 | float my_ohm = 0;//ohm for HS15P |
strysd | 1:e2034bcdb101 | 15 | int in_limit = 10; |
strysd | 1:e2034bcdb101 | 16 | int in_count = 0; |
Neel | 0:c5bcf643a8b1 | 17 | |
Neel | 0:c5bcf643a8b1 | 18 | void flip(void) |
Neel | 0:c5bcf643a8b1 | 19 | { |
strysd | 1:e2034bcdb101 | 20 | if(in_count > 0){ |
strysd | 1:e2034bcdb101 | 21 | t_period = t1.read_us();// Get time since last interrupt |
strysd | 1:e2034bcdb101 | 22 | in_count--; |
strysd | 1:e2034bcdb101 | 23 | t1.reset();// Reset timer and wait for next interrupt |
strysd | 1:e2034bcdb101 | 24 | } else { |
strysd | 1:e2034bcdb101 | 25 | //No use interrupt |
strysd | 1:e2034bcdb101 | 26 | in.mode(PullDown); |
strysd | 1:e2034bcdb101 | 27 | vcc555 = led = 0; |
strysd | 1:e2034bcdb101 | 28 | t1.stop(); |
strysd | 1:e2034bcdb101 | 29 | } |
Neel | 0:c5bcf643a8b1 | 30 | } |
Neel | 0:c5bcf643a8b1 | 31 | |
strysd | 1:e2034bcdb101 | 32 | |
Neel | 0:c5bcf643a8b1 | 33 | int main() { |
strysd | 1:e2034bcdb101 | 34 | vcc555 = led = 0; |
strysd | 1:e2034bcdb101 | 35 | in.rise(&flip);// Set up the interrupt for rising edge |
strysd | 1:e2034bcdb101 | 36 | in.mode(PullDown); |
strysd | 1:e2034bcdb101 | 37 | |
strysd | 1:e2034bcdb101 | 38 | pc.printf("\rStarting measure\n"); |
Neel | 0:c5bcf643a8b1 | 39 | |
Neel | 0:c5bcf643a8b1 | 40 | while (1) { |
strysd | 1:e2034bcdb101 | 41 | //Use interrupt |
strysd | 1:e2034bcdb101 | 42 | t1.start(); |
strysd | 1:e2034bcdb101 | 43 | in_count = in_limit; |
strysd | 1:e2034bcdb101 | 44 | vcc555 = led = 1; |
strysd | 1:e2034bcdb101 | 45 | in.mode(PullUp); |
strysd | 1:e2034bcdb101 | 46 | wait_ms(200); |
strysd | 1:e2034bcdb101 | 47 | |
strysd | 1:e2034bcdb101 | 48 | if (t_period > 0){ |
strysd | 1:e2034bcdb101 | 49 | my_freq = (1000/t_period)*1000; // Convert to Hz |
strysd | 1:e2034bcdb101 | 50 | my_ohm = t_period * ohm_constant;// Convert to ohm |
strysd | 1:e2034bcdb101 | 51 | |
strysd | 1:e2034bcdb101 | 52 | pc.printf("\r %d Hz, %d micro sec, %d ohm \n", |
strysd | 1:e2034bcdb101 | 53 | (int)my_freq, (int)t_period, (int)my_ohm); |
strysd | 1:e2034bcdb101 | 54 | } else { |
strysd | 1:e2034bcdb101 | 55 | pc.printf("\r not ready\n"); |
strysd | 1:e2034bcdb101 | 56 | } |
strysd | 1:e2034bcdb101 | 57 | wait_ms(1800); |
Neel | 0:c5bcf643a8b1 | 58 | } |
Neel | 0:c5bcf643a8b1 | 59 | } |