Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a device that is responsive to changes in light level. Write a program th

ID: 3590958 • Letter: C

Question

Create a device that is responsive to changes in light level. Write a program that compares the photoresistor circuit’s output voltage to the potentiometer circuit’s output. If the potentiometer circuit voltage is higher, the program should turn on the LED. If on the other hand, the photoresistor voltage is higher, the LED should turn off. This means that if you pass your hand over the sensor, the LED should turn on. Play with the circuit – as you turn down the potentiometer, it should be increasingly hard to get the LED to turn on, and vise-versa. This type of device is (not surprisingly) called a comparator because it compares two voltages, reacting one way if the first voltage is higher than the second, a different way if the second voltage is higher than the first. Comparators have a huge range of applications.  

please make sure that I am taking the first class on Arduino so the code for this project must be simple as much as possible.

Explanation / Answer

Solution=====================

int ledPin = 13;   //the number of the LED pin
int ldrPin = A0; //the number of the LDR pin
int potentiotPin = A1; //the number of the Potentiometer


void setup() {
pinMode(ledPin, OUTPUT); //initialize the LED pin as an output
pinMode(ldrPin, INPUT);   //initialize the LDR pin as an input
pinMode(potentiotPin, INPUT);   //initialize the Potentiometer pin as an input
}

void loop() {

//Reading voltages from both sources
int voltageAtPotentiometer = analogRead(potentiotPin);
int voltageAtLDR = analogRead(ldrPin);

//If the potentiometer circuit voltage is higher
if(voltageAtPotentiometer > voltageAtLDR){
//the program should turn on the LED
digitalWrite(ledPin,HIGH); //Turning the LED on
}
//If the photoresistor voltage is higher
else if(voltageAtPotentiometer < voltageAtLDR){
// the LED should turn off
digitalWrite(ledPin,LOW); //Turning the LED off
}

}

Let me know if any doubts...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote