I need the help for my final year project.. Question related to LM324.

Hi everyone. I am in trouble. Please help me as fast as you can. I am using LM324 comparator IC to compare the 12V battery voltages. Now I am giving 12v DC of Adapter to the Vcc of LM324 and 0v to Ground. I made 9v voltage from adapter using resistors and gave it to the Vref of LM324 means pin no 2. And i Connected +ve terminal of my 12v battery(which i want to connect to the Inverter) to the Vin terminal of LM324 which means pin no 3. LM324 works properly. It means whenever Vref<Vin then Vout(pin no 1 of LM324)= 11.89(this value is always fluctuating). And whenever Vref>Vin then Vout= 0v.
But I am facing the problem

void setup()
{
Serial.begin(9600);
pinMode(12,INPUT); // I connect output pin of LM324 at digital pin no 12 of arduino UNO
}

void loop()
{
int state = digitalRead(12);
if (state == HIGH)
{
Serial.println(“12 is high”);
}
else if (state == LOW)
{
Serial.println(“12 is low”);
}
delay(1000);
}

when i am using this code to check the state of output of LM324 if the answer always fluctuate between HIGH and LOW when Vref<Vin, also it happens in Vref>Vin.
So, this Fluctuation problem of arduino became Headache for me. I know that I have to minimize the voltage level and keep it at 5v, and i had done that but still answer is fluctuating. Please Help fast guys. I am in big trouble :confused: :confused: :disappointed_relieved: .

I know that I have to minimize the voltage level and keep it at 5v, and i had done that

How? Post a schematic, please.

And hopefully the schematic will show how you have wired the grounds, it looks like this is the problem.

I can upload Circuit diagram. Will it be okay?

Will it be okay?

OK? It is virtually mandatory please read this:-
How to use this forum

The LM324 is a very old quad general purpose opamp. There are better modern ic's for use as a comparator.

Allam

pinMode(12,INPUT); // I connect output pin of LM324 at digital pin no 12 of arduino UNO
Do you think it's ok to inject almost 12volt into an Arduino pin?

An Arduino can measure/compare voltages without the help of an external opamp.
Leo..