LCD Assitance

Hello,

I am looking for some assistance with making text appear on an LCD when a hall effect sensor is triggered.

I have an Arduino UNO Rev3 and a bread board with a 16 pin LCD screen and then a hall effect sensor hooked up to a bread board and to digital pin 9.

What I would like to accomplish is when the hall effect sensor is triggered by the magnet the word "On" would be displayed on the LCD screen.

Here is my code.

#include <LiquidCrystal.h>
int pin9 = 9;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  pinMode(pin9, INPUT); 
  lcd.begin(16, 2);
  lcd.clear();
}

void loop() {
pin9 = digitalRead(pin9);

 { if (pin9 = HIGH ); 
  lcd.setCursor(0,0);
  lcd.print("On");
  delay(1000);
}}

What happens currently is the display says "On" regardless of the hall effect sensor being on or off.
In the IF statement I have switched if (pin9 =) to both HIGH and LOW and the result is still the same.

Any assistance would be appreciated.

Thank You!
thephatcat

pin9 = digitalRead(pin9);

DigitalRead will return either a 1 or 0 (HIGH or LOW). So you just set the pin to be read the next time through loop() to pin 1 or pin 0. Use a different variable name for the result of the digital read.

pin9State = digitalRead(pin9);
{ if (pin9 = HIGH );

A few things wrong there. The { is in the wrong place, single = is for assignment (as in a = b means a is now equal to b) double == is for comparison (a == b means is a the same value as b?) which is what you want in an if statement and the semi colon at the end will make the if statement not execute any thing after the if conditionally. The if statement reference.

void loop() 
{
  pin9State = digitalRead(pin9);
   if (pin9State == HIGH )
  {
    lcd.setCursor(0,0);
    lcd.print("On");
    delay(1000);
  }
}

You might want an else clause after the if block to print something else to the LCD if the hall sensor goes off, or once the "On" is printed there is nothing to turn it off and "On" will stay.

Did you make sure your LCD is working by just printing something to it. ?

Best to get one thing working at a time, then add the next thing, make sure that works then the next thing.