Trouble uploading sketch

I am new to this so sorry for any dumb questions. Using an Arduino Uno and working off a Mac with iOS Sonoma 14.7.3. I uploaded my first simple motion activated servo sketch and it worked great. I wanted to change the rotation and reduce it from 90 degrees and to just 45 degrees so I changed the code and verified it but when I try to upload now I get the following message. Any idea what I am doing wrong? I disconnected all the wiring so I am just

Sketch uses 3396 bytes (10%) of program storage space. Maximum is 32256 bytes.
Global variables use 337 bytes (16%) of dynamic memory, leaving 1711 bytes for local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "/dev/cu.usbmodem14101": No such file or directory
Problem uploading to board. See https://support.arduino.cc/hc/en-us/sections/360003198300 for suggestions.

====================

This is my sketch....

#include <Servo.h>

// Pin Definitions
const int pirPin = 2;      // PIR sensor OUT pin
const int servoPin = 9;    // Servo control pin

Servo myServo;
int motionDetected = LOW;
unsigned long lastTriggerTime = 0;
const unsigned long cooldownPeriod = 30000; // 30 seconds in milliseconds

void setup() {
  pinMode(pirPin, INPUT);
  myServo.attach(servoPin);
  myServo.write(0); // Start at 0 degrees

  Serial.begin(9600);
  Serial.println("System initialized and ready...");
}

void loop() {
  motionDetected = digitalRead(pirPin);
  unsigned long currentTime = millis();

  // Check for motion and ensure cooldown period has passed
  if (motionDetected == HIGH && (currentTime - lastTriggerTime > cooldownPeriod)) {
    Serial.println("Motion detected! Activating servo...");

    // Move servo to 45 degrees
    myServo.write(45);
    delay(5000); // Hold at 45° for 5 seconds

    // Return to 0 degrees
    myServo.write(0);
    Serial.println("Servo reset. Entering cooldown...");

    // Update last trigger time
    lastTriggerTime = currentTime;
  }
}

UPDATE: I got the code to upload by switching to the other USB port on my Mac. The code uploaded but now nothing is happening even if I upload the old code that was previously working. Checked all the connections and they seem to be good. I am trying to troubleshoot and wondering if there is an easy way to isolate the issue. Is there some way to tell if the PIR signal is reaching the board? Is there an LED on the board that lights when its receiving input?

Provide a wiring diagram. Indicate device pins and power supply.

Macbook or Macair?

You do, here...

More specifically, here...

Thanks. Its a Macbook Air
Here is the wiring diagram
I realize I need a separate power source for the servo when I use this for real. I was just doing it this way to test the circuit and the sketch.

The servo might be drawing too much power from the Arduino during startup, when it seeks 90 degrees, immediately. Disconnect the servo and run the program again.

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