Analog pin output to Analog pin input !

Hello,
I would like to know if it is possible to send analog data from 1st arduino pin to a second arduino ?

I made a setup, by connecting a potentiometer to 1st arduino pin A0, then A1 to second arduino A0.
When I try to read in serial i get 0 or 1023.
Here is my sketch:

1st arduino

void setup() {
  
  //pinMode(A1, OUTPUT);

}

void loop() {

  int AnalogRead = analogRead(A0);
  analogWrite(A1, AnalogRead);

}

2nd arduino

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

}

void loop() {

  int AnalogRead = analogRead(A0);
  Serial.println(AnalogRead);
  delay(300);
}

Why are you using analogRead for a digital signal?

pulseIn would be more appropriate

Not directly. There is no real analog output on a typical Arduino, just PWM which is alternating HIGH and LOW digital signal. To make a real analog signal from that, you have to put it through a low pass filter first.

As hinted at in the above reply, you could measure the PWM digitally by measuring the pulse width.

But why do you need to do this?

TheMemberFormerlyKnownAsAWOL:
Why are you using analogRead for a digital signal?

pulseIn would be more appropriate

why is it a digital signal ? I am reading analog pin A0
can you explain please what do you mean by that ?
and is an arduino Analog pin, analog input but digital output ?

if I understood right pulseIn() would give a duration value, what i want is a value from 0 to 1023

aarg:
Not directly. There is no real analog output on a typical Arduino, just PWM which is alternating HIGH and LOW digital signal. To make a real analog signal from that, you have to put it through a low pass filter first.

As hinted at in the above reply, you could measure the PWM digitally by measuring the pulse width.

But why do you need to do this?

I am trying some idea, which is to build a battery tester which reads the capacity of a battery and then send a value to another arduino by a single analog pin instead of using many pins of arduino and this way I can show a progress bar representing the capacity percentage

firashelou:
why is it a digital signal ?

Because it's a PWM signal.

if I understood right pulseIn() would give a duration value, what i want is a value from 0 to 1023

So, scale it.

TheMemberFormerlyKnownAsAWOL:
Because it's a PWM signal.
So, scale it.

AWOL, I changed the setup from analog pin on the second arduino to a PWM pin 5 and the pin sending the analogWrite() is pin 3 on first arduino so now my sketches are :

Arduino 1:

int potPin = A0;

void setup() {
  Serial.begin(9600);
  pinMode(3, OUTPUT);

}

void loop() {

  int AnalogRead = analogRead(potPin);
  analogWrite(3, AnalogRead/4);
  Serial.println(AnalogRead);

}

Arduino 2:

void setup() {
  Serial.begin(9600);
  pinMode(5, INPUT);
}

void loop() {

  int AnalogRead = analogRead(5);
  Serial.println(AnalogRead);
  delay(300);
}

You can use I2C or SPI or serial to communicate between two Arduinos.

firashelou:
AWOL, I changed the setup from analog pin on the second arduino to a PWM pin 5 and the pin sending the analogWrite() is pin 3

You can use pulseIn on any digital pin

TheMemberFormerlyKnownAsAWOL:
You can use pulseIn on any digital pin

but how to turn it into a value from 0 to 1023 ?

sterretje:
You can use I2C or SPI or serial to communicate between two Arduinos.

not possible because all my pins are used except A7 and pin5 on my real project Arduino Nano.
I am doing this as an experiment to prepare to use this in the main circuit

firashelou:
but how to turn it into a value from 0 to 1023 ?

Please tell me you're joking?

TheMemberFormerlyKnownAsAWOL:
Please tell me you're joking?

i never used it, so i don't know what it does before this post and reading the arduino reference i understood that it calculates the time from a pulse to the next so :

from arduino the website here :

Example Code

The example prints the time duration of a pulse on pin 7.

int pin = 7;
unsigned long duration;

void setup() {
Serial.begin(9600);
pinMode(pin, INPUT);
}

void loop() {
duration = pulseIn(pin, HIGH);
Serial.println(duration);
}

So can you please explain why you i am joking ?

You need to get a bit clever.
Don't analogWrite(0) and don't analogWrite (255).
The frequency will be either 490 Hz or 980 Hz depending on which pin you write to.

TheMemberFormerlyKnownAsAWOL:
You need to get a bit clever.
Don't analogWrite(0) and don't analogWrite (255).
The frequency will be either 490 Hz or 980 Hz depending on which pin you write to.

ok I see, so now is there anyway to send the value from 0-255 to another arduino Analog pin A0 from one PWM pin from first arduino and show that value on the monitor from 2nd arduino ?

And from arduino website :

void loop() {
  val = analogRead(analogPin);  // read the input pin
  analogWrite(ledPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}

Software serial.

TheMemberFormerlyKnownAsAWOL:
Software serial.

but I am not looking to serial communication between arduinos no, I am looking to see if it is possible to take analog value from 1 arduino and send it to another arduino as a variable varying depending on the sensor input going to first arduino

OK.
Then the low-pass filter may, or may not do whatever it is you want to do.

TheMemberFormerlyKnownAsAWOL:
OK.
Then the low-pass filter may, or may not do whatever it is you want to do.

what do you mean by low pass filter ? i checked it on google and it says that it lower the frequency but what are you referring to as a component exactly ?

firashelou:
what do you mean by low pass filter ?

Did you read reply #2?