IR Servo Claw

Hello, While I am stuck at home quarantined, I figured I might as well start a new project. My goal is to use my tv remote to an IR receiver that is hooked up to an Arduino Nano when the right hexadecimal code is received it will cause a servo to open and close a 3-D printed claw. I am powering the project with a 2000ma 3.7v Lipo and an Adafruit powerboost 1000c that takes 3.7v and outputs a 5v at 1000ma.

Below I will have a block diagram of how my components are hooked up and i will include the code also. P.s (I have already done the sketch that tells you what code a certain button on your remote is putting out and applied that to my sketch.)

Facts- The servo and the project in whole works but it is not consistent at all. I will have the servo opening and closing like i want around 4 times in a row, then the IR receiver will still show it is receiving a signal because i have the "IR board that includes a power LED and a signal LED, which flashes when a signal is being received.
and when I reset it it won’t work most of the time, It is very random.

Questions- 1) I am not sure if the problem is in the hardware because if you look at my block diagram I have the 5v of the Arduino Nano electrically connected to my servo which is also connected to my Powerboost, so when my servo is in action, I don’t know if it is pulling power from the Nano(unwanted) or if it is pulling from my Powerboost(wanted)?
2) Or if the problem is with my code which i will have below

#include <Servo.h>
#include <IRremote.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

const int RECV_PIN = 4;

IRrecv irrecv(RECV_PIN);
decode_results results;


void setup(){
myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  
  irrecv.enableIRIn();
  

}


void loop(){
    if (irrecv.decode(&results)){

        switch(results.value){
          case 0x20df40bf: 
     
 
         for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       //
        
    }
    irrecv.resume(); 
  }

}}


I just realized that in the block diagram i had the 5v connected to ground by the servo,
here is the correct revision

Can someone please help?

Measure the voltage the servo receives. Does it drop when it behaves badly?

Thank you for the response, I did measure the voltage of the VCC and ground of the servo, but like my block diagram shows i have the servo soldered directly to the power boost board, so i metered the voltage between the 5v on the power boost and ground to the Arduino and even when the servo is moving the voltage stays at 5.19 volts.

What i was worried about is if it drawing current from the nano or power boost, i would think it would be from both because they are connected in parallel. Because i know the nano cant supply much current.

and secondly, i wasn't sure if it mattered but i also checked the voltage from the signal wire and ground of the Arduino and i noticed the based on the servo arm position and would read from .1v to .6v or 0-180 degrees.

tjones9163: and secondly, i wasn't sure if it mattered but i also checked the voltage from the signal wire and ground of the Arduino and i noticed the based on the servo arm position and would read from .1v to .6v or 0-180 degrees.

That's about what you'd expect when you're measuring the AVERAGE voltage of pulsed signal with a varying duty cycle e.g. 0.6 - 2.4ms high, 18ms low.

Steve

slipstick: That's about what you'd expect when you're measuring the AVERAGE voltage of pulsed signal with a varying duty cycle e.g. 0.6 - 2.4ms high, 18ms low.

Steve

Thank you for the response.

I cant figure out what is wrong. Does anyone know. This is driving me crazy

I put alot of time into this project, can i get some of the experts to chime in? Please Hardware/ block diagram problem or with the code?

How about adding a few Serial.prints to check if anything is actually being received and if so what? A blinking LED doesn't really tell you much.

You do realise that those two for loops make it really unresponsive. A loop() takes around 6 seconds.

Your power connection diagram is fine so the main question is if the Powerboost can provide sufficient current. What is the servo? There are plenty of servos out there that need more than 1A on startup.

Steve

slipstick:
How about adding a few Serial.prints to check if anything is actually being received and if so what? A blinking LED doesn’t really tell you much.

You do realise that those two for loops make it really unresponsive. A loop() takes around 6 seconds.

Your power connection diagram is fine so the main question is if the Powerboost can provide sufficient current. What is the servo? There are plenty of servos out there that need more than 1A on startup.

Steve

standard sg-90 servos that is the most common one.
How do i add a serial print to my code?
Thanks for the response

