marcantoinegodde / HagerEE003_HomeKit

1 stars 0 forks source link

connection diagram #1

Open putnik161 opened 2 years ago

putnik161 commented 2 years ago

Hey the question is, you can get your sensor connection diagram with all denominations. thanks.

marcantoinegodde commented 2 years ago

Hello, this was a small personal project. I just shared the code, that is why it is not well documented. I will give you some explanation.

The project was realized on a NodeMCU v3 Lolin. It uses a simple tension divider. The input uses a 3.3V pin and the measurement is realized with the ADC (pin A0). You also might have to tune R1, VMCU, VIN variables according to your board. You'll need to change the SSID and the Password to connect on your Wireless network.

The scheme is the following one. Vout is A0 and the voltage isn't 5V but 3.3V. https://cdn.sparkfun.com/assets/learn_tutorials/6/3/6/voltage_divider.png

Hope that will help. :)

putnik161 commented 2 years ago

Thank you, I figured out the connection, I need help In my code, the data is displayed incorrectly, that is, in daylight it shows 7 lux and at night for 10,000 lux. void my_homekit_report() { float read = analogRead(A0); float Vout = (read VMCU)/1024; float Rlux = (VoutR1)/(VIN-Vout); float lux_value = pow(10, -1.17*log10(Rlux)+6.12); cha_current_ambient_light_level.value.float_value = lux_value;

LOG_D("Current light level: %.1f", lux_value);
homekit_characteristic_notify(&cha_current_ambient_light_level, cha_current_ambient_light_level.value);

}

marcantoinegodde commented 2 years ago

Rlux is the value of resistor calculated with a voltage divider.

Then, we obtain the lux_value. I estimated the law of the photoresistor with values which are included in the repo. You have to do the same with your own photoresistor. You can find info about the law on Google.