I am trying to set up wireless communication between two Arduinos via DFRobot APC220 radio modules. The simplest thing I want to see is: I press a button on one Arduino, the other one flashes the LED. Here is my setup:
Code for Arduino 1 (the transmitting one):
int ledPin = 13;
int myPin = 3;
int prev=LOW;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(myPin,INPUT);
Serial.begin(9600);
}
void loop() {
int a=digitalRead(myPin);
if( a==HIGH && prev==LOW ){
digitalWrite(ledPin,HIGH); // short flash to confirm button press
delay(100);
digitalWrite(ledPin,LOW);
Serial.write(50); // send one byte
}
prev=a;
delay(100);
}
Code for Arduino 2 (the receiving one):
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {}
void serialEvent(){
int b=Serial.read();
if(b>=0){
if(b==50){
digitalWrite(ledPin,HIGH); // long flash to confirm correct reception
delay(500);
digitalWrite(ledPin,LOW);
}else{
for(int i=0;i<3;i++){ // three short flashes to indicate error
digitalWrite(ledPin,HIGH);
delay(100);
digitalWrite(ledPin,LOW);
delay(100);
}
}
}
}
It doesn't work. I press the button, the first Arduino flashes, the second Arduino does nothing. I tried connecting them by wires: GND to GND and TX to RX, this way it works, but wirelessly it doesn't.
How can I find out where is the problem? Does the first APC220 understand my signals, does it transmit anything, does the second one receive something from the air?
Are both APC220 devices ready to work upon applying power to them?
Do I just need to send bytes to Serial and they will come out on the other side? Or should I use AT commands or something?
I did not connect the EN pin, but it is "high" by default, so the device should be always on.
On my APC220, pin 6 is marked AUX. In one datasheet, pin 6 is described as "MUX - expanded for other functions"; in another datasheet and in the wiki, it is "AUX - Receive (low) Transmit (high)". Should I use this pin? I tried to connect it to VCC on the transmit side - still no luck.
I connected both APC220 to computer and set them up via RF-Magic. I have set them to the same frequency, keeping all other parameters unchanged. There are some mysterious settings like "parity" and "stop bits". Should I worry about them from the Arduino side?
I see that many people are successfully working with APC220, but their code is almost identical to mine. Am I missing something obvious?
For some reason I had set the radio frequency of DFRobot to 460 MHz which is outside the allowed range. Probably because the RF-Magic program was showing 470 MHz by default, I thought it to be the current DFRobot frequency and decreased it. Though, it didn't work even before RF-Magic; probably because I had RX and TX connected in the wrong way at that moment.
So, the schematic above is correct. After setting the frequency to 450 MHz it started working. The EN and AUX pins are not required. (Though, I will use EN later to save battery power). If something doesn't work, double-check RX-TX wiring (always connect criss-cross!) and check the radio frequency range.
Hi Goblin. I followed your setup and got everything to work with the exception of the power supply. Both units operate properly when I power them with a/c power adapters (9v output). When the receiver (Uno w/ LED notification) is powered by 9v battery, once it receives a signal notification, the LED continuously blinks and will not shut off. When the transmitter (Uno w/ button) is powered by 9v battery, the transmitter works (LED lights up) but it does not activate the receiver LED. I am using Uno's instead of Mini's. Also, I can't tell from the schematic where the one resistor is connected or it's purpose. Basically, my setup is working on a/c power but not battery power. I'm guessing it's a power issue. Thx in advance.
Probably the issue is caused by wrong voltage. Arduino usually requires 5V or 3.3V input. 9V could be too much. My Arduino is 5V, I'm using four Ni-MH batteries which give about 4.8V and it's OK. (It works even on two batteries but the LED light is dimmer). Are you sure that your AC adapter is also giving 9V? You can try checking it via a multimeter or something. Also, Arduino has a RAW pin which is "unregulated power supply". Try connecting your battery to RAW, and the built-in voltage regulator in Arduino should convert the voltage to the desired 5V.
Chadro:
Also, I can't tell from the schematic where the one resistor is connected or it's purpose.
The resistor is connected to the blue wire (Pin 3) and the black one (GND). It's required to pull Pin3 to ground when the button is not pressed. Pin3 is INPUT; without the resistor, it would be left "unconnected" and would give random results to Arduino.
im facing a problem to initialize the communication between these modules. im already set the frequency to 450Mhz but still not working. is it true that the frequency range is depend on the country. i read this on website.but how i supposely know the frequency range in my country?do your have any idea to solve this problem?
ady88, what did you try? Can you post your schematic and code?
Some ideas what you can do:
Note that there are two versions of the datasheet (first, second), and they may correspond to different versions of the DFRobot module itself. Probably your module doesn't support 450 MHz. Check both manuals and try a different frequency.
Is the Arduino code correct? Connect the two Arduinos to each other directly: GND-GND, RX-TX, TX-RX (note the criss-cross wiring). If the communication still doesn't work, then there is a bug in your code.
Connect one DFRobot to Arduino and the other to the computer using the DFRobot USB-TTL connector. Then, from the Arduino IDE, launch the Serial Monitor. Now you can send bytes to Arduino through DFRobot and see Arduino output in the console. Check both Arduino assemblies this way.
I have followed the steps and its working fine for 450MHz. But i have one question.
Is there any way we can exclusively pair two modules, so that any other device sends 450MHz signal, my receiver should not respond to it. like any id/signature can be set to transmitter and receiver modules.
I want to do a same thing for my project. Do I really need RF magic software to communicate between two arduinos through APC220 and what library do I need for arduino IDE
Can someone please send link to download RF magic software. The one I downloaded is asking for some registration id.