DC Power is glitching to Servo

Thank you so much for responding regarding the question at hand. I didn't realize issues could occur due to conflicts of libraries. Here's my code (also ignore the extra variables - copied and pasted a bit from others using this same reader):

#include <VarSpeedServo.h>

#include <LiquidCrystal.h>
#include <SPI.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <SD.h>
VarSpeedServo myServo;
SoftwareSerial RFID(2, 3); //pin2 Rx, pin3 Tx
int servoPin = 9;
#define MIN_PULSE_WIDTH       700
#define MID_PWM 1500
#define MAX_PULSE_WIDTH       2300


int out_flag = 0;

char tagValue[20];
char tagName[10];
char rfidData[20];
int readCount = 0;
int valueCount = 0;
int nameCount = 0;

const byte rxAddr[6] = "00001";
String testChip = "900_115002034428";
String rfidValue = "";
boolean raised = false;

void setup()
{
  Serial.begin(9600);
  SD.begin(8);
  RFID.listen();
  delay(2000);
  myServo.attach(servoPin);
  myServo.slowmove(0, 200);
  Serial.println("Reading....");
  RFID.begin(9600); // set the data rate for the RFID reader
  delay(10);
}

void loop()
{
  while (RFID.available())
  {
    Serial.println("data");
    byte E = RFID.read();
    if (E != '\r' && E != '\n')
    {
      rfidData[readCount] = E;
      readCount++;
      rfidData[readCount] = '\0';
      out_flag = 1;
      delay(5);
    }
  }
  if(out_flag == 0 && raised){
    myServo.slowmove(0, 100);  
    raised = false;
  }
  
  if (out_flag > 0 && !raised)
  {
    myServo.slowmove(180, 100); // sets the digital pin 13 on
    delay(60000);
    raised = true;
  }
  out_flag = 0;
  readCount = 0;
}

Anytime I seem to post to the Arduino forum, it seems that no one actually offers much advice, and when they do, it's very rude and belittling, so I appreciate you offering me help.

I believe Software Serial competes with the standard servo library for Timer1. ServoTimer2 was written to get around that. I don't know about VarSpeedServo, but check the code to see if it uses Timer 1. (EDIT: it does, try ServoTimer2)

But you should also use a separate servo power supply, like 4xAA batteries, which can handle 2 small servos if fresh. A good rule of thumb is 4.8 to 6V at 1 Ampere per servo (small servos), 2.5 Amperes per servo (large servos). Avoid using a breadboard for servo power wiring. Servo power distribution PCBs are available, or solder connections to a strip protoboard PCB.

Additional comment: Mixing servo code and software serial code is problematic for another reason: software serial suspends interrupts to get the bit timing right, and that can interfere with servo movements even if there is no timer conflict. It is best to use hardware serial. The Arduino Mega offers four hardware serial ports, and a couple of others, like the Pro Micro, offer the equivalent of two hardware serial ports (one is a USB serial port emulator).

Well if you behave like you have here that is no surprise. You were asked for a schematic and all you did was show pictures of random boards. This is useless for anyone trying to understand what circuit you have. Schematics are the language of electronics and without them all we can do is guess.

Couple that with some idiot trying to give you bad advice that “worked for him” causing a distraction and it is no wonder you are not getting any real advice.

Or as we say in English “could not care less”
John Cleese- could care less :wink:

I do not understand your problem. Is the power supply look like it's glitching in and out? Is the servo acting like it's glitching in and out? Is the lights on the board flikering?

I think he is using hardware serial. look at his wiring

It look like a complete mess. But I think ...

Aha!



Because you must realize, that the power output of the two-prong power adapters are "floating", i.e., the GND pin they have are not grounded.
This is because the AC 110V are supplied on both pins (think pin1 is -55V and pin2 is 55V), and because the two-prong do not have access to the ground pin (on a three prong), their power output for "ground" is floating.

On the desktop computer, however, the power plug is three-prong and therefore all the "GND" on the computer is connected to ground. It will be properly grounded.

