I have an Arduino Mega with a 433MHz RF Module Receiver and a Uno with the Transmitter. it is setup so that when the Mega receives the message "Hello World", it triggers the transistor to light an LED. meanwhile, I am trying to get the Uno to transmit the message when I push a button connected to pin 8, however, there are two problems.
-
the Arduino reads putting a cable (with no voltage running through it) in the pin socket as "HIGH" and will then send the message
-
the Arduino UNO will send two of the messages (one once then the second four seconds later) each time I put the cable in the pin socket
If anyone could help me it would be appreciated - here is the code:
Transmitter (Arduino UNO):
`
#include <RH_ASK.h> // Include RadioHead Amplitude Shift Keying Library
#include <SPI.h> // Include dependant SPI Library
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
Serial.begin(9600);
}
void loop()
{
if (digitalRead(8)==HIGH){
const char *msg = "Hello World";
rf_driver.send((uint8_t *)msg, strlen(msg));
rf_driver.waitPacketSent();
// Message Transmitted
Serial.println("Message Transmitted: Hello World");
digitalWrite(13,HIGH);
delay(4000);
}
}
` ` `
` ` `
Receiver (Arduino Mega):
#include <RH_ASK.h> // Include RadioHead Amplitude Shift Keying Library
#include <SPI.h> // Include dependant SPI Library
// Create Amplitude Shift Keying Object
RH_ASK rf_driver;
void setup()
{
// Initialize ASK Object
rf_driver.init();
// Setup Serial Monitor
Serial.begin(9600);
}
void loop()
{
// Set buffer to size of expected message
uint8_t buf[11];
uint8_t buflen = sizeof(buf);
// Check if received packet is correct size
if (rf_driver.recv(buf, &buflen))
{
// Message received with valid checked-sum
Serial.print("Message Received: ");
Serial.println((char*)buf);
digitalWrite(6,HIGH);
delay(500);
digitalWrite(6,LOW);
}
}
` ` `