Go Down

Topic: Controlling multiple things (Read 877 times) previous topic - next topic

TobiAlade

Which Arduino and/ or shield would be able to run 2 dc motors, an ultrasonic sensor (HC-SRO4) and an NRF24LO1.

Thank you

JimboZA

#1
Mar 27, 2016, 02:33 pm Last Edit: Mar 27, 2016, 02:35 pm by JimboZA
You don't need a shield to run dc motors, although if you want to reverse them you will need an h-bridge which are often but not always on shields.

You can "run" a dc motor with just one wire to a transistor. (But need to define "run" a bit better maybe.) Some h-bridges (like L298 based ones) will use 3 wires per motor, but this one which I use only needs 2 per motor.

HC-SR04 needs 2 iirc, a trigger and an echo.

I've never used an NRF24L01 but it seems they need 5 control wires.

So that totals (2x2) + 2 + 5 digital i/o pins, = 11 if I counted right so easy for an Uno. Add 2 if you use a 298 based h-bridge; subtract 2 if you don't need to reverse but then don't forget you need a transistor and diode for each motor.

edit... plus power lines, of course. And separate power supply for the motors.

Johannesburg hams call me: ZS6JMB on Highveld rep 145.7875 (-600 & 88.5 tone)
Dr Perry Cox: "Help me to help you, help me to help you...."
Your answer may already be here: https://forum.arduino.cc/index.php?topic=384198.0

Cactusface

#2
Mar 27, 2016, 03:58 pm Last Edit: Mar 27, 2016, 03:59 pm by Cactusface
Hi,
     Perhaps a few more details are needed!! Like what size of motors, is it a robot? which will need the motors running both ways. But the short answer is just about any Arduino will do the job, it's what you need to go with it, as for driving motors DO NOT use a shield with the L293 or 298 they both drop about 2 volts on the output. Better are the driver modules using FET H-bridges.

I've only played with the NRF24LO1 but yes 5 control pins plus power, which is 3v NOT 5v which will kill it...

Want to see my bots? www.melsaunders.co.uk
<<<<<<<

hope it helps.
Regards

Mel.
Open your mind! But not too far, your brains might fall out.
Also like Photography, model building and my 300+ Cacti and Succs.

Robin2

I have an Atmega 328 connected to an NRF24L01+ and a Pololu DRV8833 motor driver which can control 2 DC motors - but I am only using 1 motor (in a battery powered model train).

The DRV8833 needs two PWM signals per motor - one for FWD and one for REV. Some motor drivers only need one PWM input per motor and a regular I/O pin for direction control.

I have no experience of ultrasonic sensors.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

TobiAlade

I'm kind of a newbie at Arduino, does anyone know how and what to use when powering the components with a separate power source?

larryd

#5
Mar 27, 2016, 07:44 pm Last Edit: Mar 27, 2016, 07:45 pm by LarryD
Unless you need complete isolation to your external power supply, grounds are usually connected together.

Until you select your components, it is hard to recommend interconnection.

In the mean time, look at some of these images:  Here

.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Cactusface

Hi,
      Here's my code for driving one of my bots, this uses 2 DRV8833 modules and an HC-S04 U/S sensor to measure the distance between the bot and the object in front of it.  I am now working on a bot using stepper motors for measuring distances, making more precise turns, using 1600 steps per wheel revolution...

Code: [Select]

/*
*******************************
 ;    Filename:        PololuRP5Drive
 ;    Date:        12/08/2013
 ;    File Version:    Pololu_RoundDVR8833
 ;    Written by :     Mel Saunders
 ;    Function:        BuggyDrive
 ;    Last Revision:   18/11/2013
 ;    Target           Uno/Nano Pololu round chassis, etc.
 ; *******************************
 
 This program demonstrates the use of a TI DRV8833 dual H bridge (Module).
 This can run 2x DC motors control their speed and direction.
 Also uses a U/S sensor, etc.
 */

const int MA1=3,MA2=5,MB1=6,MB2=9;  //Motor pins
int distance,cm,FRQ,TD,A,B,MotorTime,switches,action;
long int randNumber,motorSpeed;
boolean go;

void setup()
{
  pinMode(MA1, OUTPUT);      // sets the digital pin as output     
  pinMode(MA2, OUTPUT);      // sets the digital pin as output
  pinMode(MB1, OUTPUT);      // sets the digital pin as output     
  pinMode(MB2, OUTPUT);      // sets the digital pin as output
  go = true;
}

// * * * start of Main program * * * *

void loop()
{
  if (go == true)
  {
     distance=scanner(cm);
    do
    {
      distance=scanner(cm);
      delay(200);
      sound(2048,6);
      delay(200);
    }
      while(distance > 25);
 
    Startup();
  }
  // If go=false, start here.
   distance=scanner(cm);
   if(distance <=16)
  {
    Radar();
  }
   distance=scanner(cm);
   if(distance >20)
  {
    digitalWrite(MA1,HIGH);       //Left motor forward
    digitalWrite(MA2,LOW);
    digitalWrite(MB2,LOW);      //Right motor forward
    digitalWrite(MB1,HIGH);
    randomSeed(millis());
    MotorTime = random(450,750);     // Speed for turning, reverese, etc.
    motorSpeed=random(90,255);       //random motor speed
    action=MotorTime && 1;
  } 
}// end Main loop


//------------------------------------------------------------------
void Startup()
{
  for(int i=0; i <= 255; i++)
  {
  analogWrite(MA1,i);       //Left motor forward
  digitalWrite(MA2,LOW);
  digitalWrite(MB2,LOW);     
  analogWrite(MB1,i);      //Right motor forward. Plus 10 to compensate for slower RIGHT motor.
  delay(20);
  }
  //delay(2500);
  go = false;
}
//-----------------------------------------------------------------
void Halt()//Both motors STOP
{
  digitalWrite(MA1,LOW);           
  digitalWrite(MA2,LOW);
  digitalWrite(MB2,LOW);     
  digitalWrite(MB1,LOW);
  delay(700);
}
//------------------------------------------------------------------
void Rturn()//Turn right
{
  digitalWrite(MA1,LOW);       //Left motor forward
  digitalWrite(MA2,HIGH);
  digitalWrite(MB2,LOW);       //Right motor reverse
  digitalWrite(MB1,HIGH);
  delay(600);
}

//------------------------------------------------------------------
void Lturn()//Turn left
{

  digitalWrite(MA1,HIGH);       //Left motor reverse
  digitalWrite(MA2,LOW);
  digitalWrite(MB2,HIGH);       //Right motor forward
  digitalWrite(MB1,LOW);
  delay(600);
}

//------------------------------------------------------------------
void Forward()//forward
{
  digitalWrite(MA1,HIGH);       //Left motor forward
  digitalWrite(MA2,LOW);
  digitalWrite(MB2,LOW);       //Right motor forward
  digitalWrite(MB1,HIGH);
}

//------------------------------------------------------------------

int  Back(int TD)//Reverse
{
  digitalWrite(MA1,LOW);       //Left motor reverse
  digitalWrite(MA2,HIGH);
  digitalWrite(MB2,HIGH);      //Right motor reverse
  digitalWrite(MB1,LOW);
  delay(TD);
}
//------------------------------------------------------------------
void BackOff()//back off!
{
  int speed=150;
  analogWrite(MA1,speed);       //Left motor reverse
  digitalWrite(MA2,HIGH);
  digitalWrite(MB2,HIGH);      //Right motor reverse
  analogWrite(MB1,speed);
  delay(2500);
}
//------------------------------------------------------------------
void sound(int FRQ,int TD)
{
  tone(12,FRQ,TD);
}
//------------------------------------------------------------------
//scan
//------------------------------------------------------------------
long scanner(long cm)
{
  const int pingPin=7, EchoPin=8;
  long duration;

  // The SRF005 is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse before to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  pinMode(EchoPin, INPUT); 

  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(2);
  digitalWrite(pingPin, LOW);
  duration = pulseIn(EchoPin, HIGH);
  delay(100);

  // convert the time into a distance
  // inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);

  return (cm);
}
//------------------------------------------------------------------
long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
//------------------------------------------------------------------

void Radar()
{
  Halt();
  BackOff();
  Lturn();
  sound(2600,20);
  Halt();
  A=scanner(cm);
  delay(100);
  Rturn();
  Rturn();
  sound(2600,20);
  Halt();
  Lturn();
 // Halt();
  B=scanner(cm);
  delay(100);
 
  if(action = 0)
  {
  (twirl);
  }
 
  if (A>B)
  {
    Lturn();  //Then turn left
    A=0;
  }
  else 
  {
    Rturn();  //Then turn right
    B = 0;
  }
 
}
//------------------------------------------------------------------ 
void twirl()
{
  action=MotorTime & 1;
  if(action=1)

    // Left twirl
  {
    digitalWrite(MA1,LOW);       //Left motor reverse
    digitalWrite(MA2,HIGH);
    digitalWrite(MB2,HIGH);      //Right motor forward
    digitalWrite(MB1,LOW);
    delay(2000);
  }
  else
    // Right twirl
  {
    digitalWrite(MA1,HIGH);       //Left motor forward
    digitalWrite(MA2,LOW);
    digitalWrite(MB2,LOW);       //Right motor reverse
    digitalWrite(MB1,HIGH);
    delay(2000);
  }
}





Hope it helps, regards

Mel.
Open your mind! But not too far, your brains might fall out.
Also like Photography, model building and my 300+ Cacti and Succs.

TobiAlade

I am using this:

http://www.amazon.com/Emgreat%C2%AE-Chassis-Encoder-wheels-Battery/dp/B00GLO5SMY?ie=UTF8&keywords=robot%20chassis&qid=1459103905&ref_=sr_1_1&sr=8-1

for the wheels and the motors
As well as

.  An Arduino uno
.  An nRF24L01+ Breakout Adapter with On-board 3.3V Regulator
.  An hc sro4 ultra sonic

 What would be the best way to power this?

larryd

No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

TobiAlade

would I be able to plug everything to my Arduino? Thank you so much for your help

TobiAlade

If I were to use this dc motor driver instead

http://www.amazon.com/SMAKN%C2%AE-HG7881-2-Channel-Driver-Module/dp/B00M6OB8ZY/ref=sr_1_4?ie=UTF8&qid=1459164421&sr=8-4&keywords=dc+motor+driver

would I have to reconsider anything? What separate power source would be the best if I wanted to power this individually.

Go Up