![]()
The readout for this project consists of a static top line of text “Brightness:” and a second line showing the value coming from the photoresistor. If you have not already done so, you need to install a library. These are easy to install and only need to be installed once. Go to Tools / Manage Libraries and search for (and install) LiquidCrystal.
1 220 Ohm Resistor 1 10K Ohm Resistor 1 Potentiometer 1 Photoresistor 1 Arduino UNO R3 1 Breadboard Connector Wires
Code:
//------------- Code Starts Here ---------------------------- //----------------------------------------- //Published by IntroductionToArduino.com //Created by Paul Illsley (www.paulillsley.com) //Please use and share so others can enjoy //----------------------------------------- // including the LiquidCrystal library #include <LiquidCrystal.h> // assigning LCD pins to arduino pin numbers const int rs = 12; const int en = 11; const int d4 = 5; const int d5 = 4; const int d6 = 3; const int d7 = 2; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); // creating an integer (int) variable called “light” to hold the photoresistor value int light; void setup() { // declaring the number of columns and rows in the LCD (16 characters and 2 rows) lcd.begin(16, 2); // print text to the LCD. This will stay on the top line lcd.print("Brightness:"); } void loop() { // reading the value from pin A1 (the photoresistor) and placing it in "light" light = analogRead(A1); // set the cursor location to column 0, line 1 (this is the second line since the first line would be 0,0) lcd.setCursor(0, 1); // print the photoresistor value lcd.print(light); // delay 500 milliseconds (0.5 seconds) to make the display easier to read (this delay is optional) delay(500); } //------------- Code Stops Here ----------------------------
Return to www.introductiontoarduino.com
|