AnalogOutPin 9 necessary?

I am using the following code to transfer sensor data from a pulse sensor attached to my arduino to an android device. The code is for the arduino.

const int analogInPin = A0;
const int analogOutPin = 9;
int sensorValue = 0;
int outputValue = 0;

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

void loop() {
sensorValue = analogRead(analogInPin);
outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(analogOutPin, outputValue);
Serial.print(" " );
Serial.println(sensorValue);
delay(20);
}

I'm just wondering why I have to include const int analogOutPin = 9; when I don't have anything attached to analog pin 9? btw, the program works fine with it, but not without it.

analogWrite(analogOutPin, outputValue);

You might not be using it but the program does

Incidentally, pin 9 (analogOutPin) should, as its name suggests, be set as an output.

Where did you get the code ?

There are several projects associated with that video.

What type of sensor are you using and how is it connected to the Arduino ?

I'm using a pulse sensor amped. The sensor is plugged into arduino A0 analog input, and the + and - are plugged respectively into the bread board. I also have the BLE HC-05 module with the same hook up as the video

If you are not using it you can remove all references to pin 9 and analogOutPin

I tried that and it said error uploading to arduino

nikobeast:
I tried that and it said error uploading to arduino

Post the code that gave the error

UKHeliBob:
Incidentally, pin 9 (analogOutPin) should, as its name suggests, be set as an output.

analogWrite takes care of that :wink:

sterretje:
analogWrite takes care of that :wink:

Another case of the Arduino environment being consistently inconsistent because digitalWrite() doesn't do it

Although analogWrite() sets the pinMode() to output I think that I will continue to do it explicitly, much as I use pinMode() to set pins to INPUT even though that is the default.

Another case of the Arduino environment being consistently inconsistent because digitalWrite() doesn't do it

I don't see the justification for that assertion - a digitalWrite can be performed on an input pin, to turn on the pullup resistor, but an analogWrite can only ever be an output.