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