Control reverse current of a DC motor

Hi all,

I am currently developing a pump system for a greenhouse.
I have some sensors connected with arduino to control some parameters. One of witch is the water level of a reservoir. When low the pump should turn on and fill it to the right measurement so the sensor may give a signal to turn it off with a relay switch. Right now I am using only one power supply to everything. As I have a common ground to both circuits (pump and arduino), I believe that somehow the DC motor of the pump is reverting some energy when shutting down. When this happens the arduino just disconnect from the pc but continues to operate flawless, what makes me believe that I can be losing communication due to the usb port security reset on my computer.

I am think on some solutions, but I am eager to know what you guys think of them.
I am using all the ports of a 4 relay board, but I may control one other circuit from the arduino and shut down both GND and Vin of the pump with 2 relays.
I read some examples of similar projects and think that a diode may solve the issue. But did not found one precise example using a relay! Instead, several are using a pinout from the arduino board and besides the diode, they use a transistor! Is the transistor really needed in my case, if I am opening and closing the circuit with a relay?
In worst case scenario I can attach other power supply and run the pump from there.

(One time tried out! When the pump was functioning I have disconnected the power supply, somehow it heept working with only usb voltage. Dont know how since the circuit only has the gnd as common.)

Any solutions?

Best Regards!

Hi,

Can you please post a copy of your sketch, using code tags?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom... :slight_smile:
PS, check if your relay board has any jumpers on it and what they do.

Hi and welcome.

Can you post a schematic diagram showing the components you described, and links to details of the various components?

Any component containing coils, like motors and relays, will need a "flyback" diode to protect the circuit from the reverse voltage when the driving current is switched off. Hopefully your relay board has these built-in for its own relays. But you will still need them for the motors and these are probably not built into the relay board.

Not sure what you are suggesting about transistors. Your relay board should have these built in to drive the relays. Power Transistors can be used to drive motors directly, but as you already have the relay board, you might as well use that.

Paul

Here is a code example of my pump control via Serial input:

int RELAY3Pin = 27;                             //  DEFINES THE PIN NUMBER OF THE RELAY 3 - PUMP POWER
int NO = LOW;                                   //  DEFINES A VARIABLE TO OPEN A ADRRESSED RELAY AND SHUT DOWN THE POWER SUPLLY TO ANY CONNECTED CIRCUIT
int NC = !NO; 
int ONOFF ;
int RelaytoControl;
//  SERIAL PROTOCOL
//serial input to read
int inputChar;                                  //  DEFINES SERIAL CASE
int overChar;                                   //  DEFINES COMPLEMENTARY CHARACTERS FOR SERIAL COMMUNICATION
String CommandString;                           //  DEFINES COMPLEMENTARY CHARACTERS FOR SERIAL COMMUNICATION
int CommandConverted;
String RelayString = "!RELAY ";

void setup ()
{
  Serial.begin(115200);                      //  GET VALUES USING SERIAL MONITOR
  pinMode(RELAY3Pin, OUTPUT);                //  DEFINES 3RD RELAY BOARD PIN AS OUTPUT
  digitalWrite(RELAY3Pin, NC);               //  MAKE SURE VIN IS OPEN (RELAY NO/LOW -> PUMP OFF)
    
}

void loop ()
{
  serialupdate();
}

void serialupdate()
{

    //Serial.println("serialupdate");     
    if (Serial.available() > 0) {
      inputChar = Serial.read();
      switch (inputChar) {
      // EXECUTE SHUTDOWN PROCEDURE
      case 'O':
        RELAYBOOT(NC);
        break;
      // CONTROL RELAY OPERATION    
      case 'R':
        overChar = 0;
        while(overChar != '!'){  // EXPECTS COMMAND WITH A TERMINATION CHAR OF ! (EX:"R 31!" TO SWITCH THE RELAY 3 TO NO)
          if (Serial.available() > 0) {
            overChar = Serial.read();        // READ NEXT CHARS
            CommandString += (char)overChar; // STRING BUILD UP
          }
        }
        CommandConverted = CommandString.toInt(); // GET NUMBER OF STRING
        CommandString = "";                       // RESET STRING
        RelaytoControl = CommandConverted / 10;   // IDENTIFY RELAY ADDRESS/NUMBER
        if ( (CommandConverted & 0x01) == 0) ONOFF = NC;    //IF 0 THAN THE ORDER IS NC
        else ONOFF = NO;                                    //IF 1 THAN THE ORDER IS NO
        RELAYC(RelaytoControl,ONOFF);
        break;    
      }
    }
}

void RELAYC(int Relay, boolean Order)
{
  if (Relay ==3){
    digitalWrite(RELAY3Pin, Order); 
    Serial.println(RelayString + Relay + !Order + "?");  //  SERIAL FEEDBACK
    return; }
  else Serial.println(RelayString + "ERROR?");           //  SERIAL FEEDBACK
}

void RELAYBOOT(int Order)
{
    digitalWrite(RELAY3Pin, Order);                      // (RELAY OFF/LOW -> PUMP OFF)
}

Attached is a fritzing example too.

The relay board is a Ywrobot 4 relay bought on ebay. The pump is from an old RC I use to use is the Electric Fuel Pump from Turnigy, from the pump there is not much information available.

From the examples I have seen transistors were use because the control was not made from the relay board. For that reason I said that I could only need the "flyback" diode. But no not know how to calculate the value it may need to have since I do not have any data on the DC motor from the pump.

Here goes the example I refer:
http://arduino-info.wikispaces.com/DC-Motors

Hi, just use a standard 1n4001 or 1n4002 or 1n4004 up to 1n4007, they will all do the job.

Tom...... :slight_smile: