I am trying to control a set of LEDs with two Arduino Unos using a 433MHz transmitter/receiver.
I am able to send signals from the transmitter and receive them and see them trough the Serial monitor, but I cant get the receiver arduino to output to the LEDs.
Im not sure where the issue is.
When ever I press the 2nd button, which should send '2' I get this on the serial monitor.
"
16:38:09.195 -> 7777Got:
16:38:09.195 -> 7 7 7 7
Can you give a link to where you got this code sample ?
I suspect that part of the problem is here: strlen(msg2) where you are sending the length of a pointer instead of the length of the string. Try strlen(*msg2).
The function driver.printBuffer() appears to print the hex values of the decimal numbers. 33 == 0x21
Ah yes, I must have assumed the original code compiled and did not look too carefully.
I guess the OP should do it like this, to keep the same structure as the original code :
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endif
RH_ASK driver (2000, 11, 12, 0);
int led1pin= 2;
int led2pin= 3;
int led3pin= 4;
int d[3]={0};//LED states
int b[3]={0};//Incoming Signal
int c[3]={0};//Combine state and signal
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 (led1pin, OUTPUT);
pinMode (led2pin, OUTPUT);
pinMode (led3pin, OUTPUT);
}
void loop() {
for (int i = 0; i < 3; i++ ) {
b[i] = 0;
}
uint8_t buflen = sizeof(b);
if (driver.recv((uint8_t*)b, &buflen)) {
for (byte i = 0; i < 3; i++) {
Serial.print(b[i]);
}
}
for (int i=0; i<3; i++ ) { c[i] = b[i] + d[i]; } //Combine state with signal
if (c[0]== 1){
digitalWrite(led1pin, HIGH);
d[0]=1;
}
if (c[0]!= 1) {
digitalWrite(led1pin, LOW);
d[0]=0;
}
if (c[1]== 1){
digitalWrite(led2pin, HIGH);
d[1]=1;
}
if (c[1]!= 1){
digitalWrite(led2pin, LOW);
d[1]=0;
}
for (int i = 0; i < 3; i++ ) {
b[i] = 0;
}
}