Trouble interpreting RF messages

Hi:

I'm trying to implement a motion detection system with multiple sensors on Arduino Nanos all talking to a central Arduino Uno system using the inexpensive RF 433MHz receiver & transmitter chips. I've gotten the sensors on the Nano to work and send a 2 character code where the first character is the sensor number and the second character is a 1 (motion detected) and a 0 (motion finished).

The receiver Base_Unit receives the code and it is properly echoed in a simple serial.print of the message. My trouble is when I try to decode the message to determine the sensor number and the on/off code so I can turn on and off a specific LED to signal that a remote sensor has seen motion.

The difficulty lies in the conversion of *char (which I understand is a pointer) to a char variable so I can do an if test to define variables to use in if tests to illuminate the proper LED. I am enough of a newbie with Arduino/C program that I do not know how to deal with the *char definition.

I've attached both my Motion_Sensor.ino sketch for the transmitter and the Base_Unit.ino sketch for the receiver. The Base_Unit.ino sketch does not compile at present because of the invalid/ambiguous character statements.

However, a slightly different sketch did compile (but with several compiler warnings) and verified that the codes were being sent and received as a sensor detected motion and lack of motion. The problem lies in how I decipher the received code to do the if tests.

Any advice would be greatly appreciated!!

Base_Unit.ino (1.91 KB)

Motion_Sensor.ino (3.82 KB)

You are in luck! The C and C++ programming languages let you use a character pointer as it it were a character array.:

pointer[0]
pointer[1]
etc.

Hi:

Thanks for your quick answer.

However, I believe I tried exactly what you suggest and it doesn't work. On compilation I get the following messages:

Base_Unit:45: error: conversion from 'uint8_t {aka unsigned char}' to 'String' is ambiguous

  • String Sensor = buf[0];*
  • ^*
    D:\Jeff\Documents\Hobbies\Microprocessors\Arduino\Motion Sensor\Base_Unit\Base_Unit.ino:45:28: note: candidates are:
    In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:223:0,
  • from sketch\Base_Unit.ino.cpp:1:*
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:61:2: note: String::String(const __FlashStringHelper*)
    String(const __FlashStringHelper *str);
  • ^*
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:61:2: note: no known conversion for argument 1 from 'uint8_t {aka unsigned char}' to 'const _FlashStringHelper*'
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:59:2: note: String::String(const char*)
    _ String(const char *cstr = "");
  • ^*
    C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/WString.h:59:2: note: no known conversion for argument 1 from 'uint8_t {aka unsigned char}' to 'const char*'
    Base_Unit:46: error: conversion from 'uint8_t {aka unsigned char}' to 'String' is ambiguous

Don't use big-S Strings if you're only storing a single character. Change that variable to be a char and then the assignment will work.

You can also add explicit casts to tell the compiler that you really did intend to put a single character into a String.

Hey MorganS:

That clarified it for me and I now have it working ... Thanks!

jproehl