Go Down

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


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
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy