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
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
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
// 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
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.
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?
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.