Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

PWM controlled LCR-0202 test with temperature indication

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    These are dirty cheap: something like 40 to 60 cents each.

    This, plus the fact that I can use them everywhere from low voltage devices to (main interest) high voltage devices, plus the fact that I can assign values through a microcontroller (to change them on the fly, like CC controllers, or as presets), are the reasons why I've spent some time on them.

    Comment


    • #17
      Originally posted by Roberto View Post
      These are dirty cheap: something like 40 to 60 cents each.

      This, plus the fact that I can use them everywhere from low voltage devices to (main interest) high voltage devices, plus the fact that I can assign values through a microcontroller (to change them on the fly, like CC controllers, or as presets), are the reasons why I've spent some time on them.
      On eBay here in the UK they were coming up at over $11 for one, hence my comment. I do see on the US site the lowest I see is $0.85, quite an improvement and definitely leads to a different conclusion. What is your source for 0.40 to 0.60 each?
      Experience is something you get, just after you really needed it.

      Comment


      • #18
        At the moment they are sold at 85 cent/each, as you say: https://www.ebay.com/itm/291774645055
        When I bought 10 of them time ago, they were around 50 cent/each.
        For sure they can be sold really cheap for bigger quantities, but I don't think this is the kind of part that can focus attention of alot of people around.

        Comment


        • #19
          Originally posted by nickb View Post
          Sort of a one bit exponent block floating point.

          You didn't really say what the real reason is so I'll have to guess. You want to use them as linear devices and that implies you want some kind digital control, probably because you want to to store and recall settings in some fashion. Am I on the right lines here?
          If this is the application (and it sounds like it is), then I love this idea!
          I briefly flirted with the idea of using a microcontroller as a multi-waveform LFO generator for experimenting with time/phase based effects. But, I wondered if a quad LM1458 oscillator or an XR2202 my buddy gave me would have been the better approach. But since I would have been using LDRs in the RC network, I wish I had thought of this. I think there could be a lot of potential here.
          Plus, I've been looking for a good arduino project to get into. There is so much utility with the platform, that I'd be fool not to take advantage of it.
          If I have a 50% chance of guessing the right answer, I guess wrong 80% of the time.

          Comment


          • #20
            Originally posted by SoulFetish View Post
            But since I would have been using LDRs in the RC network, I wish I had thought of this. I think there could be a lot of potential here.
            Plus, I've been looking for a good arduino project to get into. There is so much utility with the platform, that I'd be fool not to take advantage of it.
            Thanks SoulFetish, yes, it's my "winter holydays project" and as I've written before, that's the purpose. I'll change the title of the thread in order to keep it clearer for everyone.

            I've increased the value from 10k to 33k, as it fits better the range I want to work with, and the bypass with the 2N3904 ( https://www.sparkfun.com/datasheets/...nts/2N3904.pdf ) works perfectly. I'm looking to control from 2M to 5k with the 33k in series, and from 5k to 100 Ohm without it.

            To have a better control of the effective resistance of the LDR, two voltage dividers are made with 100k resistors (I consider reliable the values that are within one order of magnitude from the fixed resistor) and two with 1k resistors. This way I can cover the values between 1M down to 100 Ohm.

            Even more, I prefer not to use the first bits of the PWM range, just because if I find the right value with the PWM inbetween 0001 and 0002, I cannot modify it, while if it's inbetween 0016 and 0032 I've 16 values inbetween to find the right one. Hypothetically to stay in the 5%, and at least to stay in the 10% of tolerance.

            I will try the suggestion to increase the stabilisation time to 10 seconds, but with 2 seconds I can stay within ±10%. Not bad.

            Comment


            • #21
              This is the new software to check the 33k bypass:

              Code:
              #include <Wire.h>
              
              //to manage the LCR-0202s
              #include <Adafruit_PWMServoDriver.h>
              Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
              
              //just to show results
              #include <LiquidCrystal_I2C.h>
              LiquidCrystal_I2C lcd(0x27, 20, 4);
              
              //to read ambient temperature
              #include <SimpleDHT.h>
              int pinDHT22 = 2;
              SimpleDHT22 dht22;
              float temperature = 0;
              float humidity = 0;
              
              //just an array of 2^n
              int pwm_values[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4095};
              
              //analog readings in voltage dividers
              float a_read1 = 0;
              float a_read2 = 0;
              float a_read3 = 0;
              float a_read4 = 0;
              
              //LCR-0202 initial resistance values
              float LCR1_ohm = 0;
              float LCR2_ohm = 0;
              float LCR3_ohm = 0;
              float LCR4_ohm = 0;
              
              //define "leak" resistors in voltage dividers
              float bottomR1_ohm = 100000;
              float bottomR2_ohm = 100000;
              float bottomR3_ohm = 1000;
              float bottomR4_ohm = 1000;
              
              void setup() {
                //PWM startup
                pwm.begin();
                pwm.setPWMFreq(1500); //to avoid wavering of the light
              
                //LCD startup
                lcd.init();
                lcd.backlight();
                lcd.clear();
              
                // Serial startup
                Serial.begin(9600);
              }
              
              void loop() {
                for (int b = 0; b < 2; b++) {
                  for (int i = 0; i < 14; i++) {
                    for (int led_num = 0; led_num < 5; led_num++) {
                      pwm.setPWM(led_num, 0, (4095 - pwm_values[i]));
                    }
                    delay(5000);
                    show_values(i, b);
                  }
                  for (int led_num = 8; led_num < 13; led_num++) {
                    pwm.setPWM(led_num, 0, (4095 * b));
                  }
                }
              }
              
              void show_values(int i, int b) {
                lcd.clear();
                lcd.print("Robi's LCR-0202 Test");
              
                lcd.setCursor(0, 1);
                lcd.print("bit");
                lcd.print(b);
                Serial.print(b);
                Serial.print("  ");
              
                lcd.setCursor(6, 1);
                lcd.print("PWM");
                lcd.print(pwm_values[i]);
                Serial.print(pwm_values[i]);
                Serial.print("  ");
              
                lcd.setCursor(14, 1);
                dht22.read2(pinDHT22, &temperature, &humidity, NULL);
                lcd.print("T");
                lcd.print(temperature);
                Serial.print(temperature);
                Serial.print("  ");
              
                lcd.setCursor(0, 2);
                a_read1 = analogRead(0);
                LCR1_ohm = ((1023 / a_read1) - 1) * bottomR1_ohm;
                lcd.print(LCR1_ohm);
                Serial.print(a_read1);
                Serial.print("  ");
              
                lcd.setCursor(0, 3);
                a_read2 = analogRead(1);
                LCR2_ohm = ((1023 / a_read2) - 1) * bottomR2_ohm;
                lcd.print(LCR2_ohm);
                Serial.print(a_read2);
                Serial.print("  ");
              
                lcd.setCursor(10, 2);
                a_read3 = analogRead(2);
                LCR3_ohm = ((1023 / a_read3) - 1) * bottomR3_ohm;
                lcd.print(LCR3_ohm);
                Serial.print(a_read3);
                Serial.print("  ");
              
                lcd.setCursor(10, 3);
                a_read4 = analogRead(3);
                LCR4_ohm = ((1023 / a_read4) - 1) * bottomR4_ohm; //((1023 * bottomR4_ohm) / a_read4) - bottomR4_ohm;
                lcd.print(LCR4_ohm);
                Serial.println(a_read4);
              }

              Comment


              • #22
                So, these are the results from the first test with the bypassable 33k resistor:

                - 1st column is the 2n3904's bit: 0 = bypassed 33k; 1= unbypassed 33k
                - 2nd column is the PWM value (0 = 0% led on; 4095 = 100% led on)
                - 3rd is the temperature in Celsius degrees
                - 4th is the value of the resistor of the LDR supposed by reading the value of the voltage divider with a 100 kOhm to ground (I consider it acceptable within 2 orders of magnitude, so between 1 MOhm and 10 kOhm)
                - 5th is the value of the resistor of the LDR supposed by reading the value of the voltage divider with a 100 kOhm to ground (I consider it acceptable within 2 orders of magnitude, so between 1 MOhm and 10 kOhm)
                - 6th is the value of the resistor of the LDR supposed by reading the value of the voltage divider with a 1 kOhm to ground (I consider it acceptable within 2 orders of magnitude, so between 10 kOhm and 100 Ohm)
                - 7th is the value of the resistor of the LDR supposed by reading the value of the voltage divider with a 1 kOhm to ground (I consider it acceptable within 2 orders of magnitude, so between 10 kOhm and 100 Ohm)

                As you will notice, I've added a comma between each value, in order to import the data in excel as csv file (or txt file).
                If anyone wants to partecipate...

                Code:
                0, 0, 23.60, inf, inf, inf, inf,
                0, 1, 23.60, inf, inf, inf, inf,
                0, 2, 23.70, inf, inf, inf, inf,
                0, 4, 23.70, 25475000.00, 12687500.00, inf, inf,
                0, 8, 23.60, 5015000.00, 2908823.50, inf, inf,
                0, 16, 23.60, 1523809.37, 988297.87, inf, inf,
                0, 32, 23.60, 582000.00, 411499.96, inf, 510500.00,
                0, 64, 23.60, 249146.75, 188983.06, 254750.00, 126875.00,
                0, 128, 23.60, 115368.42, 91214.96, 77692.31, 50150.00,
                0, 256, 23.60, 56422.02, 46561.60, 36888.89, 25230.77,
                0, 512, 23.60, 27875.00, 24301.34, 19058.82, 13826.09,
                0, 1024, 23.60, 13793.10, 11803.28, 9882.98, 7818.97,
                0, 2048, 23.60, 6562.50, 5681.81, 5686.27, 4683.33,
                0, 4095, 23.60, 3229.06, 2710.84, 3587.44, 2980.54,
                1, 0, 23.60, inf, inf, inf, inf,
                1, 1, 23.60, inf, inf, inf, inf,
                1, 2, 23.60, inf, inf, inf, inf,
                1, 4, 23.60, inf, 14514285.00, inf, inf,
                1, 8, 23.60, 6719999.50, 3200000.00, inf, inf,
                1, 16, 23.60, 1694736.87, 1075862.00, inf, inf,
                1, 32, 23.60, 600684.93, 427319.56, inf, 510500.00,
                1, 64, 23.60, 246779.65, 187359.54, 254750.00, 112666.67,
                1, 128, 23.60, 112240.67, 89444.45, 77692.31, 50150.00,
                1, 256, 23.60, 55000.00, 45726.49, 35535.71, 25230.77,
                1, 512, 23.60, 26140.57, 22076.37, 18673.08, 14268.66,
                1, 1024, 23.60, 13289.03, 11316.65, 9546.39, 7669.49,
                1, 2048, 23.60, 6896.56, 6120.34, 6055.17, 4812.50,
                1, 4095, 23.60, 3229.06, 2710.84, 3566.96, 2965.12,
                0, 0, 23.60, inf, inf, inf, inf,
                0, 1, 23.60, 20352.94, 19369.90, 19058.82, 13208.33,
                0, 2, 23.50, 11437.91, 10954.45, 11629.63, 8300.00,
                0, 4, 23.50, 6340.96, 6230.53, 7317.07, 5557.69,
                0, 8, 23.50, 3752.53, 3857.86, 5162.65, 3966.02,
                0, 16, 23.50, 1488.09, 1488.09, 3280.33, 2640.57,
                0, 32, 23.50, 195.88, 195.88, 2177.02, 1742.63,
                0, 64, 23.50, 0.00, 0.00, 1513.51, 1209.50,
                0, 128, 23.50, 0.00, 0.00, 1122.41, 877.06,
                0, 256, 23.50, 0.00, 0.00, 823.53, 639.42,
                0, 512, 23.50, 0.00, 0.00, 623.81, 469.83,
                0, 1024, 23.50, 0.00, 0.00, 354.97, 277.15,
                0, 2048, 23.50, 0.00, 0.00, 196.49, 170.48,
                0, 4095, 23.50, 0.00, 0.00, 174.51, 143.02,
                1, 0, 23.50, inf, inf, inf, inf,
                1, 1, 23.50, inf, inf, inf, inf,
                1, 2, 23.50, inf, inf, inf, inf,
                1, 4, 23.50, 102200000.00, 20360000.00, inf, inf,
                1, 8, 23.50, 7207142.50, 3688889.00, inf, inf,
                1, 16, 23.40, 1794444.50, 1147561.00, inf, inf,
                1, 32, 23.40, 620422.56, 444148.93, inf, 510500.00,
                1, 64, 23.40, 260211.28, 196521.73, 254750.00, 126875.00,
                1, 128, 23.40, 114016.75, 90502.80, 84250.00, 52842.10,
                1, 256, 23.40, 56422.02, 46561.60, 36888.89, 25921.05,
                1, 512, 23.40, 28356.34, 24301.34, 18673.08, 13826.09,
                1, 1024, 23.40, 13163.72, 11803.28, 10366.67, 8216.22,
                1, 2048, 23.40, 7008.37, 6120.34, 5912.16, 4747.19,
                1, 4095, 23.40, 3229.06, 2814.07, 3608.11, 2980.54,
                0, 0, 23.40, inf, inf, inf, inf,
                0, 1, 23.40, 20494.70, 19091.96, 19058.82, 13208.33,
                0, 2, 23.40, 11195.65, 10714.28, 11325.30, 8216.22,
                0, 4, 23.30, 5900.62, 5791.10, 8216.22, 6006.85,
                0, 8, 23.30, 4175.15, 4387.76, 5686.27, 4246.15,
                0, 16, 23.30, 1994.01, 2095.81, 3736.11, 2875.00,
                0, 32, 23.30, 97.85, 97.85, 2227.13, 1795.08,
                0, 64, 23.30, 0.00, 0.00, 1685.04, 1298.88,
                0, 128, 23.30, 0.00, 0.00, 1268.29, 959.77,
                0, 256, 23.30, 0.00, 0.00, 933.84, 699.34,
                0, 512, 23.30, 0.00, 0.00, 330.30, 286.79,
                0, 1024, 23.30, 0.00, 0.00, 318.30, 255.21,
                0, 2048, 23.30, 0.00, 0.00, 277.15, 212.09,
                0, 4095, 23.30, 0.00, 0.00, 174.51, 143.02,
                1, 0, 23.30, inf, inf, inf, inf,
                1, 1, 23.30, inf, inf, inf, inf,
                1, 2, 23.30, inf, inf, inf, inf,
                1, 4, 23.30, 51050000.00, 12687500.00, inf, inf,
                1, 8, 23.20, 6719999.50, 3688889.00, inf, inf,
                1, 16, 23.20, 1794444.50, 1147561.00, inf, inf,
                1, 32, 23.20, 625531.93, 444148.93, inf, 510500.00,
                1, 64, 23.30, 251546.39, 188169.00, 254750.00, 126875.00,
                1, 128, 23.20, 118589.74, 95229.01, 84250.00, 52842.10,
                1, 256, 23.30, 55235.21, 45726.49, 35535.71, 25230.77,
                1, 512, 23.20, 28035.05, 23700.12, 18673.08, 13826.09,
                1, 1024, 23.20, 14429.53, 12541.26, 10494.38, 8053.10,
                1, 2048, 23.20, 6784.96, 5900.62, 5774.83, 4683.33,
                1, 4095, 23.30, 3333.33, 2814.07, 3608.11, 2996.09,
                0, 0, 23.20, inf, inf, inf, inf,
                0, 1, 23.20, 21352.32, 19929.66, 20312.50, 13614.29,
                0, 2, 23.20, 11559.44, 11195.65, 11787.50, 8385.32,
                0, 4, 23.20, 6896.56, 6784.96, 7895.65, 5820.00,
                0, 8, 23.20, 3963.41, 4069.17, 5433.96, 4140.70,
                0, 16, 23.20, 2095.81, 2197.80, 3825.47, 2934.62,
                0, 32, 23.10, 0.00, 0.00, 2053.73, 1699.21,
                0, 64, 23.10, 0.00, 0.00, 1623.08, 1263.27,
                0, 128, 23.10, 0.00, 0.00, 912.15, 769.90,
                0, 256, 23.10, 0.00, 0.00, 725.13, 578.70,
                0, 512, 23.10, 0.00, 0.00, 581.14, 440.85,
                0, 1024, 23.10, 0.00, 0.00, 434.78, 318.30,
                0, 2048, 23.10, 0.00, 0.00, 266.09, 196.49,
                0, 4095, 23.10, 0.00, 0.00, 174.51, 144.30,
                1, 0, 23.10, inf, inf, inf, inf,
                1, 1, 23.10, inf, inf, inf, inf,
                1, 2, 23.10, inf, inf, inf, inf,
                1, 4, 23.10, 51050000.00, 16950000.00, inf, inf,
                1, 8, 23.10, 6293750.00, 3688889.00, inf, inf,
                1, 16, 23.10, 1760000.00, 1162963.00, inf, inf,
                1, 32, 23.10, 615384.62, 435602.09, inf, 340000.00,
                1, 64, 23.10, 260211.28, 196521.73, 254750.00, 126875.00,
                1, 128, 23.10, 119527.89, 94486.69, 84250.00, 52842.10,
                1, 256, 23.10, 56901.83, 46982.75, 36888.89, 25921.05,
                1, 512, 23.10, 27875.00, 24756.10, 19460.00, 14044.12,
                1, 1024, 23.10, 13289.03, 12048.20, 10625.00, 8216.22,
                1, 2048, 23.10, 6896.56, 6120.34, 5912.16, 4812.50,
                1, 4095, 23.10, 3229.06, 2814.07, 3628.96, 2996.09,
                0, 0, 23.10, inf, inf, inf, inf,
                0, 1, 23.10, 21496.44, 20352.94, 20312.50, 13826.09,
                0, 2, 23.10, 11074.92, 10714.28, 11178.57, 8133.93,
                0, 4, 23.10, 5900.62, 7120.42, 8216.22, 6006.85,
                0, 8, 23.10, 4175.15, 4281.34, 5557.69, 4192.89,
                0, 16, 23.10, 1791.05, 1791.05, 3506.61, 2747.25,
                0, 32, 23.10, 195.88, 195.88, 2206.90, 1787.47,
                0, 64, 23.10, 0.00, 0.00, 1772.36, 1357.14,
                0, 128, 23.10, 0.00, 0.00, 1158.23, 883.98,
                0, 256, 23.10, 0.00, 0.00, 897.96, 674.30,
                0, 512, 23.10, 0.00, 0.00, 536.04, 412.98,
                0, 1024, 23.10, 0.00, 0.00, 438.82, 323.42,
                0, 2048, 23.10, 0.00, 0.00, 354.97, 252.14,
                0, 4095, 23.10, 0.00, 0.00, 174.51, 143.02,
                1, 0, 23.10, inf, inf, inf, inf,
                1, 1, 23.10, inf, inf, inf, inf,
                1, 2, 23.10, inf, inf, inf, inf,
                1, 4, 23.10, 102200000.00, 16950000.00, inf, inf,
                1, 8, 23.10, 5917647.00, 3553571.25, inf, inf,
                1, 16, 23.10, 1760000.00, 1147561.00, inf, inf,
                1, 32, 23.10, 605517.25, 447058.81, inf, 510500.00,
                1, 64, 23.10, 257692.31, 195664.73, 254750.00, 126875.00,
                1, 128, 23.10, 118589.74, 93750.00, 84250.00, 52842.10,
                1, 256, 23.10, 53834.58, 45106.39, 38346.15, 26648.65,
                1, 512, 23.10, 26923.07, 22514.98, 18673.08, 14268.66,
                1, 1024, 23.10, 14046.82, 12171.05, 10241.76, 7895.65,
                1, 2048, 23.10, 7232.70, 6340.96, 6153.85, 4879.31,
                1, 4095, 23.10, 3229.06, 2710.84, 3608.11, 2996.09,
                0, 0, 23.10, inf, inf, inf, inf,
                0, 1, 23.10, 21496.44, 20352.94, 20312.50, 13826.09,
                0, 2, 23.10, 11316.65, 10834.24, 11629.63, 8385.32,
                0, 4, 23.10, 7008.37, 6896.56, 7973.68, 5912.16,
                0, 8, 23.10, 3752.53, 3752.53, 5162.65, 3990.24,
                0, 16, 23.10, 1892.44, 1892.44, 3650.00, 2817.16,
                0, 32, 23.10, 589.97, 589.97, 2576.92, 1973.84,
                0, 64, 23.10, 0.00, 0.00, 1757.41, 1351.72,
                0, 128, 23.10, 0.00, 0.00, 739.80, 742.76,
                0, 256, 23.10, 0.00, 0.00, 933.84, 702.16,
                0, 512, 23.10, 0.00, 0.00, 690.91, 506.63,
                0, 1024, 23.10, 0.00, 0.00, 275.56, 253.68,
                0, 2048, 23.10, 0.00, 0.00, 294.94, 217.86,
                0, 4095, 23.00, 0.00, 0.00, 174.51, 144.30,
                1, 0, 23.00, inf, inf, inf, inf,
                1, 1, 23.00, inf, inf, inf, inf,
                1, 2, 23.00, inf, inf, inf, inf,
                1, 4, 23.00, 34000000.00, 16950000.00, inf, inf,
                1, 8, 23.00, 6293750.00, 3427586.25, inf, inf,
                1, 16, 23.00, 1760000.00, 1147561.00, inf, inf,
                1, 32, 23.00, 635971.18, 447058.81, inf, 510500.00,
                1, 64, 23.00, 257692.31, 197383.71, 254750.00, 126875.00,
                1, 128, 23.00, 117659.57, 94117.64, 84250.00, 52842.10,
                1, 256, 23.00, 57627.12, 47832.37, 38346.15, 25921.05,
                1, 512, 23.00, 27875.00, 23550.73, 18301.89, 13614.29,
                1, 1024, 23.00, 13540.51, 12294.19, 10895.35, 8216.22,
                1, 2048, 23.00, 6896.56, 5900.62, 5865.77, 4715.08,
                1, 4095, 23.00, 3333.33, 2814.07, 3628.96, 2996.09,
                0, 0, 23.00, inf, inf, inf, inf,
                0, 1, 23.00, 20070.42, 18953.49, 21239.13, 14044.12,
                0, 2, 23.00, 10594.59, 11803.28, 12285.71, 8650.94,
                0, 4, 23.00, 6340.96, 6340.96, 7317.07, 5600.00,
                0, 8, 23.00, 3542.51, 3437.82, 4879.31, 3848.34,
                0, 16, 23.00, 1791.05, 1791.05, 3526.55, 2761.03,
                0, 32, 23.00, 491.15, 491.15, 2410.00, 1881.69,
                0, 64, 23.00, 0.00, 0.00, 1742.63, 1340.96,
                0, 128, 23.00, 0.00, 0.00, 990.27, 813.83,
                0, 256, 23.00, 0.00, 0.00, 631.58, 511.08,
                0, 512, 23.00, 0.00, 0.00, 588.51, 442.88,
                0, 1024, 23.00, 0.00, 0.00, 467.72, 337.25,
                0, 2048, 23.00, 0.00, 0.00, 203.53, 178.57,
                0, 4095, 23.00, 0.00, 0.00, 174.51, 144.30,
                1, 0, 23.00, inf, inf, inf, inf,
                1, 1, 23.00, inf, inf, inf, inf,
                1, 2, 23.00, inf, inf, inf, inf,
                1, 4, 23.00, inf, 25475000.00, inf, inf,
                1, 8, 23.00, 6719999.50, 3553571.25, inf, inf,
                1, 16, 23.00, 1760000.00, 1117857.12, inf, inf,
                1, 32, 23.00, 620422.56, 444148.93, inf, 510500.00,
                1, 64, 22.90, 252758.62, 196521.73, 254750.00, 126875.00,
                1, 128, 22.90, 115822.79, 92293.25, 77692.31, 50150.00,
                1, 256, 22.90, 55707.76, 46142.85, 35535.71, 25230.77,
                1, 512, 22.90, 28195.49, 24000.00, 18673.08, 13826.09,
                1, 1024, 22.90, 13540.51, 11681.22, 10000.00, 8216.22,
                1, 2048, 22.90, 6896.56, 6010.37, 5912.16, 4747.19,
                1, 4095, 22.90, 3333.33, 2814.07, 3628.96, 2996.09,
                0, 0, 22.90, inf, inf, inf, inf,
                0, 1, 22.90, 21640.91, 20636.80, 20765.96, 13826.09,
                0, 2, 22.90, 11681.22, 11316.65, 11787.50, 8385.32,
                0, 4, 22.90, 6896.56, 6784.96, 7818.97, 5820.00,
                0, 8, 22.90, 4069.17, 4175.15, 5515.92, 4166.67,
                0, 16, 23.00, 2197.80, 2300.00, 3871.43, 2949.81,
                0, 32, 23.00, 195.88, 195.88, 2157.41, 1757.41,
                0, 64, 22.90, 0.00, 0.00, 1609.69, 1258.28,
                0, 128, 22.90, 0.00, 0.00, 919.32, 772.96,
                0, 256, 22.90, 0.00, 0.00, 623.81, 517.80,
                0, 512, 22.90, 0.00, 0.00, 529.15, 411.03,
                0, 1024, 22.90, 0.00, 0.00, 459.34, 333.77,
                0, 2048, 22.90, 0.00, 0.00, 204.95, 179.93,
                0, 4095, 22.90, 0.00, 0.00, 174.51, 144.30,
                1, 0, 22.90, inf, inf, inf, inf,
                1, 1, 22.90, inf, inf, inf, inf,
                1, 2, 22.90, inf, inf, inf, inf,
                1, 4, 22.90, 11266666.00, 20360000.00, inf, inf,
                1, 8, 22.90, 6719999.50, 2908823.50, inf, inf,
                1, 16, 22.90, 1794444.50, 1132530.12, inf, inf,
                1, 32, 22.90, 620422.56, 444148.93, inf, 510500.00,
                1, 64, 22.90, 252758.62, 191452.98, 254750.00, 126875.00,
                1, 128, 22.90, 117197.45, 93383.75, 84250.00, 52842.10,
                1, 256, 22.90, 54531.72, 48046.32, 38346.15, 25921.05,
                1, 512, 22.90, 28195.49, 23849.88, 18673.08, 13826.09,
                1, 1024, 22.90, 13666.67, 11681.22, 9882.98, 7818.97,
                1, 2048, 22.90, 6673.62, 5900.62, 5865.77, 4779.66,
                1, 4095, 22.90, 3125.00, 2710.84, 3628.96, 2996.09,

                Comment


                • #23
                  Sorry for slow replies - forum subscribed thread email updates are not working for me. Are they working for others?

                  Here is your table as a pdf so it's easier to read:LDR 2.pdf

                  Sorry the data is not clear to me.
                  1) The yellow and orange entries were apparently measured under the same PWM, 33k and temperature so why is the resistance so different?
                  2) How does the data in columns 5 and 6 differ? Both were done with 100k.
                  3) How does the data in columns 7 and 8 differ? Both were done with 10k.

                  These really are a drop in for many vactorls at a great price. I see they do a LCR-0203 in an axial package like the vactrols too.
                  Last edited by nickb; 12-31-2017, 01:50 PM.
                  Experience is something you get, just after you really needed it.

                  Comment


                  • #24
                    As for the yellow values, I've no idea, but yesterday evening, back home, I've lounched another simulation, with steps of one instead of poowers of two.

                    Here below the results, and attached the txt file of all the data and here below the code.

                    LDR resistance vs PWM control: 33k in series with the led, and 100 kOhm as voltage divider to ground.
                    Click image for larger version

