Hello all,
I'm trying to program two boards to communicate via 433mhz chips. Using radiohead library I'm sending a
"A", "B","C" respectively using push buttons to the other end when the other receives the one it lights up led. The problem is that either the message isn't being sent or it's not being received. Either way, when I press my button nothing happens.
Transmitter Module:
// ask_transmitter.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to transmit messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) transmitter with an TX-C1 module
// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy, ESP-12
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endif
RH_ASK driver;
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
// RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),
// RH_ASK driver(2000, PD14, PD13, 0); STM32F4 Discovery: see tx and rx on Orange and Red LEDS
const int button_a = 2;
const int button_b = 3;
const int button_c = 4;
void setup()
{
#ifdef RH_HAVE_SERIAL
Serial.begin(9600); // Debugging only
#endif
if (!driver.init())
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#else
;
#endif
pinMode(button_a, INPUT_PULLUP);
pinMode(button_b,INPUT_PULLUP);
pinMode(button_c,INPUT_PULLUP);
}
void loop()
{
const char *msg1 = "A";
const char *msg2 = "B";
const char *msg3 = "C";
if (digitalRead(button_a)) {
driver.send((uint8_t *)msg1, strlen(msg1));
Serial.println("its here alse 1");
driver.waitPacketSent();
Serial.println("its here 1");
delay(200);
Serial.println("Button pressed! 1");
delay(1000); // Add a delay to prevent continuous readings while the button is pressed
}
if (digitalRead(button_b)) {
driver.send((uint8_t *)msg2, strlen(msg2));
driver.waitPacketSent();
delay(200);
Serial.println("Button pressed! 1");
delay(1000); // Add a delay to prevent continuous readings while the button is pressed
}
if (digitalRead(button_c)) {
driver.send((uint8_t *)msg3, strlen(msg3));
driver.waitPacketSent();
delay(200);
Serial.println("Button pressed! 1");
delay(1000); // Add a delay to prevent continuous readings while the button is pressed
}
}
Transmittor Circuit
Receiver Module:
// ask_receiver.pde
// -*- mode: C++ -*-
// Simple example of how to use RadioHead to receive messages
// with a simple ASK transmitter in a very simple way.
// Implements a simplex (one-way) receiver with an Rx-B1 module
// Tested on Arduino Mega, Duemilanova, Uno, Due, Teensy, ESP-12
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endif
RH_ASK driver;
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
// RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),
// RH_ASK driver(2000, PD14, PD13, 0); STM32F4 Discovery: see tx and rx on Orange and Red LEDS
const int led_a = 7;
const int led_b = 6;
const int led_c = 5;
void setup()
{
pinMode(led_a, OUTPUT);
pinMode(led_b, OUTPUT);
pinMode(led_c, OUTPUT);
#ifdef RH_HAVE_SERIAL
Serial.begin(115200); // Debugging only
#endif
if (!driver.init())
#ifdef RH_HAVE_SERIAL
Serial.println("init failed");
#else
;
#endif
}
void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.available()) // Non-blocking
{
int i;
String a = "";
// Message with a good checksum received, dump it.
// driver.printBuffer("Got:", buf, buflen);
for (int i = 0; i < buflen; i++)
{
//Serial.println("main :: ");
//Serial.print((char)buf[i]);
a = a + (char)buf[i];
}
Serial.println(a);
if (a == "A") {
digitalWrite(led_a, HIGH);
Serial.println("in If");
} else if (a == "B") {
digitalWrite(led_b, HIGH);
Serial.println("in ElseIf");
}
else if (a == "C") {
digitalWrite(led_c, HIGH);
Serial.println("C");
}
}
}
Receiver Circuit :


