Radiohead transmitter not working

I have been trying to make a simple circuit that wirelessly controls a motor with a potentiometer. I am using 315 rf transmitter and recievers. I am using a led in place of the motor for tests. I have got the code to transmit the data to the reciever but when it gets there, the led does fade brighter and lighter if I move the potentiometer but it keeps flashing. I have a theory that the flashing is because it takes too long to process but I don't know. I have spent many hours working on this I hope someone can help. Note some code I used off other videos and changed it to work for my thing. Here is the receiver code:

#include <RH_ASK.h>
// Include dependant SPI Library
#include <SPI.h>

int pwmPin = 12; // assigns pin 12 to variable pwm
int c2 = 0; // declares variable c2

String int_out;
int c11 = 0;

// Create Amplitude Shift Keying Object
RH_ASK rf_driver;

void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
pinMode(pwmPin, OUTPUT);
Serial.begin(9600);
}

void loop()
{
// Set buffer to size of expected message
uint16_t data;
uint16_t xyz = data;
uint8_t datalen = sizeof(data);
if ( rf_driver.recv((uint8_t*)&data, &datalen)
&& datalen == sizeof(data))
{
c11 = data;
int c2 = 1024-c11;
Serial.println(c11);
digitalWrite(pwmPin, HIGH);
delayMicroseconds(c11);
digitalWrite(pwmPin, LOW);
delayMicroseconds(c2);
}
}

Why all this? You already know the size of "data" is 2 bytes, because you assigned it that way.
Paul

I got that off of another post here [https://forum.arduino.cc/t/arduino-433-mhz-rf-sending-numbers-instead-of-strings/619707] If I am correct then what it does is recieves the message and processes it for more use.

Have you tried debugging by printing the results on the serial monitor?
Paul

Yes I have. I have tried many things the only thing I tried that had somewhat progress was when I put this:

Serial.println(c11);
digitalWrite(pwmPin, HIGH);
delayMicroseconds(c11);
digitalWrite(pwmPin, LOW);
delayMicroseconds(c2);

Outside of the if statement, the light would stay still and not flash but it would only change if I moved potentiometer and for some reason on the reciever close and reopen the serial monitor.

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