Use Xbees (series 2) to Control a Motor

66K925

Intro: Use Xbees (series 2) to Control a Motor

Using two xbees, an arduino, an xbee explorer, and an h-bridge, wirelessly control a DC motor to spin in both directions (last video).

Note: I used the xbee I linked to, but for a one to one communication, rather than a network of wireless devices, xbee series 1 would do fine, but the AT commands are slightly different.

This instructables was made at TechShop! www.techshop.ws

You can also control servo motors, or make a moving wireless security camera, as seen below.

In the photos I'm actually using an seeeduino but it is very similar to Arduino










STEP 1: Materials

Arduino
xbees
Any DC motor
power supply or battery
usb mini cable
xbee explorer
w
ires
breadboard
h-bridge

STEP 2: Set the Firmware on the Xbees

1.On a PC, download X-CTU

2.With the first Xbee plugged into the Xbee Explorer, and the usb cable connecting it to the computer's USB port, Open up X-CTU.
Click "Modem Configuration"

Click "READ" in the top left.

3.Set the first Xbee (the one currently plugged in) as ZIGBEE COORDINATOR AT (see the top)

4. Set the Pan ID to be a unique one (I used 1234)

5.Then, make note of the SH and SL
The SL is unique for each xbee. A great practice is to LABEL on that xbee the SL so you always know its address. 

6.Then, set the DH and DL of that xbee to the SH and SL, respectively, to the xbee it is going to be talking to and listening to. 
(the SH and SL can be found on the BACK of the XBEE on the white label)

7. Click WRITE.

8. Once it is finished, (see the bottom of the monitor), remove it and place the other xbee in the xbee explorer. You can unplug and replug the USB but you don't have to. 

9. Click READ again in the top left of the X CTU window. 

10. Set this Xbee to be ZIGBEE END DEVICE AT. 

11. Set it's PAN ID to be the same UNIQUE PAN ID of the other xbee (1234 in my case)

12.Set the DH and DL to be the SH and SL of the OTHER Xbee that you previously updated.

13. Press WRITE and wait for the firmware to be updated.

You're xbees should talk now!

If you had a second xbee explorer and another computer, you can hook both xbees up, and in X CTU go to "TERMINAL". 
Whatever you type in one terminal window should show up in the other computer's XCTU terminal window.

STEP 3: Wire the Motor

I used the sn754410 H-bridge. To wire it to arduino, follow the following schematic in the fritzing drawing. 

The H bridge has the following pins and functions: The H-bridge has the following pins and features:

Pin 1 (1,2EN) enables and disables our motor whether it is give HIGH or LOW
Pin 2 (1A) is a logic pin for our motor (input is either HIGH or LOW)
Pin 3 (1Y) is for one of the motor terminals
Pin 4-5 are for ground
Pin 6 (2Y) is for the other motor terminal
Pin 7 (2A) is a logic pin for our motor (input is either HIGH or LOW)
Pin 8 (VCC2) is the power supply for our motor, this should be given the rated voltage of your motor
Pin 9-11 are unconnected as you are only using one motor in this lab
Pin 12-13 are for ground
Pin 14-15 are unconnected
Pin 16 (VCC1) is connected to 5V

See here for more info.

(Also, before wiring the motor, I took off the top so i could look at the gear box - the gears look super cool...see the images)

STEP 4: Upload the Code

Upload this code

Now, you can adjust the direction of the DC motor by pressing 'a' and 's' in the serial monitor of Arduino.

If you are using servos like I was in the video with three servos mounted to a wireless webcam, you can use this code instead:


#include <Servo.h> 
 
Servo myservo1;  // create servo object to control a servo 
 Servo myservo2;
 Servo myservo3;
 const int ledpin = 5;
 
 
void setup() 
{ 
  Serial.begin(9600);
  myservo1.attach(2);  // attaches the servo on pin 2 to the servo object 
  myservo2.attach(3);  // attaches the servo on pin 3 to the servo object 
  myservo3.attach(4);  // attaches the servo on pin 4 to the servo object 
  pinMode(ledpin, OUTPUT);
} 
 
void loop() 
{ 
  if(Serial.available()>0){
 // Serial.println(Serial.read());
byte info=Serial.read();
Serial.println(info);
  if(info=='1'){
   
     myservo1.write(0);  
myservo3.write(0);     

  }
  else if (info=='2'){
   myservo1.write(180); 
   myservo3.write(180);
  }
  else
{myservo1.write(90);
myservo3.write(90);

}
  
 if(info=='6'){
  myservo2.write(0); 
 }
 else if(info=='5')
 {
  myservo2.write(180); 
   
 }
 else{myservo2.write(90);
}
  }
  delay(20);
}




STEP 5: Connect the Xbee to the Arduino.

Leave one xbee connected to the computer via the Xbee Explorer and the USB. The other xbee needs four connections: power (3.3 V), ground, tx, and rx. 

See the pinout in the image : the pins you have to wire are:
xbee pin 1: to Arduino's 3.3V 
xbee pin 2: to Arduino Rx (digital pin 0)
xbee pin 3: to Arduino Tx (digital pin 1)
xbee pin 10: to Arduino ground

You can also get an xbee shield like this.

STEP 6: Talk to Arduino From Xbee

With one xbee plugged via USB to the PC, open X-CTU TERMINAL tab.

Now, you can have a standalone motorized device: With the other Arduino unit that you just programmed and wired up, unplug itfrom the computer USB. Plug in a battery either to the DC jack (9-12 V battery works well) or Voltage into the Vin pin and ground into the Arduino's ground. 

Now, if you type 'a' into the terminal, the motor (hooked up to the standalone Arduino / Xbee battery-powered unit) should begin to spin one way. 
if you type 's' into the terminal, the motor will spin the other direction.

Great! You have a wirelessly controlled motor.

Now make a r/c robot!

4 Comments

When we connect the xbee directly to the arduino we are making straight connections not reverse so we need to connect the RESET pin of Arduino to GND pin or we need to upload an empty code to the arduino,it bypass the boot loader only then Xbee module is going to work but then it is imposible simultaneously to run the motor bypasing boot loader..either xbee can be detected by arduino or it can run the motor not both at a time.If you want both then you have to use a xbee arduino breakout board.
In step 4 you have used pin 9 and 11 in the code but in step 3 there is no connection to pin 9 and 11.The hardware connection and the code is not matching.Could you please resolve this as soon as possible.

There is a mistake on this page, in Step 5.

The graphic in Step 5 shows Pin2 connecting to Tx and Pin3 connecting to Rx, but the written directions specify that Pin2 connects to Rx and Pin3 connects to Tx.

OK, this is scary:

https://www.instructables.com/id/Remote-controlled-webcam-using-Arduino-SensorMonk/

You two need to get together...