Write an Arduino sketch that reads the sensor values from a photocell with the v
ID: 2998385 • Letter: W
Question
Write an Arduino sketch that reads the sensor values from a photocell with the values being in the middle of the range in ambient light. In your sketch, take this value as an input and program a red LED such that covering the cell completely (thus, depriving it of any measurable light) lights up the LED brightest, while flooding it with bright light makes LED glow the dimmest possible. For in-between values of the input, light up the LED in proportion to the darkness. This would be the idea behind an automatic light sensitive night lamp that now you can create and keep in your room. Use serial communication to show in serial monitor window the values read by the photocell, values being written to the LED.
Explanation / Answer
uint16_t last;
void setup() {
analogReference(DEFAULT);
Serial.begin(500000);
last = micros();
}
void loop() {
const uint16_t now = micros();
if (now - last < 1000)
return;
last += 1000;
const int v = analogRead(0);
Serial.println(v);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.