I just got the elegoo arduino kit for Christmas, so I'm about as new as they come to this. I've been trying for days to figure out how to code my Arduino to have a servo that is controlled by an IR remote so that I can turn my light switch on and off! I already did trial and error printing out the servo mount, but in between I've been stressing about my code and was wondering if anyone could help me out with this.
I'm on arduino IDE ver. 2.3.7
IRremote Library version 4.5.0
Servo Library version 1.3.0
Sketch uses 7124 bytes (22%) of program storage space. Maximum is 32256 bytes
Global variables use 794 bytes (38%) of dynamic memory, leaving 1254 bytes for local variables. Maximum is 2048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xac
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xac
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xac
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xac
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xac
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xac
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xac
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xac
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xac
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xac
Failed uploading: uploading error: exit status 1
I'm stuck trying to figure out why this code isn't working in the serial monitor to display the values of the buttons pressed on my remote
#include <IRremote.h>
int IRpin = 11;
IRrecv irrecv(IRpin);
decode_results results;
void setup(){
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, DEC); // Print the Serial 'results.value'
irrecv.resume(); // Receive the next value
}
}
i'm sorry i'm very new to coding, what does it mean when you commented this?
The code actually shows values of the buttons i'm pressing in the monitor so that's a good sign!
Okay so I found the values of the up button (0x46) and the down button (0x15), and i tried replacing this line
with
case 0x46: servo.write(servoPos[static_cast<uint8_t>(Index::up)]); break;```
but it just made the servo move continuously once i pressed that button so I had to unplug it.
is there any way to make it so that it's a command that disables once i let go of the button? something like "the servo will move when the button is held and stop when it's released?"
There are basically two types of servos:
Type 1, the motor goes to an angle from 0° to 180° then stops when the angle is reached.
Type 2, (continuous) the motor is stopped when told to go to 90° and CW when the angle is > 90°, CCW when the angle is < 90°.