Read 2analog inputs and compare them

in the lines of code analogRead(5); what is the (50 refering to

RTFM? ➜ analogRead() - Arduino Reference

@ade95
Please read the forum guidelines before going further.
You can edit your messages in the forum. It's absolutely not necessary to post the same message again.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not suitable for this question.

@ade95

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

@ade95

As J-M-L mention ... the 5 stand for A5. The analog input name A5 of the Arduino, use to measure a voltage from 0 V to 5 V ... more than 5 V ... well .... you may damage the ATMega chip.

Example ... reading_data = analogRead(5); // Will measure a voltage at pin A5 of the Ardiuno.
It will give a result from 0 to 1023, an integer, a 2 byte number. Because the ADC i( Analog to Digital Converter ) result a 10 bits number. It mean you got a step of 4.88 mV ( 5 V / 1024 ) for every 1 step.

Let say you read ... reading_data is 511 in value. So the input voltage of the A5 pin is ... ( 5 / 1024 ) * 511 = 2.495117188 <-- Multimeter will read 2.5 V.

Let say to want to read 2 voltage and compare them ( as your title say ) You need 2 analog input.

byte analogpin1 = 0; // Analog pin A0
byte analogpin2 = 1; // Analog pin A1

unsigned int reading_data_one; // to store a number from 0 to 1023
unsigned int reading_data_two;
unsigned int reading_difference;

float voltage_difference;
float current;

const unsigned int resistance = 10;


void setup()
{
  Serial.begin(9600);
}

void loop
{

reading_data_one = analogRead(analogpin1); // It will be the highest voltage
reading_data_two = analogRead(analogpin2); // it will be the lowest voltage

// It depend on where you measure the voltages on your circuits
// let say measure a voltage drop across a resistor in order to calculate the current.

// Let get the difference
reading_difference = reading_data_one - reading_data_two;

// Let get the voltage
// reading_difference - 5 - 1024 are integer and the result as to be a float.  
voltage_difference = float(reading_difference * ( 5 / 1024 )); 
current = voltage_difference / float(resistance);

// let display the  current
serial.println(current);
delay(2000);

}

Sorry for the mistakes if any.

I think you meant:

thank u for a speedy reply,having looked at the sketch again it is a lot clearer

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.