I’m trying to get a readout of the photoresistor resistance, however the value is outputted at a constant and does not appear to change (stays at around 75,000). The value of the Lux however appears correct. Below is a photo and my code.
My Vout also stays constant at 0.2. The exact readings of R2 are 75,238. I am unsure why this is happening since my peers have the same setup as I do, however they are using an Arduino Uno. That is why I have 4095.0 in my code for Vout. Do you think this is a photoresistor issue?
I think there is 50% chance it is a wiring, broken wires, glue on the legs of the components or a breadboard with bad contacts.
Do you have a multimeter ? Can you measure that indeed 0.2V is going to A2 ?
If you don't have a multimeter then use other jumper wires and an other location on the breadboard.
A have not heard of a broken photoresistor (LDR) yet. Can you try a different LDR ?
What happens if you connect GND to A2 and then 3.3V to A2 ?
Can you replace the LDR with a few resistors to check if the printed values are changing ?
We prefer that you copy the output of the Serial Monitor to show it to us. Now you sometimes use a comma and sometimes a dot in a floating point number
The language is "English" but this is international English. I always have to try really hard to not make fun of people who use nose-length or feet for length and a bottle of milk for volume
An int variable cannot hold 3.3. it will be truncated to 3.
However, this value does not, or should not, matter in the calculation. If your formulae were correct, the value of Vin would "cancel out" at some point in the calculation. But I can see that this won't happen, so the formulae must be incorrect.
The equation you need to use its simply this:
raw / 4095 = Rfixed / (Rfixed+Rldr)
You need to solve the equation for Rldr and use that formula in your code.
This circuit shows a common simplistic misunderstanding. The LDR is conencted wbtween piin and Vcc so as it conducts more, it pulls up to 5 V - against the pull-down resistor whcih is some "220" value I cannot quite discern because these blue 1% metal film resistors are hard to read even in good light, let alone a photo.
While this arrangement seems "logical" it is generally bad design. Particularly where the sensor - the LDR in this case - is to be mounted at the end of a cable, it is much more sensible to have it between the pin and ground and with a pull-up resistor to 5 V adjacent to the Arduino (or other microcontroller).
Only the ground need be taken out to external components, thus avoiding any danger of the 5 V supply being accidentally shorted out - or picking up or radiating interference.
The inverted sense of the readings made of the sensor is dealt with in the coding and involves no additional complexity.
raw input data =19
raw input data =19
raw input data =18
raw input data =18
raw input data =19
raw input data =17
raw input data =16
raw input data =15
raw input data =17
raw input data =16
raw input data =16
raw input data =16
raw input data =16
raw input data =16
raw input data =16
This is what the serial monitor displays after a few iterations with the code you have provided. I do not have a DMM.
If the resistor in series with the LDR is 220 R then that will not help. As a starter measure the LDR resistance with the light on and set the series resistor to around this value .
Would you assume my problem is instead affiliated with the code and not the circuit? I am still receiving a constant photoresistor resistance value. I am not sure what can be wrong with the circuit I constructed above.
I am trying to plot how the lux vs resistance changes with different resistor values. I removed the resistor and the photoresistor measures at a constant value of 621. I am not understanding why this value is constant, it should not be as the LED gets brighter by the for loop.