Name:	LCR-0202-33k-bypassed-100k-leak-A&amp;B.jpg
Views:	1
Size:	66.0 KB
ID:	848097


                    LDR resistance vs PWM control: 33k in series with the led, and 1 kOhm as voltage divider to ground.
                    Click image for larger version

Name:	LCR-0202-33k-bypassed-1k-leak-C&amp;D.jpg
Views:	1
Size:	69.8 KB
ID:	848098

                    Both previous data in the same plot.
                    Click image for larger version

Name:	LCR-0202-33k-bypassed-A&amp;B&amp;C&amp;D.jpg
Views:	1
Size:	77.2 KB
ID:	848099

                    Code:
                    #include <Wire.h>
                    
                    //to manage the LCR-0202s
                    #include <Adafruit_PWMServoDriver.h>
                    Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
                    
                    //just to show results
                    #include <LiquidCrystal_I2C.h>
                    LiquidCrystal_I2C lcd(0x27, 20, 4);
                    
                    //to read ambient temperature
                    #include <SimpleDHT.h>
                    int pinDHT22 = 2;
                    SimpleDHT22 dht22;
                    float temperature = 0;
                    float humidity = 0;
                    
                    //just an array of 2^n
                    //int pwm_values[] = {0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4095};
                    
                    //analog readings in voltage dividers
                    int a_read[] = {0, 0, 0, 0};
                    
                    //LCR-0202 initial resistance values
                    float LCR_ohm[] = {0, 0, 0, 0};
                    
                    //define "leak" resistors in voltage dividers
                    unsigned long bottomR_ohm[] = {100000, 100000, 1000, 1000};
                    
                    void setup() {
                      //PWM startup
                      pwm.begin();
                      pwm.setPWMFreq(1500); //to avoid wavering of the light
                    
                      //LCD startup
                      lcd.init();
                      lcd.backlight();
                      lcd.clear();
                    
                      // Serial startup
                      Serial.begin(9600);
                    }
                    
                    void loop() {
                      for (int b = 0; b < 2; b++) {
                        for (int i = 1; i < 4096; i++) {
                          for (int led_num = 0; led_num < 5; led_num++) {
                            pwm.setPWM(led_num, 0, (4095 - i));
                          }
                          read_values();
                          show_values(b, i);
                        }
                        for (int led_num = 8; led_num < 13; led_num++) {
                          pwm.setPWM(led_num, 0, (4095 * b));
                        }
                      }
                    }
                    
                    void read_values() {
                      delay(1000);
                      dht22.read2(pinDHT22, &temperature, &humidity, NULL);
                      for (int gpio = 0; gpio < 4; gpio++) {
                        a_read[gpio] = analogRead(gpio);
                        LCR_ohm[gpio] = ((1023.00 / a_read[gpio]) - 1) * bottomR_ohm[gpio];
                      }
                    }
                    
                    void show_values(int b, int i) {
                      lcd.clear();
                      lcd.print("Robi's LCR-0202 Test");
                    
                      lcd.setCursor(0, 1);
                      lcd.print("bit");
                      lcd.print(b);
                      Serial.print(b);
                      Serial.print("  ");
                    
                      lcd.setCursor(6, 1);
                      lcd.print("PWM");
                      lcd.print(i);
                      Serial.print(i);
                      Serial.print("  ");
                    
                      lcd.setCursor(14, 1);
                      lcd.print("T");
                      lcd.print(temperature);
                      Serial.print(temperature);
                      Serial.print("  ");
                    
                      lcd.setCursor(0, 2);
                      lcd.print(LCR_ohm[0]);
                      Serial.print(LCR_ohm[0]);
                      Serial.print("  ");
                    
                      lcd.setCursor(0, 3);
                      lcd.print(LCR_ohm[1]);
                      Serial.print(LCR_ohm[1]);
                      Serial.print("  ");
                    
                      lcd.setCursor(10, 2);
                      lcd.print(LCR_ohm[2]);
                      Serial.print(LCR_ohm[2]);
                      Serial.print("  ");
                    
                      lcd.setCursor(10, 3);
                      lcd.print(LCR_ohm[3]);
                      Serial.println(LCR_ohm[3]);
                    }

                    Comment


                    • #25
                      Three plots with the 33k bupassed (only the SMD 220 Ohm resistor on the PCA9685 board):

                      LDR resistance vs PWM control: 220 Ohm in series with the led, and 100 kOhm as voltage divider to ground.
                      Click image for larger version

