Hi fellow Arduinians,
I set up a PIR motion sensor and an LCD (20x4) to UNO. PIR is ground, positive and also goes out to PIN 2. LCD is connected using Ladyadas tut.
My code is written to display whenever there is motion detected or not. Simple.
However, when I try to run this, the lcd becomes very static and unable to read. With some letters faded out and so on. Does anyone know why? I am guessing this is due to voltage (either too much or too low) with PIR sensor messing it up somehow.
However, while not changing my connection in anyway, if I just run a sketch to display Hello World on the LCD it works perfectly, once I include the code to use PIR sensor (pretty much exact copy of code posted in ladyadas tut the LCD screen goes haywire.
So here is my code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
(somewhere here I indicate this is 20x4)
if ( val == HIGH )
lcd.setcursor(o,1);
lcd.print(“Motion”);
if ( val == LOW )
lcd.print(“No Motion”);
}
Thanks for any help....
Also, does anyone know if its possible to do a faster refrash rate on the PIR sensor. It seems like it detects motion and displays Motion detected for 6 seconds. Is there a way to make it instant? If there is motion display msg, and if the next second there is none display accordingly?
Thanks guys