And because you have one 12V powering the RFID and one 5V powering the Arduino UNO, none of their "ground" plane is actually connected together.

Here, I have a ADALM1K (USB oscilloscope). I will show you in a moment ...
This is when channel A is connected to my Apple USB power adapter (three prong, grounded)


And THIS is when channel A is connected to a USB power adapter without ground:

(notice, in both occasions, "channel B" is left floating, at about 0.2V.
This is the "setup" or the stuff I used:

As you can see the difference is incredibly big, and this is why you should have most things grounded via a three-prong plug.

This is why you had it working when you plug it into your PC. Because this way the PC grounds the Arduino, providing a clean 5V and allowing it to provide a clean signal. Even though the rest of the apparatus is floating, the servo worked fine. Perhaps because internal circuitry (in the servo, but likely the RFID) helped grounded them.

This is also why, despite I think everything Apple makes are unrepairable glue(and glass) sandwich, I will say that their USB power adapter is perfect. Partly because they are reliable (and dangerous) enough to never supposed to be opened, and more so because it have GROUND.



Except when you don't have a three-prong DC power adapter. It's ok. I don't have, either.
But this is where your setup comes "dangerous", because you are running two un-grounded DC power adapter.
So you have two options:

  • Run everything off the 12V adapter and get the 5V from the breadboard regulator. Power the Arduino by feeding it 5V through the 5V pin.
  • Run everything off the 5V adapter

After you pick one, remember to connect all of the "ground" pins on your devices together.

I tried, but once someone posts some disagreement, a war starts. In this case, I started the war. Because, again, as I had shown in the picture, everything I said will work. And I will refuse to apologize.

Once again a post that is full of rubbish.

Please refrain from posting if you don’t know what you are doing.

You can use as many ungrounded, or double isolated as they are more properly called, power supplies as you like as long as the signal grounds are common.

I don’t know where you get your rubbish from but please keep it to yourself.

And while you are at it try to learn how to use your oscilloscope.

He didn't ground the signal.

Oh, so you think it will be a good thing to run two "double isolated" power supplies on one project?

Go for it.

I'm using it quite well.

No those signals you posted show you have no idea how to connect your scope nor how to interpret what you see.

Yes, I do it all the time and virtually everyone else dose. I once worked on a commercial project that had six of them.

You have absolutely no idea of what you are doing, and it would benefit everyone if you stopped posting on this forum.

See how other members rush to your defence.

What is your experience level, have you got a qualification or experience in the commercial electronics business or are you self miss taught?

Nope. Wrong again, and welcome to my ignore list!

People who know what they are doing look at the code.

#include <SoftwareSerial.h>
#include <SD.h>
VarSpeedServo myServo;
SoftwareSerial RFID(2, 3); //pin2 Rx, pin3 Tx

Who is this he?
The op is @hackergirl69420 , the clue is the letters “girl” in the name, so should be addressed as she not he.

Honestly @cdr_xavier if you can’t even get that right what makes you think you are anyway correct with the technical stuff.
Now go away and we can get on trying to help @hackergirl69420 if you haven’t driven her away.

Just nipping back here.

I note a picture showing a "MB102 breadboard power supply" powered by a supply connected to the "barrel jack". This is not a suitable power supply for a servo in the same way that using the 5 V from a UNO similarly powered through the "barrel jack" is not and for exactly the same reason.

You need a genuine regulated 5 V power supply for the servo; for the one shown a 5 V "USB phone charger" rated at no less than 1 Amp, 2.1 Amp (common rating) for two such servos. The module cited in the first posting is pretty useless except as an adapter for a USB power supply (needing a "poofter" cable).

The drivel about the non-grounded power supplies is worrying. You absolutely should be using double insulated power supplies.

The ground should be connected from one part to another paired with the supply wire or the corresponding data/ control wire. Relying on ground connections through the power supplies and mains wiring would be variously ineffective, foolish and downright dangerous. :astonished:

1 Like

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