Hello!
I am interested also into Larry's problem. I've been searching for hours on the internet for example of codes for the transmitter/receiver to give IDs for the transmitters or so. Nothing found! I am surprised since this is some essential stuff.
I want to put temp/humid sensors in every room in my house, and a central receiver with LCD in living room to display the sensor information from the other rooms.
So, please if you could be more precise, give me an example of how the code should be.
Now I have this sketch... and it works great with one Transmiter and one receiver:
Transmiter:
#include <OneWire.h>
#include <LiquidCrystal.h>
#include <DallasTemperature.h>
#include <VirtualWire.h>
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int led =13;
float tempC = 0;
char msg[6];
void setup() {
sensors.begin();
lcd.begin(16,2);
lcd.clear();
pinMode(3, OUTPUT);
analogWrite(3, 0);
Serial.begin(9600);
vw_set_tx_pin(12); // Sets pin D12 as the TX pin
vw_setup(2000); // Bits per sec
}
void loop() {
sensors.requestTemperatures();
tempC = sensors.getTempCByIndex(0);
delay(1000);
dtostrf(tempC, 6,2,msg); //converts the float into a char
digitalWrite(13, HIGH); // LED ON to show transmitting
vw_send((uint8_t *)msg, strlen(msg)); //transmits the data
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, LOW); // LED OFF stop transmitting
delay(200);
Serial.println(tempC);
lcd.setCursor(0,0);
lcd.print("Temperature is:");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.print(tempC);
lcd.print(" °C");
lcd.clear();
}
and for RECEIVER:
#include <OneWire.h>
#include <LiquidCrystal.h>
#include <DallasTemperature.h>
#include <VirtualWire.h>
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int i;
void setup() {
sensors.begin();
lcd.begin(16,2);
lcd.clear();
pinMode(3, OUTPUT);
analogWrite(3, 0);
Serial.begin(9600);
vw_set_rx_pin(13); //Sets pin D13 as the RX Pin
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
void loop() {
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if( vw_get_message(buf, &buflen) )
{
lcd.setCursor(0, 0);
lcd.print("Temp is:");
lcd.setCursor(3,1);
for (i = 0; i < buflen; i++)
{
lcd.write(buf[i]);
}
lcd.print((char)223);
lcd.print("C");
}
}
so basically for the transmitter are these 4 lines:
dtostrf(tempC, 6,2,msg); //converts the float into a char
vw_send((uint8_t *)msg, strlen(msg)); //transmits the data
vw_wait_tx(); // Wait until the whole message is gone
delay(200);
and for receiver:
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if( vw_get_message(buf, &buflen) )
{
lcd.setCursor(0, 0);
lcd.print("Temp is:");
lcd.setCursor(3,1);
for (i = 0; i < buflen; i++)
{
lcd.write(buf[i]);
}
lcd.print((char)223);
lcd.print("C");
}
How can I modify these to be sure that it does not mixup with other transmiters.
Thank you.
Adrian.