Go Down

Topic: Project 11 -> Photoresistor instead of Tilt sensor (Read 3083 times) previous topic - next topic

patalanov


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: [Select]
#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;
     
      }
    }
  }

Fabio881

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:

Go Up