Go Down

Topic: Comparing two analog input signals and outputting a digital signal (Read 6905 times) previous topic - next topic


I have two analog inputs on A0 and A1.  Both are on scales from 0-5000 (0-5 volts). A1 is connected to a variable resistor which is set at a certain value.  A0 changes based on the environment.  What I want to do is output a digital signal to turn on an alarm when A0's is greater than or equal to the value of A1 but have the alarm stay off when the value of A0 is less that A1. HELP.


I'm not sure what's confusing you.  Wouldn't it basically be:

Code: [Select]

var1 = analogRead(0);
var2 = analogRead(1);
if (var1 > var2)
digitalWrite(pinOut, HIGH);
digitalWrite(pinOut, LOW);

As long as you're using a 5V arduino your 0-5v will be scaled from 0-1023.


Probably need to do this to keep the signals from bleeding into each other:

var1 = analogRead(0);
var1 = analogRead(0); // read twice, ignore first read

var2 = analogRead(1);
var2 = analogRead(1); // read twice, ignore first read
if (var1 > var2)


Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up