I am supposed to use an LDR and an RGB LED to create a circuit that changes colour (show 7 possible colours) with different levels of illumination. I don't know how to connect the photoresist to the circuit and how to program it. Can someone help?
Connect your photoresistor as a voltage divider and connect to an analogue pin.
Your post was MOVED to its current location as it is more suitable.
Could you also take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.
Hello miyukiharuto
Post your sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.
Connect the photoresistor to an analog pin of your Nano and ground. Using any of A0 to A5, set pinMode on that pin to INPUT_PULLUP and use analogRead to read the voltage. ![]()
How does one get Arduino assignment in school? It is not like this is essential subject like English or Math
This is the schematic. And this is the code
// C++ code
//
int i = 0;
int counter;
void setup()
{
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
}
void loop()
{
analogWrite(11, 255);
analogWrite(10, 102);
analogWrite(9, 102);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(11, 102);
analogWrite(10, 255);
analogWrite(9, 255);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(11, 255);
analogWrite(10, 0);
analogWrite(9, 0);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(11, 255);
analogWrite(10, 255);
analogWrite(9, 51);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(11, 204);
analogWrite(10, 51);
analogWrite(9, 204);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(11, 0);
analogWrite(10, 0);
analogWrite(9, 102);
delay(1000); // Wait for 1000 millisecond(s)
analogWrite(11, 51);
analogWrite(10, 51);
analogWrite(9, 51);
for (counter = 0; counter < 10; ++counter) {
}
}
It works, but my problem is I need to include a photoresistor and I don't know where should a connect it and how to include it on the code.
I just told you.
Hello miyukiharuto
Take some time and study the map() and analogRead() function.
Have a nice day and enjoy coding in C++.
p.s. You may start using a potentiometer instead of a LDR.
Hi!
I think you should take a look in this topic --> https://forum.arduino.cc/t/new-project-input/955289/33
The project is a little bit different of yours, but your questions are probably all answered during the discussion.
No your problem is you don't know what the photo resistor should do in your project. At least if you do know you are keeping it a secrete.
First learn how to use a photoresistor.
Google "arduino photoresistor" for examples and tutorials.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
