Stability problem (arduino nano)

Hello,
In an associative framework for sick children, I automate an Ironman cosplay.
The project consists of managing the opening of the visor of a helmet via 2 sg90 motors, 2 leds for the eyes, all controlled by an RF433 remote control.

The opening sequence works perfectly with in dry contact.
When I add the RF receiver the opening and closing also works but I see something weird.
The motors vibrate slightly and the LEDs also flash slightly. But as soon as I unplug my receiver, these small oscillations disappear ... (see video: VID_20210420_190025.mp4 - Google Drive)

Currently the nano is powered via the usb port for tests via my pc (I tried with a 2A phone charger, same problem), eventually the nano will be powered by a 9v rechargeable battery (I need a battery life of 6 to 8 hours max for hospital visits)

Here are the receivers that I use for the tests (identical problem with the 2)

code :

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

#define INTERRUPTEUR 10
#define OEILG 14
#define OEILD 15
bool memoInter=false;
int bp1 = 0;            
int bp1Mem = 0;         
int ledOn = 1;          

char str_BPH[]="278308";
char str_BPB[]="278305";
char str_BPS[]="278306";
char str_reception[]="";

void setup() {
  //Serial.begin(9600);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.write(0); 
  pinMode(INTERRUPTEUR, INPUT); //interupteur (D10)
  pinMode(OEILG, OUTPUT); //oeil 1 (A0)
  pinMode(OEILD, OUTPUT); //oeil 2 (A1)
  analogWrite(OEILG,0);
  analogWrite(OEILD,0);
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
}


void loop() {
  
  bp1 = digitalRead(INTERRUPTEUR);
  
  if (mySwitch.available()) { 
    sprintf(str_reception,"%ld", mySwitch.getReceivedValue());
    if(strcmp(str_reception,str_BPH) == 0  || strcmp(str_reception,str_BPB) == 0 || strcmp(str_reception,str_BPS) == 0){
    bp1=1;
  }
  mySwitch.resetAvailable();
  }
  
  if (bp1 != bp1Mem){
    bp1Mem = bp1;
    
    if (bp1 == 1) {
      
     ledOn = !ledOn;
      //Serial.println("here");
     if (ledOn == 1) {
      analogWrite(OEILG,0);
      analogWrite(OEILD,0);
      myservo.write(0);
    
     }else{
      myservo.write(130);
      delay(800);
      analogWrite(OEILG,511);
      analogWrite(OEILD,511);
    }
   }

  }
bp1=0;
}

Hi

how are the servo wired ? do they take power directly through the Arduino 5V pin?

yes

whether in open or closed position, the motors vibrate and they have little tones
but if I remove the receiver or if I order the code of the receiver, everything is stable

That's probably too much current drawn through the Arduino pins.
You might need to power the board on one side and the motor separately, joining GND

9V battery is a bad idea. Arduino and servos both run at 5V so what you need is a rechargeable 5V powerbank. Even then you will need to choose carefully to get a long run time.

Steve

I tested by adding a separate power supply for the power part. The problem is still here. I replaced the nano with an uno, but the problem remains the same. I am lost there. Is it possible that there is a conflict with the servo and rc-switch libraries?

try with ServoTimer2 to make sure in case it's a timer1 conflict (I use RadioHead and never used RCSwitch)

I will test with servotimer2, thanks. I tried RadioHead but I don't know why it doesn't work. I tested with pin 2 and 11, without success

I just tested the servotimer2 library, but I have the same problem. I also retested radiohead, but it doesn't work.
Here is a picture of the behavior of the engines: VID_20210421_162854.mp4 - Google Drive

I'm lost and I'm tearing my hair

if I remove the line from the code: mySwitch.enableReceive(0); or if I unplug the receiver, the motors no longer move

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