I’ve been playing with my Cadmium Sulfide (CdS) photoresistors, and have put together a basic light sensor. I’m outputting raw values, so there is no correlation with solar insolation. If anyone knows some cool formulas that would convert the output to sun hours, I’d love to play with them. The wiring is documented in the code as follows:
Become the Maker you were born to be. Try Arduino Academy for FREE!
#include <LiquidCrystal.h>
/*
LCD Connections:
rs (LCD pin 4) to Arduino pin 12
rw (LCD pin 5) to Arduino pin 11
enable (LCD pin 6) to Arduino pin 10
LCD pin 15 to Arduino pin 13
LCD pins d4, d5, d6, d7 to Arduino pins 5, 4, 3, 2
Cds Connections:
CdS Pin 1 to +5v
CdS Pin 2 to Analog Pin 0
10k ohm resistor pin 1 to Analog Pin 0
10k ohm resistor pin 2 to Gnd
*/
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
int backLight = 13; // pin 13 will control the backlight
int sensorPin = 0;
int val = 0;
void setup() {
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace ‘HIGH’ with ‘LOW’ to turn it off.
lcd.begin(20, 4); // rows, columns. use 16,2 for a 16×2 LCD, etc.
lcd.clear(); // start with a blank screen
lcd.setCursor(0,0); // set cursor to column 0, row 0
lcd.print(“Light level is:”);
}
void loop() {
val = analogRead(sensorPin);
lcd.setCursor(0,1);
lcd.print (val);
delay(100);
}