Wireless Stepper Control with Potentiometer with 433MHz RF module & Arduino

 Stepper motors are widely used in various applications such as printers, robots, automation systems, etc. that require precise control over the rotation of the motor. They are preferred over DC motors in such applications because of their ability to rotate in precise steps. Stepper motors can be controlled by various means such as digital inputs, analog inputs, and wireless inputs. Wireless Control of Stepper Motors Controlling stepper motors wirelessly opens up a lot of possibilities in terms of mobility and remote control such as for IoT applications. In this tutorial, we will see how we can control the stepper motor with a potentiometer wirelessly using a 433 MHz RF module.

433MHz RF (Radio Frequency) module

The 433MHz RF (Radio Frequency) module is a versatile and widely used device for wireless communication that operates in the 433MHz frequency band. It has both transmit and receive capabilities and is connected to an antenna for communication over a certain range. This module is often used in Arduino 433 mhz projects, such as remote control systems, home automation systems, and wireless sensor networks, as it can be easily integrated into microcontroller-based projects. Its compact size, low cost, and readily availability make it an attractive option for hobbyists and makers looking to add wireless communication to their projects.

rf module

Advantages of Using 433 MHz RF Module 433 MHz RF modules are widely used in wireless communication applications. Some of the advantages of using these modules are:

  • Low cost
  • Long-range communication
  • Robust communication protocol
  • Easy to use

Circuit Diagram

The following shows the circuit diagram of Wireless Stepper Control with Potentiometer with 433MHz RF module & Arduino.

Wireless Stepper Control with Potentiometer with 433MHz RF module & Arduino

In the above circuit diagram, Arduino nano along with the 433MHz RF module is used as the wireless transmitter. The 433MHz RF transmitter module data pin is connected to the Arduino pin 12 because the radio head library which we will be using in the program code uses pin 12 as the default transmitter pin. A 10KOhm potentiometer is connected to the analog pin A0. This potentiometer is rotated to change the stepping value of the stepper motor connected at the receiver. 

The receiver consist of Arduino Uno and 433MHz RF module. The 433MHz RF receiver module is connected to the pin 11 of Arduino Uno. Again we have used pin 11 because we are using the radio head library which uses pin 11 as the default receiver pin. The stepper motor is connected to the L298N stepper motor driver via the diode bridge and the Arduino pins 7,8,9 and 10 are connected to the L298N stepper motor driver.

Arduino 433mhz rf transmitter and receiver code

Below are the Arduino 433mhz rf transmitter and receiver code for wireless control of stepper motor and potentiometer using Arduino Nano and Arduino Uno using 433MHz RF module.

Transmitter Code

The following is the Arduino nano 433mhz transmitter code.

#include <RH_ASK.h>
#include <SPI.h> 

RH_ASK rfTx; 

void setup(){
  Serial.begin(9600);
  if (!rfTx.init())
    Serial.println("init failed");
}

void loop() {

  int potValue = analogRead(A0);
  char buffer[20];
  sprintf(buffer, "%d", potValue);  //converts integer value potValue to string and stores it in the buffer

  rfTx.send((uint8_t *)buffer, strlen(buffer));
  Serial.println(buffer);
  rfTx.waitPacketSent();
  delay(1);
}

This above code is for an Arduino Nano 433mhz transmitter that uses the RH_ASK library to transmit data wirelessly using the ASK (Amplitude-shift keying) method.

The first line of the code, "#include <RH_ASK.h>", includes the RH_ASK library, which provides functions to communicate using the ASK method. The second line, "#include <SPI.h>", includes the SPI (Serial Peripheral Interface) library, which is used by the RH_ASK library.

The line "RH_ASK rfTx;" declares an object "rfTx" of the RH_ASK class. This object will be used to perform wireless transmission operations.

The "setup()" function initializes the serial communication and sets the baud rate to 9600 baud. Then, it calls the "init()" function of the "rfTx" object. If this function returns "false", it means the initialization failed and an error message is printed.

