Hi everybody,
I'm doing some tests on some cheap LDRs called LCR-0202 (they can be found on various cheap music equipments), that I want to share.
The purpose is to find a correlation between the PWM used to control them (supplied with 5V), and their resistance.
The needed material is:
- an Arduino (I'm using a Mega 2560, but every Arduino can be used, from Nano to Uno to Due, etc...);
- a DHT22 temperature and humidity sensor;
- a PCA9685 16 channel 12 bit PWM controller;
- up to 16 LCR-0202 to be tested (the limit is the number of PWM outputs of the PCA9685 and the number of analog inputs of the Arduino);
- one LED to have a visual feedback of the actual PWM;
- a 20x4 LCD screen (can be a 16x2 too, it just needs to be redrawn).
In the attached photos you'll see the values of four LCR-0202s shown on screen:
Second line shows the actual PWM command (the lower the value, the lower the current through the led, so the higher the resistance of the LDR), and the actual ambient temperature.
Third and fourth lines show the actual value in Ohms of the four LDRs.
This is the code:
I'm doing some tests on some cheap LDRs called LCR-0202 (they can be found on various cheap music equipments), that I want to share.
The purpose is to find a correlation between the PWM used to control them (supplied with 5V), and their resistance.
The needed material is:
- an Arduino (I'm using a Mega 2560, but every Arduino can be used, from Nano to Uno to Due, etc...);
- a DHT22 temperature and humidity sensor;
- a PCA9685 16 channel 12 bit PWM controller;
- up to 16 LCR-0202 to be tested (the limit is the number of PWM outputs of the PCA9685 and the number of analog inputs of the Arduino);
- one LED to have a visual feedback of the actual PWM;
- a 20x4 LCD screen (can be a 16x2 too, it just needs to be redrawn).
In the attached photos you'll see the values of four LCR-0202s shown on screen:
Second line shows the actual PWM command (the lower the value, the lower the current through the led, so the higher the resistance of the LDR), and the actual ambient temperature.
Third and fourth lines show the actual value in Ohms of the four LDRs.
This is the code:
Code:
#include <Wire.h> //to manage the LCR-0202s #include <Adafruit_PWMServoDriver.h> Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); //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[] = {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 = 1000; float bottomR2_ohm = 1000; float bottomR3_ohm = 1000; float bottomR4_ohm = 1000; void setup() { //PWM startup pwm.begin(); pwm.setPWMFreq(500); //to avoid wavering of the light //LCD startup lcd.init(); lcd.backlight(); lcd.clear(); } void loop() { for (int i = 0; i < 13; i++) { for (int led_num = 0; led_num < 6; led_num++) { pwm.setPWM(led_num, 0, (4095 - pwm_values[i])); } show_values(i); } } void show_values(int i) { lcd.clear(); lcd.print("Robi's LCR-0202 Test"); lcd.setCursor(0, 1); lcd.print("PWM "); lcd.print(pwm_values[i]); lcd.setCursor(10, 1); dht22.read2(pinDHT22, &temperature, &humidity, NULL); lcd.print("Temp "); lcd.print(temperature); lcd.setCursor(0, 2); a_read1 = analogRead(0); LCR1_ohm = ((1023 * bottomR1_ohm) / a_read1) - bottomR1_ohm; lcd.print(LCR1_ohm); lcd.setCursor(10, 2); a_read2 = analogRead(1); LCR2_ohm = ((1023 * bottomR2_ohm) / a_read2) - bottomR2_ohm; lcd.print(LCR2_ohm); lcd.setCursor(0, 3); a_read3 = analogRead(2); LCR3_ohm = ((1023 * bottomR3_ohm) / a_read3) - bottomR3_ohm; lcd.print(LCR3_ohm); lcd.setCursor(10, 3); a_read4 = analogRead(3); LCR4_ohm = ((1023 * bottomR4_ohm) / a_read4) - bottomR4_ohm; lcd.print(LCR4_ohm); delay(2000); }
Comment