Communication Arduino-Arduino with apc220 v3.0 potentiometer+ledFade , need help

I have x2 apc220 v3.0 and I want to control the brightness of my led with a potentiometer from Arduino to Arduino.

This is my transmitter code:

unsigned int knobValue;        //This is the variable we will use to store the buzzers 
int potpin = 0;

int ledFade = 11;

void setup()
{
 Serial.begin(9600); //APC220's can use the standard Serial communication 
 pinMode(ledFade, OUTPUT);
}

void loop()
{
  
  
  knobValue = analogRead(potpin);
  knobValue = map(knobValue, 0, 1023, 0, 255);
  analogWrite(ledFade, knobValue);
  
 

  delay(100);
}

This is my receiver code:

unsigned int knobValue;                            //This is the variable we will use to store the buzzers 

int ledFade = 11;

void setup()
{
  Serial.begin(9600);          //APC220's can use the standard Serial communication 
  pinMode(ledFade, OUTPUT);
  
}

void loop()
{
  


  if (Serial.available() > 0)  //While there is a serial connection available...
  {        
    
     
     knobValue = Serial.read();           //Read the incoming serial data and store it to data
     
    
     analogWrite(ledFade, knobValue);   // change the brightness of the led

     
    
  }
}

I believe that I made the logic correctly. But I am missing something; because I cannot control my led's brightness with my potentiometer from other arduino.

Please, would you show me where am I missing or doing wrong ? thank you very much.
I am new at this wireless communication and there is not solid tutorial on the internet for using apc220 v3.0 too ( at least the way I want to use ).

There is no Serial.print or write in the transmit code. You aren't sending anything.
Analog inputs are A0 to A5. 0 might work but A0 will for sure and is more readable.

I think that you may be better off using a software serial library for the APCs so you can use hardware serial for sending debug prints to serial monitor.

groundfungus:
There is no Serial.print or write in the transmit code. You aren't sending anything.
Analog inputs are A0 to A5. 0 might work but A0 will for sure and is more readable.

I think that you may be better off using a software serial library for the APCs so you can use hardware serial for sending debug prints to serial monitor.

would you give me a small example for software serial how to use on with apc220 please ? or at least a link that I can follow as a beginner at this wireless communication for apc220 ? I am really confused after a point because I cannot find a working example the way I want to take it as a base while coding the way I want for my coding experience. On the internet, the examples I checked, everyone wrote in a different way; so at the end I am really confused ( there is no solid and clear tutorial to explain how these are working successfully by showing it on an example ). At the end, I wanted to ask to friends of this forum to get some help.

APC220 information has a lot of info on setup and use of the APC220 radios. You will need the rf magic program to setup the radios. If you are running win10, make sure to run the rf magic program as an admin or it might not work.

Software serial library is in the IDE supplied libraries. There is example code with the library.

The following two sketches show how to use software serial with the APC radios. It has been tested on my two Uno boards with attached APC220 radios. Note the serial rate is 38400 for the serial between the Uno and radio. You will need to set the rate to what the radios that you have are set to. Wire Arduino pin 4 to APC TX and pin 5 to APC RX.

Receive code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 5); // RX, TX

void setup()
{
  Serial.begin(115200);  // make sure serial monitor is set to this rate
  mySerial.begin(38400); // change this to the rate set in rf magic.
}


void loop()
{
  if(mySerial.available())
  {
     Serial.print(char(mySerial.read()));     
  }
  
}

Transmit code: Sends "hello" every second to the receiver

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 5); // RX, TX
unsigned long timer;
unsigned long interval = 1000;

void setup()
{
  Serial.begin(115200); // make sure serial monitor is set to this rate
  mySerial.begin(38400); // change this to the rate set in rf magic.
}

void loop()
{
  if(millis() - timer >= interval)
  {
    timer = millis();
    Serial.println("send");  // shows in serial monitor
    mySerial.println("hello");
  }

}

There are better software serial libraries, but this one comes with the IDE so is easier for a new user.
Once you get the radios to talk we can work on sending the data that you want to.

groundfungus:
The following two sketches show how to use software serial with the APC radios. It has been tested on my two Uno boards with attached APC220 radios. Note the serial rate is 38400 for the serial between the Uno and radio. You will need to set the rate to what the radios that you have are set to. Wire Arduino pin 4 to APC TX and pin 5 to APC RX.

Receive code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 5); // RX, TX

void setup()
{
Serial.begin(115200); // make sure serial monitor is set to this rate
mySerial.begin(38400); // change this to the rate set in rf magic.
}

void loop()
{
if(mySerial.available())
{
Serial.print(char(mySerial.read()));
}

}





Transmit code: Sends "hello" every second to the receiver


#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 5); // RX, TX
unsigned long timer;
unsigned long interval = 1000;

void setup()
{
Serial.begin(115200); // make sure serial monitor is set to this rate
mySerial.begin(38400); // change this to the rate set in rf magic.
}

void loop()
{
if(millis() - timer >= interval)
{
timer = millis();
Serial.println("send"); // shows in serial monitor
mySerial.println("hello");
}

}





There are better software serial libraries, but this one comes with the IDE so is easier for a new user.
Once you get the radios to talk we can work on sending the data that you want to.

