I am having a lot of inconstant results with my 433mhz set up. I've made a few of these, and every time I get mixed results. Sometimes they work perfectly, sometimes not at all, sometimes only when a few cm away from each other. Sometimes they work great, then just decide to stop working after a few tests.
The set up:
- 433mhz chips, like these https://smile.amazon.com/gp/product/B017AYH5G0/ref=oh_aui_detailpage_o02_s00?ie=UTF8&psc=1
- 17cm wire for antenna
- Arduino Pro Mini (5v)
- Low-profile servo
- 3x AA battery packs for both
- Button on transmitter module for activation
Transmitter:
Receiver:
The antenna problem:
When first starting this project, I didn't know you needed antennas for these chips. When I learned you did, I was using the generic copper Helical antennas for a while. Then I read that a 17cm wire also works, and for a while they were working better. I just had it coming straight off the module.
I then started to try a 34cm wire, half coiled for even better signal - but that was also hit or miss after a few set ups.
The antenna problem part 2:
I read somewhere, on some form post (that I now can't find), that you are supposed to solder together your antenna and the prong next to it (picture below). Not sure if this was true, but upon trying it I did notice an improvement on some set ups.
Chip inconsistencies:
I also have noticed, after going though many of these 433mhz chips from various sellers, two big inconsistencies. First being one of the copper coils missing from some transmitter modules. Second being some copper coils being soldered into the antenna port rather than the normal port.
Servo Power:
The servo is powered from the arduino. I have read this is a no-no, but with how this project is used I have no choice. When the system decided to work, it works flawlessly despite this.
Code:
Now for the code. I have to use ServoTimer2 because the default servo library conflicts with both Virtual Wire and RadioHead (at least it did a year ago when I started this).
Receiver:
#include <RH_ASK.h>
#include <SPI.h>
#include <ServoTimer2.h>
RH_ASK driver(2000,11,12);
ServoTimer2 RFServo;
const int RFServo_pin = 9;
int RFServo_state = 0; //1 = up | 0 = down
int JustMoved = 0; //Check if just moved
void setup()
{
//pinMode(RFServo_pin,OUTPUT);
Serial.begin(9600);
Serial.println("On");
if (!driver.init())
Serial.println("init failed"); //Radiohead Error Check
RFServo.attach(RFServo_pin);
RFServo.write(1000);
delay(1200);
RFServo.detach();
}
void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen)) // Non-blocking
{
driver.printBuffer("Got:", buf, buflen);
if (RFServo_state == 0 && JustMoved != 1){
Serial.println("MOVE to State 1");
RFServo.attach(RFServo_pin);
int i;
for (i = 1801; i > 1000; i -= 25){
RFServo.write(i);
delay(25);
}
RFServo_state = 1;
JustMoved = 1;
//Serial.println("In State 1");
RFServo.detach();
delay(200);
}
if (RFServo_state == 1 && JustMoved != 1){
Serial.println("MOVE to State 0");
RFServo.attach(RFServo_pin);
int i;
for (i = 1000; i < 1801; i += 25){
RFServo.write(i);
delay(25);
}
RFServo_state = 0;
JustMoved = 1;
Serial.println("In State 0");
RFServo.detach();
delay(200);
}
JustMoved = 0;
}
}
Transmitter:
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK driver(2000,11,12);
const int buttonPin = 3;
int buttonState = 0;
int lastButtonState = 0;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP);
if (!driver.init())
Serial.println("init failed"); //Radiohead Error Check
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == LOW){
Serial.print("Push");
const char *msg = "1";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
}
}
What frustrates me the most about this project is half the time the kits I make work flawlessly the first time. Then I have 2-3 that I have to fiddle with for days to get working.
I replace the transmitter and receiver chips in case they are bad, re solder points, adjust antennas, and eventually they normally kick on.
I know the code and the wiring is correct (or correct enough), as it can work perfectly, I just want to know what is wrong that makes it not always work perfectly.