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@7:42e7f18361c8, 2013-11-06 (annotated)
- Committer:
- strysd
- Date:
- Wed Nov 06 07:38:20 2013 +0000
- Revision:
- 7:42e7f18361c8
- Parent:
- 6:7f90a61e1a69
sync libraries
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
strysd | 6:7f90a61e1a69 | 1 | //see mbed.org/users/strysd/notebook/measure_humidity_with_hs15p_and_lmc555/ |
Neel | 0:c5bcf643a8b1 | 2 | #include "mbed.h" |
strysd | 6:7f90a61e1a69 | 3 | #include "main.h" |
strysd | 1:e2034bcdb101 | 4 | |
strysd | 4:64d9c0bed75b | 5 | InterruptIn in(p8); //connect to the Discharge of 555 |
strysd | 5:9be3080ca8ba | 6 | DigitalOut run555(p9);//connect to the Reset of 555 |
strysd | 7:42e7f18361c8 | 7 | DigitalOut led1(LED1);//running 555 |
strysd | 7:42e7f18361c8 | 8 | DigitalOut led2(LED2);//not ready |
Neel | 0:c5bcf643a8b1 | 9 | Timer t1; |
Neel | 0:c5bcf643a8b1 | 10 | |
strysd | 4:64d9c0bed75b | 11 | float my_interval = 0;//between interrupts in microseconds |
strysd | 1:e2034bcdb101 | 12 | float my_freq = 0;//Hz |
strysd | 4:64d9c0bed75b | 13 | float my_ohm = 0;//ohm for HS15P |
strysd | 4:64d9c0bed75b | 14 | int rest_in = 0;//rest of interrupt times |
Neel | 0:c5bcf643a8b1 | 15 | |
Neel | 0:c5bcf643a8b1 | 16 | void flip(void) |
Neel | 0:c5bcf643a8b1 | 17 | { |
strysd | 6:7f90a61e1a69 | 18 | if(rest_in < READ_TIMER){ |
strysd | 6:7f90a61e1a69 | 19 | my_interval = t1.read_us();// Get time since last interrupt |
strysd | 4:64d9c0bed75b | 20 | } |
strysd | 5:9be3080ca8ba | 21 | |
strysd | 6:7f90a61e1a69 | 22 | t1.reset();// Reset timer and wait for next interrupt |
strysd | 6:7f90a61e1a69 | 23 | rest_in--; |
strysd | 6:7f90a61e1a69 | 24 | |
strysd | 6:7f90a61e1a69 | 25 | if(rest_in <= 0){ |
strysd | 1:e2034bcdb101 | 26 | //No use interrupt |
strysd | 7:42e7f18361c8 | 27 | run555 = led1 = 0; |
strysd | 1:e2034bcdb101 | 28 | t1.stop(); |
strysd | 1:e2034bcdb101 | 29 | } |
Neel | 0:c5bcf643a8b1 | 30 | } |
Neel | 0:c5bcf643a8b1 | 31 | |
Neel | 0:c5bcf643a8b1 | 32 | int main() { |
strysd | 7:42e7f18361c8 | 33 | run555 = led1 = led2 = 0; |
strysd | 5:9be3080ca8ba | 34 | // Set up the interrupt |
strysd | 2:c4d4f0f9d77c | 35 | in.mode(PullUp); |
strysd | 6:7f90a61e1a69 | 36 | in.rise(&flip); |
strysd | 1:e2034bcdb101 | 37 | |
strysd | 3:bf0a5effbed2 | 38 | printf("\rStarting measure\n"); |
strysd | 5:9be3080ca8ba | 39 | |
Neel | 0:c5bcf643a8b1 | 40 | while (1) { |
strysd | 1:e2034bcdb101 | 41 | //Use interrupt |
strysd | 4:64d9c0bed75b | 42 | my_interval = 0; |
strysd | 1:e2034bcdb101 | 43 | t1.start(); |
strysd | 4:64d9c0bed75b | 44 | rest_in = IN_TIMES; |
strysd | 7:42e7f18361c8 | 45 | run555 = led1 = 1; |
strysd | 7:42e7f18361c8 | 46 | led2 = 0; |
strysd | 4:64d9c0bed75b | 47 | wait_ms(WAIT_IN); |
strysd | 7:42e7f18361c8 | 48 | run555 = led1 = 0;//force stop |
strysd | 3:bf0a5effbed2 | 49 | |
strysd | 4:64d9c0bed75b | 50 | if (my_interval < MIN_INTERVAL || my_interval > MAX_INTERVAL){ |
strysd | 3:bf0a5effbed2 | 51 | printf("\r not ready\n"); |
strysd | 7:42e7f18361c8 | 52 | led2 = 1; |
strysd | 1:e2034bcdb101 | 53 | } else { |
strysd | 4:64d9c0bed75b | 54 | my_freq = ONESEC_BY_MICRO / my_interval; // Convert to Hz |
strysd | 4:64d9c0bed75b | 55 | my_ohm = my_interval * CONV_KILO_OHM;// Convert to kilo ohm |
strysd | 6:7f90a61e1a69 | 56 | printf("\r %.0f Hz, %.0f micro sec, %.1f kilo ohm \n", |
strysd | 6:7f90a61e1a69 | 57 | my_freq, my_interval, my_ohm); |
strysd | 1:e2034bcdb101 | 58 | } |
strysd | 3:bf0a5effbed2 | 59 | |
strysd | 4:64d9c0bed75b | 60 | wait_ms(WAIT_NEXT); |
Neel | 0:c5bcf643a8b1 | 61 | } |
Neel | 0:c5bcf643a8b1 | 62 | } |