Wardemon:
I got my arduinos to communicate with each other by simple blink led code.
Im using 433Mhz RF sender/receiver for it
Welcome to the Forum. Please post the code that you already have. Read the two posts at the top of this Forum by Nick Gammon on guidelines for posting here, especially the use of code tags ("</>") when posting source code files. Also, before posting the code, use Ctrl-T in the IDE to reformat the code in a standard format, which makes it easier for us to read.
Also please tell us which RF units you have, and which library you are using to support them.
// Remote Receiving Temparature and Humidity over RF Link to LCD Display
// how to use VirtualWire to receive messages and display floating point values to SerialMonitor
// rx pin 3 on mega
#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
Serial.begin(9600); // Debugging only
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_set_rx_pin(3);
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)) // Non-blocking
{
int i;
digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i]); // the received data is stored in buffer
}
Serial.println("");
}
}
Transmitter code
// Remote transmitting Temparature and Humidity over RF Link to SerialMonitor
// DHT11 Sensor
#include <VirtualWire.h>// library for RF RX/TX
#undef int
#undef abs
#undef double
#undef float
#undef round
#undef round
#include "DHT.h"
#define DHTPIN 4
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
float temp_c;
float humidity;
int packet = 0;
char charnum[10];
void setup()
{
// Debug Serial.begin(38400);
// Serial.println("Starting up");
// Initialise the IO and ISR
vw_set_tx_pin(3);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
dht.begin();
}
void loop()
{
byte error;
byte rh;
float humival_f;
float tempval_f;
float dew_point_f;
char str[15];
// Read values from the sensor
float temp_c;
float humidity;
temp_c = dht.readTemperature();
humidity = dht.readHumidity();
char buff[30];
sprintf(buff, "%c", 255);
const char *msg0 = buff;
vw_send((uint8_t *)msg0, strlen(msg0)); // Send control character
vw_wait_tx(); // Wait until the whole message is gone
// Serial.print("Temperature = ");
serialPrintFloat(temp_c);
sprintf(buff, "%cC ", 223);
const char *msg1 = buff;
vw_send((uint8_t *)msg1, strlen(msg1));
vw_wait_tx(); // Wait until the whole message is gone
// Serial.print("C");
////////////////////////////////////////////////////////////////////////////////////////
sprintf(buff, "%c", 254);
const char *msg5 = buff;
vw_send((uint8_t *)msg5, strlen(msg5));
vw_wait_tx(); // Wait until the whole message is gone
// Serial.print(" Rel Humidity = ");
serialPrintFloat(humidity);
// Serial.print("%");
const char *msg2 = "% ";
vw_send((uint8_t *)msg2, strlen(msg2));
vw_wait_tx(); // Wait until the whole message is gone
delay(1000);
}
void serialPrintFloat( float f) {
//Serial.print((int)f);
itoa((int)f, charnum, 10);
vw_send((uint8_t *)charnum, strlen(charnum));
vw_wait_tx(); // Wait until the whole message is gone
// Serial.print(".");
const char *msg = ".";
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
int temp = (f - (int)f) * 100;
// Serial.print( abs(temp) );
itoa(abs(temp), charnum, 10);
vw_send((uint8_t *)charnum, strlen(charnum));
vw_wait_tx(); // Wait until the whole message is gone
}
I get strange gibberish on mega receiver end on terminal.
Im trying to measure only celcius and humidity.
Id like to get info as following in terminaldigit, Example: Celsius: 26, Humidity: 50% <-percent mark not needed but I want info as percent
Libraries are virtualwire and DHT-sensor-library-master(from adafruit)
sprintf(buff, "%c", 255);
const char *msg0 = buff;
vw_send((uint8_t *)msg0, strlen(msg0)); // Send control character
// could be
msg0 = 255;
vw_send((uint8_t *)msg0, 1); // Send control character
// or
vw_send((uint8_t *)"\xFF", 1); // Send control character