Hello, I have made a project using OLED display and photoresistor. It is supposed to display a message on the OLED display based on the level of sunlight, which is measured by the photoresistor. Although the code compiles, I think there is an issue because it doesn't work. I am sure there is no hardware issue because both components work with other codes, just not mine.
Here is the code:
Please describe what you expect the program to do, and what it does instead.
Please post a picture of a hand drawn wiring diagram, with pins, parts and connections clearly labeled. A close up, focused picture of your setup would be useful, too, as there may be a wiring error.
It is supposed to display different messages on the OLED display, for example, if the analog value of the sensor is more than 500, it will say "Today is very sunny!" etc. however, it allways displays the same message, " Today is very cloudy!" even when the sensor's value is above 500. I don't think a wiring diagram would be necessary, as I already said that my components are working fine (and tested them with different codes).
The problem may exist in your circuit connection too. Please troubleshoot part by part. First check the photoresistor part. Just run a simple code. Print its output value to the serial monitor to see if it is really responding to light intensity. Then check your OLED by printing a 'Hello world' message.
Yes I have done this multiple times. I use the light in my room as a tester. According to the serial monitor, the value of the sensor is around 600 when the light is on, and around 200 when the light is off.
The code works. Maybe a broken LDR or your threshold values need adjusting. Per my previous email, the mapping is upside down (max lux reports cloudy, min lux reports sunny).
I hope you realize you have no need for the sensor to test the rest of the code. Skip the analog read, plug in simple values(try values above and below any conditional thresholds), and see what your code does. Then, add in the read, but also use Serial Monitor to track what your analog read is giving you for values.
Or, add the analog readout to your displayed "conditions". For example, "LDR 102 cloudy today" would give you an idea of what's going on in the code.