Name:	LCR-0202-33k-unbypassed-A&amp;B&amp;C&amp;D.jpg
Views:	1
Size:	77.3 KB
ID:	848100

                      LDR resistance vs PWM control: 220 Ohm in series with the led, and 1 kOhm as voltage divider to ground.
                      Click image for larger version

Name:	LCR-0202-33k-unbypassed-1k-leak-C&amp;D.jpg
Views:	1
Size:	69.9 KB
ID:	848101

                      Both previous data in the same plot.
                      Click image for larger version

Name:	LCR-0202-33k-unbypassed-100k-leak-A&amp;B.jpg
Views:	1
Size:	69.2 KB
ID:	848102

                      Comment


                      • #26
                        This is part of the data I've collected, limited by the forum's limit of txt files (1 MB ).
                        Attached Files

                        Comment


                        • #27
                          Instead of taking one sample for each PWM setting, take (say) 16 and average the results. That will give you an effective two extra bits of resolution and reduce the noise.

                          The tolerance is something like +/-20% based on this very small sample size. Not too bad really.
                          Experience is something you get, just after you really needed it.

                          Comment


                          • #28
                            Originally posted by nickb View Post
                            2) How does the data in columns 5 and 6 differ? Both were done with 100k.
                            3) How does the data in columns 7 and 8 differ? Both were done with 10k.
                            Column 7 and 8 have 1k to ground, not 10k. The difference in both cases are due to the fact that I use two LDRs for each trial (four parallel trials at the same time).

                            Comment


                            • #29
                              Originally posted by nickb View Post
                              Instead of taking one sample for each PWM setting, take (say) 16 and average the results. That will give you an effective two extra bits of resolution and reduce the noise.
                              That's logical, let's make it 1024 times, this will improve it even further. At the end I've nothing to do, the software does it all by itself, so no worries if it takes 1 hour or 4.
                              Give a look at the code here below.

                              Originally posted by nickb View Post
                              The tolerance is something like +/-20% based on this very small sample size. Not too bad really.
                              First trials with mean values of analog readings seem even better:
                              0, 385, 23.40, 51331.26, 48004.06, 55805.95, 28921.45
                              0, 449, 23.40, 43862.16, 41156.53, 43602.32, 24041.33
                              0, 513, 23.40, 38319.50, 36120.92, 35899.09, 20699.56
                              0, 577, 23.40, 34047.06, 32204.07, 30795.68, 18290.80
                              0, 641, 23.40, 30663.62, 29088.16, 27017.76, 16420.19
                              0, 705, 23.40, 27935.19, 26535.53, 24100.12, 14971.72
                              0, 769, 23.40, 25633.93, 24426.04, 21766.80, 13750.23
                              0, 833, 23.40, 23722.07, 22628.13, 19925.44, 12735.44
                              0, 897, 23.40, 22063.43, 21098.49, 18353.94, 11878.22
                              0, 961, 23.40, 20660.28, 19774.09, 17036.00, 11159.91
                              0, 1025, 23.40, 19382.92, 18599.71, 15945.69, 10541.60
                              0, 1089, 23.40, 18287.51, 17573.33, 14977.84, 9976.95
                              0, 1153, 23.40, 17314.19, 16650.28, 14148.49, 9497.52
                              Code:
                              #include <Wire.h>
                              
                              //to manage the LCR-0202s
                              #include <Adafruit_PWMServoDriver.h>
                              Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
                              
                              //just to show results
                              #include <LiquidCrystal_I2C.h>
                              LiquidCrystal_I2C lcd(0x27, 20, 4);
                              
                              //to read ambient temperature
                              #include <SimpleDHT.h>
                              int pinDHT22 = 2;
                              SimpleDHT22 dht22;
                              float temperature = 0;
                              float humidity = 0;
                              
                              //analog readings in voltage dividers
                              int a_read[] = {0, 0, 0, 0};
                              
                              //LCR-0202 initial resistance values
                              float LCR_ohm[] = {0, 0, 0, 0};
                              
                              //define "leak" resistors in voltage dividers
                              unsigned long bottomR_ohm[] = {100000, 100000, 1000, 1000};
                              
                              void setup() {
                                //PWM startup
                                pwm.begin();
                                pwm.setPWMFreq(1500); //to avoid wavering of the light
                              
                                //LCD startup
                                lcd.init();
                                lcd.backlight();
                                lcd.clear();
                              
                                // Serial startup
                                Serial.begin(9600);
                              }
                              
                              void loop() {
                                for (int b = 0; b < 2; b++) {
                                  for (int i = 1; i < 4096; i += 64) {
                                    for (int led_num = 0; led_num < 5; led_num++) {
                                      pwm.setPWM(led_num, 0, (4095 - i));
                                    }
                                    read_values();
                                    show_values(b, i);
                                  }
                                  for (int led_num = 8; led_num < 13; led_num++) {
                                    pwm.setPWM(led_num, 0, (4095 * b));
                                  }
                                }
                              }
                              
                              void read_values() {
                                delay(1000);
                                dht22.read2(pinDHT22, &temperature, &humidity, NULL);
                                for (int gpio = 0; gpio < 4; gpio++) {
                                  LCR_ohm[gpio] = 0;
                                  for (int num_read = 0; num_read < 1024; num_read++) {
                                    a_read[gpio] = analogRead(gpio);
                                    LCR_ohm[gpio] = LCR_ohm[gpio] + (((1023.00 / a_read[gpio]) - 1) * bottomR_ohm[gpio]);
                                  }
                                  LCR_ohm[gpio] = LCR_ohm[gpio] / 1024;
                                }
                              }
                              
                              void show_values(int b, int i) {
                                lcd.clear();
                                lcd.print("Robi's LCR-0202 Test");
                              
                                lcd.setCursor(0, 1);
                                lcd.print("bit");
                                lcd.print(b);
                                Serial.print(b);
                                Serial.print(", ");
                              
                                lcd.setCursor(6, 1);
                                lcd.print("PWM");
                                lcd.print(i);
                                Serial.print(i);
                                Serial.print(", ");
                              
                                lcd.setCursor(14, 1);
                                lcd.print("T");
                                lcd.print(temperature);
                                Serial.print(temperature);
                                Serial.print(", ");
                              
                                lcd.setCursor(0, 2);
                                lcd.print(LCR_ohm[0]);
                                Serial.print(LCR_ohm[0]);
                                Serial.print(", ");
                              
                                lcd.setCursor(0, 3);
                                lcd.print(LCR_ohm[1]);
                                Serial.print(LCR_ohm[1]);
                                Serial.print(", ");
                              
                                lcd.setCursor(10, 2);
                                lcd.print(LCR_ohm[2]);
                                Serial.print(LCR_ohm[2]);
                                Serial.print(", ");
                              
                                lcd.setCursor(10, 3);
                                lcd.print(LCR_ohm[3]);
                                Serial.println(LCR_ohm[3]);
                              }

                              Comment


                              • #30
                                I report here the values of the 250k, 500k and 1M log pots based on the formula
                                resistance = nominal value * (%Rot)^3.3

                                Code:
                                %Rot   250 k   500 k   1 M
                                0%   0,00   0,00   0,00
                                2%   0,00   0,00   0,00
                                4%   0,01   0,01   0,02
                                6%   0,02   0,05   0,09
                                8%   0,06   0,12   0,24
                                10%   0,13   0,25   0,50
                                12%   0,23   0,46   0,91
                                14%   0,38   0,76   1,52
                                16%   0,59   1,18   2,36
                                18%   0,87   1,74   3,49
                                20%   1,23   2,47   4,94
                                22%   1,69   3,38   6,76
                                24%   2,25   4,50   9,01
                                26%   2,93   5,87   11,73
                                28%   3,75   7,49   14,98
                                30%   4,70   9,41   18,81
                                32%   5,82   11,64   23,28
                                34%   7,11   14,22   28,44
                                36%   8,58   17,17   34,34
                                38%   10,26   20,52   41,05
                                40%   12,15   24,31   48,62
                                42%   14,28   28,56   57,11
                                44%   16,65   33,29   66,59
                                46%   19,28   38,55   77,11
                                48%   22,18   44,37   88,74
                                50%   25,38   50,77   101,53
                                52%   28,89   57,78   115,56
                                54%   32,72   65,44   130,89
                                56%   36,89   73,79   147,58
                                58%   41,42   82,85   165,70
                                60%   46,33   92,66   185,31
                                62%   51,62   103,24   206,49
                                64%   57,32   114,65   229,29
                                66%   63,45   126,90   253,80
                                68%   70,02   140,04   280,08
                                70%   77,05   154,10   308,19
                                72%   84,55   169,11   338,22
                                74%   92,56   185,11   370,22
                                76%   101,07   202,14   404,28
                                78%   110,12   220,23   440,47
                                80%   119,71   239,42   478,85
                                82%   129,88   259,75   519,50
                                84%   140,62   281,25   562,50
                                86%   151,98   303,96   607,92
                                88%   163,96   327,92   655,83
                                90%   176,58   353,16   706,32
                                92%   189,86   379,73   759,45
                                94%   203,83   407,65   815,31
                                96%   218,49   436,98   873,97
                                98%   233,88   467,75   935,50
                                100%   250,00   500,00   1000,00

                                Comment

                                Working...
                                X