RF/TF 433MHZ potentiometer problems

Hi, I'm using an Arduino Uno and mega as well as a 433mhz communication module and a potentiometer to control a motor. but I've run into some problems. The reading is being transmitted properly but the motor only turns on and off and the speed is not adjusted

please any help is appreciated thank you

here's my code for receiver

#include <VirtualWire.h>
int in1 = 8;
int in2 = 9;
int ConA = 10;
int speed1;


void setup() {
  Serial.begin(9600);
  vw_setup(2000);
  vw_rx_start(); 
  Serial.println("Value : ");
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
}

void TurnMotorA(){
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
   int transmit;
  
  byte wireless = sizeof(int);
  vw_wait_rx();
  if (vw_get_message((byte *) &transmit, &wireless)) {
    
    speed1 = (transmit);
    speed1 = speed1*0.2492668622;
    //speed1 = speed1*1;
    
  }
  analogWrite(ConA, speed1);
  delay(1000);
  Serial.println(speed1);
}

void loop() {
   TurnMotorA();
   
  }```

What does the Serial.print present?

Hi, the serial presents the values of the potentiometer which are values between 0 and 255, and actually works but the problem is the motor only turns on at value 255 and is off the rest of the values so I don't know what is wrong

Print the value of speed1 after that calculation.
With integer math that evaluates to speed * 0.

If you want to scale 1023 to 255, just divide by 4.

hi, I realise the motor only turns on when the value is 255. can you help me with some code that can solve this problem, I'm trying to wirelessly control this motor using a potentiometer

Here is some code:

Sender:

// Include RadioHead Amplitude Shift Keying Library
// data to Uno pin 12
#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

const byte potPin = A0;

void setup()
{
   // Initialize ASK Object
   Serial.begin(9600);
   Serial.println("starting potentiometer transmitter");
   rf_driver.init();
}

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 200;
   if (millis() - timer >= interval)
   {
      timer = millis();      
      int potValue = analogRead(potPin);
      rf_driver.send((uint8_t*)&potValue, sizeof(potValue));
      Serial.print("sending ... ");
      Serial.println(potValue);
      rf_driver.waitPacketSent();
   }
}

Receiver:

// Include RadioHead Amplitude Shift Keying Library
// data to Uno pin 11
#include <RH_ASK.h>
#include <SPI.h>

const byte pwmPin = 5;
const byte dirPin = 4;

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

int inputValue = 0;

void setup()
{
   // Initialize ASK Object
   rf_driver.init();
   // Setup Serial Monitor
   Serial.begin(9600);
   Serial.println("starting potentiometer receiver");
   pinMode(dirPin, OUTPUT);
   digitalWrite(dirPin, LOW);   
}

void loop()
{
   uint8_t buflen = sizeof(inputValue);
   // Check if received packet is correct size
   if (rf_driver.recv((uint8_t*)&inputValue, &buflen) && buflen == sizeof(inputValue))
   {
      // Message received with valid checksum
      Serial.println("Message Received: ");
      Serial.print("input value = ");
      Serial.println(inputValue);
      Serial.println();
      byte pwmOut = inputValue / 4;
      analogWrite(pwmPin, pwmOut);     
   }
}

Code is tested and is known to control speed of motor connected to receiver in accordance with values from a potentiometer connected to the sender. Sender and receiver are Unos with 433MHz transmitter and receivers connected to them.

thank you for your code but it still won't work. I've tested it without any communication by using a single board, potentiometer and motor and it works, as soon as I use the RF/TF, the motor only moves at the highest value so don't know what is wrong

Me either. I have no idea what your circuit looks like, my crystal ball is broken.

Here is the circuit that I used to successfully test the code with real hardware.

OK, I showed you mine, now show me yours. Post a schematic. Hand drawn, photographed and posted is fine. Include all components, their part numbers and/or values and all power supplies.

Post clear photos of the project and wiring.

Post the exact code that you loaded to the transmitter and receiver Arduino boards. Read the forum guidelines to see how to properly post code and some good information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Hi,
here is a rough picture of my setup of the receiver

#include <VirtualWire.h>
int in1 = 8;
int in2 = 9;
int ConA = 10;
int speed1;


void setup() {
  Serial.begin(9600);
  vw_setup(2000);
  vw_rx_start(); 
  Serial.println("Value : ");
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
}

void TurnMotorA(){
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
   int transmit;
  
  byte wireless = sizeof(int);
  vw_wait_rx();
  if (vw_get_message((byte *) &transmit, &wireless)) {
    
    speed1 = (transmit);
    speed1 = speed1/4;
    //speed1 = speed1*1;
    
  }
  analogWrite(ConA, speed1);
  delay(1000);
  Serial.println(speed1);
}

void loop() {
   TurnMotorA();
   
  }

the transmitter is like so

#include <VirtualWire.h>

void setup() {
  vw_setup(2000);
}
 
void loop() {
  int transmit = analogRead(A0);
  vw_send((byte *) &transmit, sizeof(transmit)); 
  vw_wait_tx(); 
}

hopes this helps you to help me
thanks,

That is sending hundreds if not thousands of messages per second. Way too fast. Slow it down with a delay or the millis() method from my example code. Did you

Are you really trying to run a motor off of a smoke alarm battery?

Don't put the delay in the receiver. Put it in the transmitter. Then the receiver can be ready for incoming data instead of stuck with its head up its hoohoo waiting for the delay to time out.
Is the correct speed number being printed?

1 Like

I tried ur suggestion but it still didn't work, and to answer ur question about the smoke alarm battery, it's actually a 12v power supply. I hooked up a voltmeter and when the value is 255 there's power but other than that value there is no power whatsoever.

Does that mean that you could control the motor speed with the potentiometer.

Mine is on vacation...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.