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;
}
}
