Pages: [1]   Go Down
Author Topic: Project 11 -> Photoresistor instead of Tilt sensor  (Read 2946 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


In project 11 - The Crystall Ball, I'm trying to use a photoresistor instead of the tilt sensor.
So, every time I put my hand over the photoresistor (given a constant light source in the room) and cast a shadow over it,
the new current value (different from initial value) would trigger the random answers.
But no characters show up on the LCD. It only lightens up.
What am I doing wrong?
Here's the code:

Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int sensorPin = A0;
int sensorValue;
int sensorTop = 1023;
int initialSensorValue;
int reply;
void setup() {
  Serial.begin(9600);
  lcd.begin(16, 2);
  pinMode(sensorPin, INPUT);
  lcd.print("Ask");
  lcd.setCursor(0, 1);
  lcd.print("Mighty Mithras");
  sensorValue = analogRead(sensorPin);
  if (sensorValue < sensorTop) {
    sensorTop = initialSensorValue;
  }
}
void loop() {
 
  sensorValue = analogRead(sensorPin);
  Serial.print(sensorValue);
  if (sensorValue < initialSensorValue) {
    reply = random(8);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("The Ball says:");
    lcd.setCursor(0, 1);
    switch (reply) {
      case 0:
      lcd.print("Yes");
      break;
      case 1:
      lcd.print("Most likely");
      break;
      case 2:
      lcd.print("Certainly");
      break;
      case 3:
      lcd.print("Outlook Good");
      break;
      case 4:
      lcd.print("Unsure");
      break;
      case 5:
      lcd.print("Ask Again");
      break;
      case 6:
      lcd.print("Doubtful");
      break;
      case 7:
      lcd.print("No");
      break;
     
      }
    }
  }


* photo.JPG (2677.95 KB, 3264x2448 - viewed 63 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi patalanov,

a really trivial question: have you tried to play with the potentiometer that controls the contrast of the lcd screen?
It might seem stupid, but the first time ever I used an lcd screen, for this very same project, I experienced something similar: I could see the screen lighting up, but no text appearing. After checking all the possible connections and finding no problems, I simply turned the potentiometer to the max. value and well...I realized that the text has actually been there under my nose all the time...  smiley-roll-sweat
Logged

Pages: [1]   Go Up
Jump to: