Driving Nema34, Nema42 motors with external stepper motor driver(DQ860MA) and RAMPS 1.4

If you ever need to drive big motors(Nema23, Nema34, Nema42) for your 3Dprinter or CNC you might be a little bit puzzled by the complicated wire connections needed just like I was so I am writing this article to help you build those BIG CNCs or 3D printers easily.

Parts needed:

  1. RAMPS 1.4
  2. BIG Motor :-)  – In my case Double shaft Nema34
  3. Appropriate driver for the motor above – In my case DQ860MA
  4. Appropriate power supply – In my case 60 volt 5.85A switching power supply (Yes, that is for a single motor :-D)
  5. Arduino Mega 2560 for the RAMPS 1.4
  6.  You don’t need any Pololu drivers since we will be using an external driver

In case you have trouble finding big motors and drivers or you are wondering what I have used as parts I have used motor+driver+power supply from Wantai motor and you can find those from Wantmotor from a local warehouse(no customs) here for USA or here for Europe.

Just a side note…I will not gonna cover the driver configuration itself thoroughly. Just select the appropriate driver amps with the switches and select a lower resolution for the tests something like 400 pulses per revolution. This way it will be easier for you to see the motor moving. You will adjust that to a better resolution later.

I am going to use the Repetier firmware since I like it very much and it has all the needed stuff. You can download it from here:  https://www.repetier.com/firmware/v092/. Be sure to use firmware which is at least 0.92.  Previous version proved to be problematic and will probably not work.I will talk about the issues later on…

As always I encourage you to donate to Repetier if you like their software


Ok, let’s get all that connected together:

Connect the motor to the driver… you can see that in the image below. Wire colors might be different so please refer to your motor manual to understand which wires are A+,A- and B+,B-

  1.  Connect ENBL-  to DIR- to PUL- and then all those to 5v on the RAMPS. Yes, that is correct connect all those 3 pins together and then to the +5v on the RAMPS
  2. Connect ENBL+ to the ENABLE inverted pin on the X axis pinouts. You have two rows of 8 pin female sockets. the correct pin is the first on the right row  (again I am reminding that you don’t need drivers on the board, If you have some then remove them)
  3. Connect the DIR+ pin of the driver to the Direction pin on the RAMPS.That is the last pin for the X axis on the right row
  4. Connect the PUL+ pin of the driver to the STEP pin for the x axis on the RAMPS. That is the pin before the last one again on the right row

You are done, upload the Repetier firmware and try to run the motor. and if it does not run correctly read on…

If the motor only vibrates and does not spin the axle then you need to reduce the driving speed/accelerations

I am using the following values and the motor is running correctly:

x,y,z axis max feedrate mm/s is 100

x,y,z max acceleration mm/s^2 is 1000

If the motor is running correctly but is not able to change the direction then there are a few possibilities:

1. You are using Repetier firmware prior to 0.92 – please use 0.92 upwards

2. You might need to adjust the direction pulse delay and re flash the firmware. The setting is in Configuration.h of the firmware and is #define DIRECTION_DELAY 0 by default. Increase that a bit and try again until it works. Depending on the driver a good value might range from 10 to 120 us. Please read the driver manual for details or increase the value gradually until it starts working.

 If nothing else works In some rare cases you might need to adjust the STEPPER_HIGH_DELAY 0 to a higher value

I hope you can see the connections on the photo below. Please have in mind I have connected the motor on the Y axis on it. Not on the X axis as described above



Enjoy your BIG motors running and go build that enormous machine :)

Arduino simple 433Mhz/315Mhz remote control(transmitter & receiver)

I decided to create probably the simplest and cheapest remote control which is compatible with the rest of the commercial RC equipment. The remote control purpose is to be cheap, simple and fast enough for ground equipment such as RC cars, tanks, rovers, robots, etc.  If the remote proves to be reliable and more important fast enough it can be used for flying stuff like quad copters and other single and multi rotor equipment.I am bringing up the speed topic because I will be doing a lot of DA and AD conversions which will need time. In my initial tests the remote control response time is 1/15 seconds which should be enough speed for most ground vehicles.

The remote control is again based on those cheap ASK 315/433Mhz modules and Arduino to keep the cost low. I will be using the 433Mhz modules since I found great and cheap antennas for them only and without good antennas the range will be probably less than 10 meters which renders the project almost useless. With the antennas the initial tests were successful at transmitting at 15 meters indoors (3 concrete walls in between) which is a great result.

I guess outdoors the range can easily reach at least 60 meters at line of sight, probably more. I will post an update when I test it. And if this is not enough the range can be further extended by increasing the voltage of the transmitter from 5 volts to the maximum the transmitter can accept. On mine it is 12 volts (Please check your transmitter max voltage)

Parts List(for a 2-3 channel transmitter):

1. PS2 Game Joystick Module

2. 315Mhz/433Mhz transmitter receiver pair

3. Antennas

4. Arduino Nano v3  – 2pcs

5. Power bank for transmitter power (Optional)

Total cost is under 10$ without the power bank

For the transmission I will be using the RadioHead library and more specifically their RH_ASK Class. In order for the code to compile you will need to download the library from:  http://www.airspayce.com/mikem/arduino/RadioHead/RadioHead-1.61.zip

If you like how RadioHead works for you, please consider donating to the author at http://www.airspayce.com/ via the Donate button

The  first thing you should do after installing the RadioHead library is to force it to use Timer2 otherwise it will conflict with the Servo library and the code will not compile. To instruct RadioHead to use Timer2 you need to go to the place you installed the library and find the file named RH_ASK.cpp  Edit the file with your favorite editor and find the line // #define RH_ASK_ARDUINO_USE_TIMER2. Uncomment the line, save the file and you are done. If you don’t do this you will get an error during compilation of the receiver code saying  something about `__vector_11′ being already used.

Building the transmitter:


  1. PS2 Game Joystick Module
  2. 433Mhz transmitter
  3. Arduino Nano
  4. Antenna (optional but highly recommended)

The parts should be connected in the following manner:

Transmitter data pin should be connected to pin 12 on the Arduino Nano. Transmitter Vcc to the 5v on the Arduino and the transmitter GND to Arduino GND.

The PS2 Joystick should be connected ass follows: GND on the Joystick to the GND on the arduino, +5V on the joystick to the 5V on the arduino, VRx should be connected to A0 on the arduino, VRy should be connected to A1 and the SW on the joystick should be connected to D2 on the Arduino. Basically that is how simple it is.

//Transmitter code

#include // Not actually used but needed to compile

RH_ASK driver(1000, 11, 12, 10); // bps,rx,tx

int xPin = A1;
int yPin = A0;
int buttonPin = 2;

int xPosition = 0;
int yPosition = 0;
int buttonState = 0;

void setup()
Serial.begin(115200); // Debugging only
if (!driver.init())
Serial.println("init failed");
void loop()
// Since my joysticks are really not precise we can encode their values at 256 possibly less
xPosition = analogRead(xPin);
xPosition = map(xPosition, 0, 1023, 0, 255);
yPosition = analogRead(yPin);
yPosition = map(yPosition, 0, 1023, 0, 255);
buttonState = digitalRead(buttonPin);

//Put the values in the array, 8 bits per input
uint8_t values[3];
values[0]=(uint8_t) xPosition;
values[1]=(uint8_t) yPosition;
values[2]=(uint8_t) buttonState;

Serial.print(" : ");
driver.send(values, 3);

Building the receiver:


  1. 433Mhz transmitter
  2. Arduino Nano
  3. One or two servos (depending on your specific needs)
  4. External 5 volt power supply at least 1A for the servo(s) since they require larger currents
  5. Antenna (optional but highly recommended)

The parts should be connected in the following manner:

Receiver data pin should be connected to pin 11 on the Arduino Nano. Receiver Vcc to the 5v on the Arduino and the Receiver GND to Arduino GND.

Servo signal pin(yellow or white wire) should be connected to D3, servo ground wire(black or brown) should be connected to the Arduino GND and also to the external power supply ground. The servo positive + wire(Red) should be connected to the external power supply +5V.

If you are connecting a second servo connect its signal pin to D9 and its positive and negative terminals just as the first servo

The code is currently set to 1000 bps  so it would have slower speed but better range and thus it is easier to test. Please feel free to increase that to 2000 after successful tests. To avoid headaches please after uploading the code to the transmitter move it to a different USB power supply. I had a lot of issues trying to transmit anything when the transmitter and receiver were both connected to the USB ports on my laptop. Moving the transmitter to an external USB power supply instantly resolved the issues. The button on the receiver is connected to the LED pin D13 but it also seems to be used  by RadioHead for transmission indication. Please change that according your needs

//Receiver code

#include  // Not actualy used but needed to compile

Servo servo1;
Servo servo2;
//RH_ASK driver;
 RH_ASK driver(1000, 11, 12, 10); // bps,rx,tx

//Those are used for fine tuning
int SERVO_LOW = 0;
int SERVO_HIGH = 180;
int c1,c2,c3;

// Pin assignments for channels(output to servos)
byte CH1_PIN = 3;
byte CH2_PIN = 9;
byte CH3_PIN = 13;

void setup()
    pinMode(CH3_PIN, OUTPUT);

    // Debugging only, comment serial stuff when done  
    if (!driver.init())
         Serial.println("init failed");
void loop()
    uint8_t buf[12];
    uint8_t buflen = sizeof(buf);
    if (driver.recv(buf, &buflen)) // Non-blocking
        c1 = buf[0];
        c2 = buf[1];
        c3 = buf[2];

        // Remap values to the predefined range
        byte v1 = map(c1, 0, 255, SERVO_LOW, SERVO_HIGH); 
        byte v2 = map(c2, 0, 255, SERVO_LOW, SERVO_HIGH);


        //Output button state to a led
        digitalWrite(CH3_PIN, c3); 

        //Servo reaction time(adjust delay to your needs)
        Serial.print("  ");


Enjoy your new 2(3) channel arduino remote controller!

Arduino multiple sensor wireless thermometer using 433Mhz/315Mhz RF modules

I always wanted a thermometer displaying the temperature of each room of the house and was thinking of buying a weather station to solve this. The problem was that most weather stations had one remote sensor and I needed at least 3.

I decided to build my own base station capable of displaying the temperature from multiple sensors around the house. I wanted the project to be cheap so I decided to use those 315/433Mhz receiver/transmitter pairs for under a dollar. For the display I chose a 1602 which has the I2C interface so I can interface it with only a few cables and for sensors/base station I chose Arduino nanos.

I was thinking of using the Arduino Wire library for the communication but as I wanted to be able to expand the project with remote power outlets at some later time I just chose to use the RC-Switch Library http://code.google.com/p/rc-switch/


The wiring of the modules is really easy, you just connect GND to the Arduino Groud, the VCC to +5V on the Arduino and the DATA to:

  • Remote sensor transmitter module DATA pin to Arduino D10
  • Base station receiver DATA pin to Arduino D2

Since I don’t need the temperature readings to be super precise the only thing I needed for the reading was a cheap 10K thermistor and a 10K resistor



Wireless sensor code follows. The code contains code fragments from Arduino Playground http://playground.arduino.cc/ComponentLib/Thermistor2

In order to compile it you will need rc-switch library which you can download at http://code.google.com/p/rc-switch/.

# Remote sensor Arduino code
#include <RCSwitch.h>
#define ThermistorPIN 6 // Analog Pin 6

RCSwitch mySwitch = RCSwitch();
int sensorID = 2; //For the purpose of multiple sensors. Valid values would be 1..9

double ReadTemperature(){

int RawADC = analogRead(ThermistorPIN);
long Resistance; double Temp; // Dual-Purpose variable to save space.
Resistance=10000.0*((1024.0/RawADC) - 1); // Assuming a 10k Thermistor. Calculation is actually: Resistance = (1024 /ADC -1) * BalanceResistor

 Temp = log(Resistance);
 Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
 Temp = Temp - 273.15; // Convert Kelvin to Celsius

 // Uncomment following line for the function to return Fahrenheit instead.
 //Temp = (Temp * 9.0)/ 5.0 + 32.0;
 return Temp;

void setup() {
 // Transmitter is connected to Arduino Pin #10 

void loop() {
 double temp=ReadTemperature();
 // A simple way of encoding sensor ID and value in one code
 long codetosend = temp*100+(sensorID*100000);
 mySwitch.send(codetosend, 24);

The code above is not optimized at all for battery operation since I am powering those “sensors” through usb. If you want to make those more battery friendly there are a lot of useful guides on the internet. Serial prints are also not needed and can be removed. I was only using those for debugging purposes

Base Station

The base station consists of an I2C 1602 LCD Display, Arduino Nano3, 315/433Mhz receiver. Everyone needs to know the local temperature on the base station so again we need the same 10K thermistor connected the same way as in the Remote sensor

In order to compile the Base Station code you will need libraries Wire, LiquidCrystal_I2C and RCSwitch

Base station code follows:

# Base Station Arduino code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RCSwitch.h>

#define I2C_ADDR 0x27 // <<----- Add your address here. Find it from I2C Scanner
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define ThermistorPIN 6 // Analog Pin 6

RCSwitch mySwitch = RCSwitch();
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

double ReadTemperature(){
int RawADC = analogRead(ThermistorPIN);
long Resistance; double Temp; // Dual-Purpose variable to save space.
Resistance=10000.0*((1024.0/RawADC) - 1); // Assuming a 10k Thermistor. Calculation is actually: Resistance = (1024 /ADC -1) * BalanceResistor

 Temp = log(Resistance);
 Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
 Temp = Temp - 273.15; // Convert Kelvin to Celsius

 // Uncomment following line for the function to return Fahrenheit instead.
 //Temp = (Temp * 9.0)/ 5.0 + 32.0;
 return Temp;

void setup() {
 lcd.begin (16,2); // <<----- My LCD is 16x2
 mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2

 // Switch on the backlight
 lcd.home (); // go home

#define ThermistorPIN 6 // Analog Pin 6
double temp;
double rc=0;
void loop() {
 double temp=ReadTemperature();
 // End of Line
 lcd.setCursor ( 0, 0 );

 for (int i=0;i<100;i++){
 // TRY TO READ VALUE 100 times!
 if (mySwitch.available()) {
  int value = mySwitch.getReceivedValue();
  if (value == 0) {
  Serial.print("Unknown encoding");
 } else {
 rc = mySwitch.getReceivedValue();
  // Process value from Remote sensor 2 and display reading on the right line1
  if (abs(rc)>=150000 && abs(rc)<250000){
   lcd.setCursor ( 10, 0 );
  // Process value from Remote sensor 3 and display it on the left line 2
  if (abs(rc)>=250000&& abs(rc)<350000){
   lcd.setCursor ( 0, 1 );
 //Update delay

The code only manages 1 local and 2 remote sensors but you can add more by just adding the respective code just like the one for sensor 2 &3. Hint:  Don’t forget to set a unique sensor ID in the remote sensor code ;-)

Wiring the Base Station

Display  – we need an I2C display so it only needs 4 wires: GND, VCC, SDA and SCL

Connect GND to ground on the Arduino and VCC to the 5V of the Arduino, SDA to A4 and SCL to A5


Connect GND to ground on the Arduino and VCC to the 5V of the Arduino, DATA to D2 on the Arduino


Connect the thermistor and resistor just like on the remote sensor, reading on pin A6

Sourcing the parts:

Resistor, thermistor and cables are widely available in local electronics stores

I2C 1602 Display

Arduino Nano v3

433Mhz Transmitter and Receiver pair

P.S. If you are looking at the code and thinking what are we doing to encode the values and sensor ID in one code and  how do we handle negative values when the code we transmit is always positive?   Well :)  it is not that easy to understand but you can figure it out by looking at the code a bit more. You just need to know that the effective temperature range is from -499.99 to 499.99 by design. E.g. Remote sensors cannot transmit values outside of this range

Done! Enjoy your multi sensor thermometer

I just found those great 433 Mhz antennas for the modules. With those the range of the sensors increases dramatically! Just solder them on the antenna spot and you’re done

Programming an Arduino Pro Mini with another Arduino

Warning: Executing the steps below will re-program both of your Arduinos, so if you have something valuable on the Arduino Nano please be sure to backup first. If you can’t afford to  erase your Nano please don’t follow this instructions

I usually use Arduino nano 3 for all my projects because it is reasonably small and still has a lot of pins, it also uses male headers instead of the female ones that the Uno does, of course this is not breadboard friendly but I kind of like it more.

But there comes a time when you want your projects to be even smaller and if possible a lot cheaper.

For that purpose I recently bought a couple of arduino pro minis(5 volts version). They also have the Atmega328P chip as the Nano and the price is much cheaper but don’t have the micro usb port and there lies the trouble… How can I program this?


I searched the net for possible solutions and found a lot which ranged from using external USB to serial board to … well using an arduino uno and removing its chip while programming, but all I had was an Arduino Nano R3!

Arduino Nano 3

Ordering a usb to ttl serial adapter was not an option because of the long delivery time so I had to do something…

I have done a lot of thinking and here is what I came up with…

What will happen if I just connect GND to GND, 5V on the Nano to the VCC of the PRO MINI, RX0 on the Nano with the RX1 on the Pro Mini, the RST on the Nano with the RST on the Pro mini and the TX1 on the Nano with the TX0 on the Pro Mini? After all they have the same chip ATmega328P

The only thing that can happen is an error while programming because when starting the programming the Arduino IDE will ask the microcontroller stuff and both chips will answer

Ok then… let’s make the Pro Mini unable to answer(no, I’m not going to break stuff :)). The thing we will do is disconnect the cable that goes from TX1 to TX0. And voila! You can program your Arduino Pro Mini with the Arduino Nano!

Go to Arduino IDE and select Arduino Nano /w ATmega 328 as your board and upload the sketch. Doing so will really be programming both Arduinos but who cares!

The same hack should work with other Arduinos as well but it always has to be the same chip running on the same frequency and the same voltage. Do not try it if these three conditions are not met!


Connect the pro mini and the nano as follows:


Driving 28BYJ-48 step motor with Pololu A4988/DRV8825 drivers

I have always liked the 28BYJ-48 motor because of its power and price, it also supposed to very reliable since it is used in different types of air conditioners.


Some information about the motor:

This motor is very small but has enough power for most of the projects because it has a built-in 1/64 reduction gear. The result is a very small step of the motor which is 0,087890625 degrees per step. The reduction gear of course has its downiside which is the speed – you can typically drive this motor with maximum frequency of 100Hz which result in 100 steps per second which is 8,7890625 degrees per second. That is 41 seconds per revolution – Not very speedy :) but for the price of under 2$ it still is a very good motor. Needless to say they are two versions of the motor(in fact 7 or even more), one is 12 volt and the other is a 5 volt version. They are pretty much the same except for the resistance. In this example I will be using the 12 volt version because of the higher resistance.

The main issue about driving this motor with a pololu a4988 driver is that this is an unipolar motor and the pololu driver is designed to work with bipolar motors. The best driver for our motor is the ULN2003 or similar but the point is to make it work with pololu drivers. What is the point? you may ask… the point is to be able to create different type of high precision machines which usually use the pololu driver. Such machines would be a mini CNC router, a 3D printer and especially a laser engraver because of the high precision. Another point is the cost, this motor costs less than 2 bucks a piece compared to a 15+ dollars for a Nema17 stepper motor

Ok, so straight to the point. How can we solve the issue? The answer is simple, we modify the motor to be bipolar. How?  Just cut the red wire :-)


This is however not that simple. We definitely don’t need the red wire so we can cut it but we also need to cut the path which is connecting the two sets of coils. The picture above shows what should be done.This is accomplished by removing the blue plastic cover of the motor and cutting one of the paths. Do not try to disassemble the motor itself because it will be too hard to assemble, just grab a knife or a sharp flat screwdriver and carefully pull out the blue plastic cover. Do not worry if it breaks, it will be pretty easy to get back in even if it does. Just try to not pull the wires too much when doing this.


Motor cutting path

After you remove the blue plastic you will have access to the path we need to remove. Can you see the cut in the picture above?   That is best cut with the tip of a sharp knife.  We only need to cut the path in the middle just like shown in the picture. Make sure that the cus is deep enoug and there is no contact between its two sides – otherwise the motor will not work as a bipolar one.  At this point we are pretty much done. We just need to put back the blue plastic cap to its place and we are done. The thing you might want to do is to cut the red wire before closing the cap since we will no loger need it.

Congratulations!, you now have a bipolar 28BYJ-48 motor

Last  but not least the two pair of wires are orange/pink and blue/yellow. Between each pair there should be a resistance doubled in value of the original – In my case it was 210 Ohms but this really depends on the motor type. From what I can see in the spec there are 7 types of motors each with different resistance ranging from 60 Ohms for the 5v version to 380 for the 12v versions

At this point you can connect the motor to the a4988 driver. The good news is if you are using RAMPS you can rearrange the wires in the motor connector and cut out the fifth pin and it can be directly plugged in to the RAMPS X,Y or Z ports

Don’t forget to adjust your A4988/DRV8825 driver current to the minimum! These motors cannot take more than about 100mA per phase. Forgetting to do that will burn or even melt the motor. You can also decrease the resoulution of the driver to 1/2 step

The 12 volt version of the 28BYJ-48 motor is pretty hard to find but they sell it at Aliexpress

And if you are looking for 5 volt version these are the cheapest I could find