I notice you were having the same problems with exactly the same code 6 months ago. https://forum.arduino.cc/index.php?topic=641057.msg4339329#msg4339329 And you still haven’t taken any of the advice you were given then. If it didn’t work then what made you think that it would suddenly start working now?

It’s not easy to believe that someone with nearly 400 posts has never seen a Serial.print but here is the reference page Serial.print() - Arduino Reference

Steve

slipstick: I notice you were having the same problems with exactly the same code 6 months ago. https://forum.arduino.cc/index.php?topic=641057.msg4339329#msg4339329 And you still haven't taken any of the advice you were given then. If it didn't work then what made you think that it would suddenly start working now?

It's not easy to believe that someone with nearly 400 posts has never seen a Serial.print but here is the reference page https://www.arduino.cc/reference/en/language/functions/communication/serial/print/

Steve

Thank you for the response, I have little to no knowledge of coding which was why I couldnt do what "Delta_G" asked because i truly do know how. I really dont. Thats why I am asking for help and i didnt know if i should continue my post from 6 months ago so i made a new post.

slipstick:
I notice you were having the same problems with exactly the same code 6 months ago. https://forum.arduino.cc/index.php?topic=641057.msg4339329#msg4339329 And you still haven’t taken any of the advice you were given then. If it didn’t work then what made you think that it would suddenly start working now?

It’s not easy to believe that someone with nearly 400 posts has never seen a Serial.print but here is the reference page Serial.print() - Arduino Reference

Steve

time to finish this.
I have code below that i did my best from what i read about serial.prints and this is what i came up with and it “Verified” but before i upload it i have a question.

I need to hook my arduino up to the computer through usb and my project can only work(according to my diagram) with power through the battery and powerboost.
Can i have power from the computer and my project powered by my lipo batter and powerboost at the same time?

#include <Servo.h>
#include <IRremote.h>

Servo myservo;  // create servo object to control a servo
                // twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

const int RECV_PIN = 4;

IRrecv irrecv(RECV_PIN);
decode_results results;


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


myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  
  irrecv.enableIRIn();
  

}


void loop(){
    if (irrecv.decode(&results)){

        switch(results.value){
          case 0x20df40bf: 
     
 Serial.println(results.value);
 delay(1);
         for (pos = 0; pos <= 180; pos += 1) {       // goes from 0 degrees to 180 degrees
                                                     // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) {           // goes from 180 degrees to 0 degrees
    myservo.write(pos);                           // tell servo to go to position in variable 'pos'
    delay(15);                                    //
        
    }
    irrecv.resume(); 
  }

}}

Thanks

I also noticed another potential problem. I was reading about "switch-case" because I have it written in my code, when i was reading up on what it means on the Arduino website, it says that the should be a "break" at the end of a "switch-case" and mine does not have one. Is that "break" absolutely needed and possibly the reason why my project is not working?

Disconnect your Arduino from the lipo as well as from other power consuming things in your circuit. Connect your Arduino to your computer via USB. Upload your program to the Arduino. Disconnect your Arduino from the computer. Connect your Arduino to your circuit. Connect your lipo to your circuit.

If you’ve only got one case, then a break is unnecessary.
So is the switch - an if would suffice.

Normally we only use switch/case to deal with a number different values. Since you only have one case the break is not really needed. If you later decide you need several different cases then break at the end of each is at least advisable.

But as you’re only interested in one value why mess with switch/case? Why not make it a simple if statement? Oh and move the Serial.println up so that it prints whatever value is received e.g.

  if (irrecv.decode(&results)) {
    Serial.println(results.value);

   if (results.value == 0x20df40bf) {
        for (pos = 0; pos <= 180; pos += 1) {       // goes from 0 degrees to 180 degrees
          myservo.write(pos);         
          delay(15);                       // waits 15ms for the servo to reach the position
        }
        for (pos = 180; pos >= 0; pos -= 1) {           // goes from 180 degrees to 0 degrees
          myservo.write(pos);                           // tell servo to go to position in variable 'pos'
          delay(15);                                    //
        }
        irrecv.resume();

    }

You should be o.k. with both USB and a 5V Powerboost connected for testing. Give it a try and report back.

Steve