displaying the sinusoidal signal from waverofm generator in the oscilloscope

Hi,
I tried to read a sinusoidal signal from a waveform generator using arduino UNO and I want to display it in the oscilloscope but the output signal that display in the oscilloscope is just a noise. Can you please help me out on how to solve this problem?
I'm very new to arduino.

Thanks

code.PNG

code.PNG

Please read and follow the directions in the "How to use this forum" post. Code is posted in line, using code tags and NOT as a picture.

Explain what the code should do, and what it does instead.

this is my code: I want to read the signal from the generator and output it to an oscilloscope .

this is my code i want simply to read the signal and output it to an oscilloscope

int out = 9;
int analogPin = 0;
int analogvalue;


void setup() {
  // put your setup code here, to run once:
pinMode(out,OUTPUT);
analogvalue = 0;
}

void loop() {
  // put your main code here, to run repeatedly:
analogvalue = analogRead(analogvalue);
analogWrite(out,analogvalue);
}

AnalogWrite() is not an analog output. It is a PWM signal, and only values 0-255 are used.

On an analog input, POSITIVE voltages in the range of 0 to 5V are allowed. So, you cannot connect a sine wave signal generator directly to an analog input, or you may destroy the input.

What is the frequency and amplitude of the sine wave from the generator?

Are you doing this for real, or just simulating?

Your analogRead line should have the parameter “analogpin” and not “analogvalue “ too.

Pin 9 of the Arduino has a PWM frequency of 490Hz.
You have a low pass filter on the output, with a cut off frequency somewhere between 1Hz and 2Hz.

If you use the analogWrite() function, then the circuit will give an analogue output between 0V and 5V - but only if you allow the output long enough to stabilise.

However in your loop you are changing the value that is sent to analogWrite() as fast as you can. you are not allowing the output to reach a steady value, before changing it again.

If you were to put a very low frequency (say a few mHz), and only update the value of analogWrite() at say once a second, then I think you would be able to see the output on an oscilloscope as required.

....and yes, I do mean mHz (milliHertz)

I've modified your code to incorporate the changes I suggested.

Also analogRead() gives a result in the range 0 to 1023, and analogWrite() requires a number between 0 and 255, so I have divided the result of the analogRead() by 4.

int out = 9;
int analogPin = 0;
int analogvalue;
unsigned long previousMillis = 0;
const long sampleinterval = 1000;

void setup() {
  pinMode(analogPin, OUTPUT);
  analogvalue = 0;
}

void loop() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= sampleinterval)
  {
    analogvalue = analogRead(analogPin)/4;
    analogWrite(out, analogvalue);
    previousMillis = currentMillis;
  }
}

The yellow trace is the input, a 20mHz sinewave,(period 50s), 5v pk-pk amplitude and with a 2.5V offset.

The magenta trace is the output of the Arduino and 10kΩ / 10μF low pass filter.