I am making wireless rainwater tank meter with relay. Will use a uno with temp sensor, relay driver and rf board talking to a mega with tft display and rf board.
Only aspect I am not sure about is how to send 3 variables (temp, humidity, level) over rf from uno to mega and how to send a flag from mega back to uno to turn on relay.
Any help with coding on the rf modules would be appreciated.
I looked at the product you referenced. It is apparently a bare bones type radio, where you toggle a pin on the transmitter, and it either sends out 10 mw. sine wave, or it's off (also known as on-off keying, OOK). That means that you've got to invent your own data transmission protocol -- there aint no advanced features of any kind here.
I'd suggest that you go look up the RFM22B transceiver modules -- just a tiny bit more expensive, but they offer actual built-in data transmission through a high level library (Radiohead). They also provide 100 mw. output power, which gives you much better range.
Once you climb the modest learning curve involved, that little radio will be your friend for life.
Those radios work well with the VirtualWire or RadioHead libraries. Experiment with the provided simple examples and make sure you understand them before adapting to your project.
Range depends almost entirely on the antenna and line of sight conditions. I get over 300 meters range with those modules (doing similar reporting jobs) with a balanced dipole antenna, as shown in the photo below.
Connect one interior end of the antenna to ANT and the other to GND on both TX and RX, with very short wires if necessary. For 433 MHz, the antenna should be about 33 cm from tip to tip.
I use those cheap RF modules OP linked to, and with VirtualWire, it sends a character string up to 27 characters.
They are entirely capable of doing what you want. Except you need two pairs if you want to send data both ways, since transmit module only transmits, receive module only receives.
I was playing with a set of these last week they work great with the serial set a 1200 ran them for about 2 hours no lost data. But you have to watch using delay's.
I was just using software serial.
I didnt realize that unit was so low powered! Ideally I dont really want a long antenna protruding as this unit is to mount nicely on the wall, are there any models which function up to around 50m with small 10cm max antennas?
I use a single 17 cm wire. I haven't tried coiling it up but if all you need is 50m, it should still be fine for your application if you do that.
I wouldn't call them low powered, assuming you are indirectly referencing range. As they come they're still beating typical IR remote range and the Bluetooth range of peripherals.
As a first approximation, take about 25cm of wire, and wind all but the last 10 cm into a loose coil - about 2cm
dia, 1cm spacing. Feed your transmitter/receiver into the base of the coil to drive, put the coil and 10cm part in as clear a place as possible.
Check out LowPowerLabs as they have open-source libraries, code examples, and unique hardware to solve almost any low-power RF issue in the hobby field.
Module data from pin 12 with vcc & gnd
LED on pin 5 to gnd
#include <VirtualWire.h>
int ledPassive = 5; //standby light
void setup()
{
pinMode(ledPassive,OUTPUT);
vw_set_ptt_inverted(true);
vw_set_rx_pin(12); // set receiver pin
vw_setup(4000); // Bits per sec
vw_rx_start(); // Start Phase Locked Loop (listening to the receiver)
}
void loop()
{
digitalWrite(ledPassive,HIGH);
uint8_t buf[VW_MAX_MESSAGE_LEN]; // 80 bytes is messgage length
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) { // if message received
if(buf[0]=='X'){ // and if the first letter in message array is X
digitalWrite(ledPassive,LOW);
}
else if(buf[0]!='X'){
digitalWrite(ledPassive,HIGH);
}
Tried this tut but the blink teste (tutorial 1) does not even work, my reciever might be susspect...
Just getting 1 & 2 when monitoring on terminal with TX on or off.
Try putting a delay after the writing LOW to turn off the LED. It may just be turning right back on right away since you have writing HIGH at the beginning of every single loop.
You can't use delay it blocks the reading of your transmitter. You need use blink without delay. I tried code with delay and if I had more then 100 ms it errors
You don't need to be reading your transmitter while the receiver is executing a function because of a trigger.
I don't have a delay for my LED marker setup because I have it as a toggle. You can try this bit just to confirm whether the setup is working and not just an improper use of LED handling:
if (vw_get_message(buf, &buflen))
{
boolean static state = false;
if (buf[0] == 'X') {
digitalWrite(ledPin, state);
state = !state;
}
}