7th Inning
Jump to navigation
Jump to search
Introduction
Photocells and thermistors Here we set up voltage dividers for a photocell and a thermistor The code works the same as the potentiometer! Both the photocell and the thermistor are 3K so we set the voltage divider up with 3K resistors (orange-black-red)
Components Needed
- Freeduino or Arduino or clone
- USB cable for Freeduino
- Freeduino development software - download here!
- Solderless Breadboard
- Hookup wire 22gauge solid
How to
- See the fritzing diagram
Schematic
The schematic was to confusing on the Fritzing program. I will try to make it cleaner...
Fritzing
Code
//This code builds upon Inning 5 by //showing the value of a pot on analog 0 //bpw 5/11/10 // include the library code: #include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins LiquidCrystal lcd(7, 8, 9, 10, 11, 12); int inPin = 2; // choose the input pin (for a pushbutton) int val = 0; // variable for reading the pin status int potpin = 0; // analog pin 0 int potval = 0; // variable for reading the pin status int pcpin = 1; // analog pin 1 - photocell int pcval = 0; // variable for reading the pin status int thpin = 2; // analog pin 2 - thermistor int thval = 0; // variable for reading the pin status void setup() { // set up the LCD's number of rows and columns: lcd.begin(16, 2); // Print a message to the LCD. //lcd.print("hello, world!"); pinMode(inPin, INPUT); // declare pushbutton as input } void loop() { // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis()/1000); lcd.setCursor(6, 1); //col 6, row 1 //code for button pressed! val = digitalRead(inPin); // read input value if (val == LOW) { // check if the input is HIGH (button released) lcd.print("DOWN"); } else { lcd.print("UP "); } //read the pot - values are 0..1023 lcd.setCursor(12, 1); //col 12, row 1 lcd.print(" "); potval = analogRead(potpin); // read the value from the (center lead of ) potentiometer connected to potpin lcd.setCursor(12, 1); //col 12, row 1 lcd.print(potval); //read the photocell - values are 0..1023 lcd.setCursor(0, 0); //col 12, row 1 lcd.print("PC:"); pcval = analogRead(pcpin); // read the value from the photocell circuit lcd.print(pcval); //read the thermistor - values are 0..1023 lcd.print(" Th:"); thval = analogRead(thpin); // read the value from the thermistor circuit lcd.print(thval); }