pins of interrupts and lcd interfacing

In my project i am interfacing lcd to atmega328. I want to use interrupt at digital pin 2…but both interrupt pins are used in lcd…therefore i connected one lcd pin to digital pin 7 instead of pin pin 2… and used pin 2 for interrupt … but i am getting random characters…please give me some solutions…

please give me some solutions

Write the code correctly.
Eliminate noise everywhere.

If you told us what kind of LCD, and showed the code you are using, and explained when/how random characters appear, and explained what is generating the external interrupt, we (I) might be more helpful.

I am using 16 pin lcd and modified only one connection of pin 2 from connections given in arduino tutorial…
In my code i am testing alcohol and taking necessary actions like stoping motor , displaying on lcd… I am also using ultrasonic sensor and when output of it goes high interrupt is given on pin 2… given below is my code…

#include <LiquidCrystal.h>
#include <avr/interrupt.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 7);
int MQ3Pin=2;
int MotorPin =9;

void setup()
{
lcd.begin(16,2);
attachInterrupt( 0,stopmotor,RISING);
interrupts();
}

void stopmotor()
{
analogWrite(MotorPin,0);
delay(5000);
lcd.print(" Stop");
delay(1000);
lcd.clear();
}

int MQ3testing()
{
lcd.print("m in MQ3testing ");
delay(5000);
lcd.clear();
int Speed;
int MQ3sensor;
int i;

Speed=analogRead(MotorPin);
lcd.print(Speed);
delay(5000);
lcd.clear();
MQ3sensor=analogRead(MQ3Pin);
lcd.print(MQ3sensor);
delay(5000);
lcd.clear();
while (MQ3sensor >500)
{
lcd.print(“cont. high”);
delay(5000);
lcd.clear();
for(i=Speed; i>0; i-=50)
{

lcd.print(" m in for loop");
analogWrite(MotorPin,i);
delay(10000);
lcd.clear();

}
lcd.print(“m outside”);
delay(1000);
lcd.clear();
if(i<0)
{
lcd.print(“wait…”);
delay(1000);
lcd.clear();
delay(10000);
return 1;
}
}
}

void loop()
{

lcd.setCursor(0,1);
int j;
int t;
int env;
label:
int MQ3Sensor;
lcd.print(“final”);
delay(1000);
env = analogRead(MQ3Pin);
lcd.print(env);
delay(1000);
lcd.clear();
do
{
do
{
lcd.print(“TEST ALCOHOL”);
delay(1000);
lcd.clear();
MQ3Sensor=analogRead(MQ3Pin);
lcd.print(MQ3Sensor);
delay(1000);
lcd.clear();
}while(MQ3Sensor==env);
if(MQ3Sensor > 600)
{
lcd.print(“High alcohol”);
delay(30000);
lcd.clear();
break;
}
}while(MQ3Sensor >600 );
lcd.print(" u can drive");
delay(1000);
lcd.clear();
for(j=0;j<200;j+=50)
{
lcd.print("reached ");
delay(1000);
lcd.clear();
analogWrite(MotorPin,j);
lcd.print(j);
delay(1000);
lcd.clear();
t=MQ3testing();
if(t==1)
{
goto label;
}
}
while(j==200)
{
lcd.print(“constant speed”);
delay(5000);
lcd.clear();
t=MQ3testing();
if(t==1)
{
goto label;
}
delay(1000);
lcd.clear();

}

}
/code]

Can you use [ code ] tags please?

attachInterrupt( 0,stopmotor,RISING);

...

void stopmotor()
{
  analogWrite(MotorPin,0);
  delay(5000);
  lcd.print(" Stop");
  delay(1000);
  lcd.clear();
}

I would not personally be putting a 5-second delay into an interrupt service routine. Plus, delay() will not work in it.

Of the code that is in the interrupt service routine, the [u]only[/u] statement that belongs there is the one to stop the motor. The routine should set a flag that tells loop that it needs to print the message and twiddle its thumbs for a while.