Is something missing from this program?

I have an Arduino Uno R3 connected to an adjustable IR sensor with 3 pins.
Red to 5volts +
Black to GND (They came with that color)
Yellow to pin9. I also have a 10Kohm resistor between Yellow and +5V

This is the sketch (program) I wrote for it.

int distance =9;
int pinRead;
int pinWrite;
void setup() {
// put your setup code here, to run once:
distance = 9;
}

void loop() {
// put your main code here, to run repeatedly:
pinRead = 9;
pinWrite = 9;
}

I downloaded the blink program and that worked. Now I get this error

avrdude: ser_open(): can't open device "\.\COM5": The system cannot find the file specified.

What am I doing wrong?
Ken

Is something missing from this program?

Code tags for a start (<> above the editor window)

Does COM5 exist on your system ? What is the port set to in the IDE ?

The program is nonsense anyway and will do nothing even of you get it uploaded. It does not read any pins nor produce any output.

From tools -> programmers, select the COM port corresponding to your Arduino. Sometimes windows gives different numbers to COM ports depending on what USB port they're in, and god-knows what else.

Also, your code doesn't do anything at all. You're not reading or writing any pins, or really doing anything other than assigning the value 9 to three variables. But it should compile and upload successfully.

Sorry. My book on programming Arduino is upstairs and I was trying to get the IR sensor to print out on the screen the distance it was set for.
I do have my computer telling me that it is set to COM5. I did not do that. The computer set it there.
I got it to load and it did nothing as predicted.
Sorry for bothering everyone.
I am 75 and just learning about this.
Ken

Raybrite:
I am 75 and just learning about this.

I have said it to others - don't use age as an excuse. If you want to do it, you can.

Have a look at the examples that come with the Arduino IDE so that you can learn how the Arduino system works. Start with the Blink example as it does not need any external components.

Then learn to work with a push button. You can simulate a button with two pieces of wire stuck - one stuck into an I/O pin and the other into GND.

...R

Now I get this error

avrdude: ser_open(): can't open device "\.\COM5": The system cannot find the file specified.

You have several problems there.

When you write an arduino program, there are several steps to the process. First, it will get compiled, your source code will be converted into a form which actually controls the arduino. Second, your compiled code has to get sent from your computer to the arduino. This second step is done by a program called "avrdude". That is the program complaining here.

When you plug the cable from the arduino to the PC into the USB socket on your PC, it gets allocated a COM port. This might not be the same number each time. You can usually observe this by using "control panel" and then "device manager" if you have a windows pc.

When you say, you downloaded the blink program, and it worked, did you actually compile this program and successfully send it to the arduino ?

I have been through most of the examples in the Starter kit except the ones with the servo motors. We also built a robot and have that sort of working.
I didn't look at any of the other examples when I wrote that first one.
I did manage to get the blink from the examples and download that. I now have changed the program and added the Serial. designation in the front of the lines where it was missing.
I will bring my book down tomorrow and compare it to the program and probably completely rewrite it as I am using this now and changing it to agree with a program I made this morning to measure the temperature in my room.

int pinRead;
int pinWrite;
int distance;
void setup() {
// put your setup code here, to run once:
distance = 9;
}

void loop() {
// put your main code here, to run repeatedly:
Serial.pinRead(distance);
Serial.pinWrite(distance);
}

This is the error I am getting now. I am sure I can figure it out if I take enough time.

Distance_Sensor.ino: In function 'void loop()':
Distance_Sensor:11: error: 'class HardwareSerial' has no member named 'pinRead'
Distance_Sensor:12: error: 'class HardwareSerial' has no member named 'pinWrite'

I only mention my age because I am a bit slow and not as smart as some on here. When I began electronics we taught current flow which is the opposite of what is taught here and we used vacuum Tubes.

int pinRead;
int pinWrite;
int distance;
void setup() {
  // put your setup code here, to run once:
distance = 9;
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.pinRead(distance);
Serial.pinWrite(distance);
}

Well, the error you get now is a compiler error, not an avrdude error.

There is a lot wrong with you code.

Firstly, you need to understand what is the sensor output from your IR device which is the input to your arduino. Is it a digital signal ? An analog signal ? Is it a signal where you have to count pulses or measure the duration of pulses ? You need to find that out.

Secondly, in your setup( ) function, you need to do two things. Set the mode of pin 9 (possibly), and initialize the serial communication to your PC. Look for examples of Serial.begin(9600).

Thirdly, your code in loop( ) is nonsense. There is no "Serial.pinread()" or pinwrite() . If you want to read the state of a digital pin, you would want code like this.

void loop( )
{
      int state = digitalRead(9) ;
      if ( state == HIGH )   Serial.println("Its high");
      else  Serial.println("It is low");
  
      delay(500);
}

Here, you are reading the state of the digital pin ( high/low true/false 5V or 0V ) and then sending a message to the computer for you to see the result. The delay is just to slow down the display.

The code you wrote is trying to use Serial functions named pinRead and pinWrite which don't exist, hence the errors. Can you please explain in words what you are trying to do ? Are you trying to print something and if so, what ?

I am a bit slow

Nothing wrong with going slowly as long as you get where you want to be.

While comparing my program with the one for temperature I had earlier this morning I noticed that. I was trying to read the output and then write it on the screen. I have taken those out.
The company that sells the sensors is a company called Seed from China. (quality Products)
They do not say if the output is digital or analog.I have been trying to get a digital out from them but I may have to go to analog so see if I can find anything there.
I am going to try the code above to see if the pin is digital and if it changes with a detection. If not , I will have to go to the Analog and look for things there.
thanks for the help. I seem to be getting farther.
I usually read my programming book in the evening for a few hours in the evening to catch up on things. Electronics has changed much since the days when we replaced capacitors and resistors to fix things. Now they just change boards.
Thanks again for the help.
I am probably going to head upstairs for the evening soon.
Ken

Raybrite:
int pinRead;
int pinWrite;
int distance;
void setup() {
// put your setup code here, to run once:
distance = 9;
}

void loop() {
// put your main code here, to run repeatedly:
Serial.pinRead(distance);
Serial.pinWrite(distance);
}

You say you have worked through several of the examples that come with the Arduino IDE. But this code is not like any of the examples and it simply CANNOT work. You seem to be mixing up several concepts.

Go back to the examples and study them more closely. See how to use variables and see how Serial is used.

Use a copy of a working example as a start point for your own code. Then make one change at a time checking to ensure it works properlyy after each change.

...R