The "loop()" function is executed repeatedly. It first reads an analog value from the analog pin A0 and stores it in the integer variable "potValue". Then, it converts the integer value to a string and stores it in a buffer "buffer" using the "sprintf()" function.

The "rfTx.send()" function is then used to transmit the string stored in the "buffer" over the wireless channel. The "strlen(buffer)" function is used to determine the length of the string. The "Serial.println(buffer)" function is used to print the buffer to the serial monitor. The "rfTx.waitPacketSent()" function waits until the data transmission is completed. Finally, a delay of 1 millisecond is added using the "delay(1)" function.

Receiver Code

The following code is for Arduino RF 433 receiver.

//Receiver Program
#include <RH_ASK.h>
#include <SPI.h>
#include <Stepper.h>

Stepper myStepper(180, 7, 8, 9, 10);
RH_ASK rf_driver;

void setup() {
  Serial.begin(9600);
  if (!rf_driver.init())
    Serial.println("init failed");
    myStepper.setSpeed(30);
}

void loop() {
  uint8_t buf[12];
  uint8_t buflen = sizeof(buf);
  if (rf_driver.recv(buf, &buflen)) {
    int potValue = atoi((char*)buf);
    int steps = map(potValue, 0, 1023, 0, 200);
    myStepper.step(steps);
    Serial.println(potValue);
    Serial.println(steps);    
  }
}

This Arduino RF 433mhz receiver code receives data wirelessly and controls a stepper motor using the RH_ASK library.

The first line of the code, "#include <RH_ASK.h>", includes the RH_ASK library, which provides functions to communicate using the ASK (Amplitude-shift keying) method. The second line, "#include <SPI.h>", includes the SPI (Serial Peripheral Interface) library, which is used by the RH_ASK library. The third line, "#include <Stepper.h>", includes the Stepper library, which provides functions to control stepper motors.

The line "Stepper myStepper(180, 7, 8, 9, 10);" creates an object "myStepper" of the Stepper class with 180 steps per revolution, and pin numbers 7, 8, 9, and 10 connected to the stepper motor.

The line "RH_ASK rf_driver;" declares an object "rf_driver" of the RH_ASK class. This object will be used to receive wireless data.

The "setup()" function initializes the serial communication and sets the baud rate to 9600 baud. Then, it calls the "init()" function of the "rf_driver" object. If this function returns "false", it means the initialization failed and an error message is printed. The "myStepper.setSpeed()" function sets the speed of the stepper motor to 30 RPM.

The "loop()" function is executed repeatedly. The "rf_driver.recv()" function is used to receive data from the wireless channel and store it in a buffer "buf". The "atoi((char*)buf)" function converts the received data from a string to an integer and stores it in the variable "potValue". If you want to use another method than atoi() function then see the article Different Ways of Converting Integers to Strings for Data Transmission.

The "map(potValue, 0, 1023, 0, 200)" function maps the value of "potValue" from 0 to 1023 to a value between 0 and 200, which represents the number of steps the stepper motor should take. The "myStepper.step(steps)" function makes the stepper motor take "steps" steps. The "Serial.println(potValue)" and "Serial.println(steps)" functions are used to print the value of "potValue" and "steps" to the serial monitor.

Conclusion 

In this article, we have seen how we can control a stepper motor wirelessly with a potentiometer and a 433 MHz RF module. We have also seen the different ways to convert integer data into a string for data transmission. This tutorial can be helpful for anyone looking to control a stepper motor wirelessly, and it can be used in various applications such as automation systems, robots, and so on.

This tutorial is just the beginning, and there is a lot more that can be done with the 433 MHz RF module and Arduino. You can check out our articles on "LED Control with 433MHz RF Module and Arduino" and "Different Ways of Converting Integers to Strings for Data Transmission" for more information. 

References:

- Wireless Control of Stepper Motor with 433MHz RF Module and Arduino

Post a Comment

Previous Post Next Post