I hope I am done correctly. This is what I am getting now. Am I done correctly ?

I believe I am ready for the next step. Please teach me more the way I want please ( " Potentiometer+led fade/brightness control and potentiometer+servo communication and control between Arduino and Arduino " ). Thank you very much for helping me, I am very happy to do and at least I am able to communicate with my Arduino(s) now.

Here is code to read a potentiometer, send to second Uno, read the data and fade the LED. For sending and receiving more complex messages (servo commands) refer to serial input basics. The link shows how to format, send and parse serial messages.

Transmit code:

#include <SoftwareSerial.h>

unsigned int knobValue; //This is the variable we will use to store the buzzers

const byte potpin = A0;
const byte ledFade = 11;

SoftwareSerial mySerial(4, 5); // RX, TX
unsigned long timer;
unsigned long interval = 100;

void setup()
{
  Serial.begin(115200); // make sure serial monitor is set to this rate
  mySerial.begin(38400); // change this to the rate set in rf magic.
  pinMode(ledFade, OUTPUT);
}

void loop()
{
  knobValue = analogRead(potpin);
  knobValue = map(knobValue, 0, 1023, 0, 255);
  analogWrite(ledFade, knobValue);

  if(millis() - timer >= interval)
  {
    timer = millis();
    Serial.print("send ");  // shows in serial monitor
    Serial.println(knobValue);
    mySerial.write(knobValue); // use write to send binary byte
  }

}

Receive code:

#include <SoftwareSerial.h>

const byte ledFade = 11;

SoftwareSerial mySerial(4, 5); // RX, TX

void setup()
{
  Serial.begin(115200);  // make sure serial monitor is set to this rate
  mySerial.begin(38400); // change this to the rate set in rf magic.
  pinMode(ledFade, OUTPUT);
}


void loop()
{
  if(mySerial.available())
  {
    byte ledValue = mySerial.read(); 
    Serial.println(ledValue);
    analogWrite(ledFade, ledValue);    
  }
  
}

groundfungus:
Here is code to read a potentiometer, send to second Uno, read the data and fade the LED. For sending and receiving more complex messages (servo commands) refer to serial input basics. The link shows how to format, send and parse serial messages.

Transmit code:

#include <SoftwareSerial.h>

unsigned int knobValue; //This is the variable we will use to store the buzzers

const byte potpin = A0;
const byte ledFade = 11;

SoftwareSerial mySerial(4, 5); // RX, TX
unsigned long timer;
unsigned long interval = 100;

void setup()
{
Serial.begin(115200); // make sure serial monitor is set to this rate
mySerial.begin(38400); // change this to the rate set in rf magic.
pinMode(ledFade, OUTPUT);
}

void loop()
{
knobValue = analogRead(potpin);
knobValue = map(knobValue, 0, 1023, 0, 255);
analogWrite(ledFade, knobValue);

if(millis() - timer >= interval)
{
timer = millis();
Serial.print("send "); // shows in serial monitor
Serial.println(knobValue);
mySerial.write(knobValue); // use write to send binary byte
}

}




Receive code:


#include <SoftwareSerial.h>

const byte ledFade = 11;

SoftwareSerial mySerial(4, 5); // RX, TX

void setup()
{
Serial.begin(115200); // make sure serial monitor is set to this rate
mySerial.begin(38400); // change this to the rate set in rf magic.
pinMode(ledFade, OUTPUT);
}

void loop()
{
if(mySerial.available())
{
byte ledValue = mySerial.read();
Serial.println(ledValue);
analogWrite(ledFade, ledValue);
}

}

I upload the code. I don't have problem at transmitter but my receiver doesn't led on my led from transmitter commands. I was used uno then I used mega for receiver to see if sth wrong with my arduin board. Then I checked all wirings too and thy are correct too. But I cannot fade or bright my led.

My transmitter Arduino board's TX led is blinking all the time , I believe it sends the data successfully; but the receiver board nothing happens. Would you tell what might be the problem ? and how to solve it.

Should I buy a new arduino board or maybe the apce220 again ? I don't know why receiver side doesn't work :frowning:

When I was bought my apc220 modules newly, I was tried these two example from internet ( https://www.youtube.com/watch?v=RNzsBLjvpVM&feature=share and https://www.youtube.com/watch?v=ukbKR1QwNHI&feature=share ) and thy were working; so I believe that there is no problem with my apc220 modules too. But still I don't know what is the cause :frowning:



The code that I posted has been tested on my Unos with APC radios and works well. The APC radios are a bit tricky to get set up. You must be able to use rf magic app to check their default setup and change the radio or sketch setup as necessary. See PM.

Note that the serial rate in my sketches are 38400. You will probably need to change that to the series baud rate that your radios are set to.


my settings are correct ?

I set my apc220 modules like that both of them with same values. Then I click first write W and then read R buttons to apply the options to both modules.

if led doesn't work would we try to do servo one maybe ? for the last 3 days I try to do this successfully but every time a problem occurs and I generally cannot find the cause too at this wireless communication. Should I buy original R3 uno or mega then try again ?


It is working but the problem is " the receiver doesn't receive the commands fast enough; but the opposite very slow " that is to say it doesn2t fade or become brighter at the same time of potentiometer values. Do you know how to fix it or is there anyone else might know it ? thank you.