Advertisement
zoro-10

Temperature sensor

Apr 1st, 2024 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. https://imgur.com/a/Zv4ioBx
  2.  
  3.  
  4. int lightSensorValue = 0; // Variable to store the light sensor reading
  5. void setup()
  6. {
  7.   pinMode(A0, INPUT); // Set A0 pin as an input for the light sensor
  8.   pinMode(9, OUTPUT); // Set pin 9 as an output to control the LED
  9.   Serial.begin(9600); // Initialize serial communication at 9600 baud
  10. }
  11. void loop()
  12. {
  13.   lightSensorValue = analogRead(A0);
  14.   // Read the light sensor value
  15.   Serial.println(lightSensorValue);
  16.   // Print the sensor value to the Serial Monitor
  17.   int ledBrightness = map(lightSensorValue, 0, 1023, 0, 255);
  18.   // Map the sensor value to LED brightness
  19.   analogWrite(9, ledBrightness);
  20.   // Control LED brightness based on the sensor reading
  21.   delay(100);
  22.   // Wait for 100 milliseconds before the next loop iteration
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement