Lima Moreira
Published © GPL3+

Discover how to comunicate two Arduino in 1000 m of distance

You'll learn how to create a comunication using two Arduinos through HC-12 Module.

IntermediateFull instructions provided3 hours250
Discover how to comunicate two Arduino in 1000 m of distance

Things used in this project

Hardware components

NEXTPCB Printed Circuit Board
×1
HC-12 Module
×1
Breadboard (generic)
Breadboard (generic)
×1
LED (generic)
LED (generic)
×2
Resistor 1k ohm
Resistor 1k ohm
×2
PTS 645 Series Switch
C&K Switches PTS 645 Series Switch
×2

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Electronic Schematic and Gerber Files

Code

Transmiter Code

Arduino
#include <SoftwareSerial.h> // Inclui a biblioteca Software Serial
SoftwareSerial HC12(8,7); // 8 RX vai ligado no Tx do modulo HC 12, 7 TX vai
ligado no RX do módulo
#define B0 2
#define B1 3
void setup()
{
 pinMode(B0,INPUT);
 pinMode(B1,INPUT);
 Serial.begin(9600);
 HC12.begin(9600);
}
void loop() 
{
 if(!digitalRead(B0))
 {
 Serial.println("B0 pressionado ");
 Serial.print('1');
 HC12.print('1');

 while(digitalRead(B0)==0);
 }
if(!digitalRead(B1))
 {
 Serial.println("B1 pressionado ");
 Serial.print('2');
 HC12.print('2');

 while(digitalRead(B1)==0);
 }
}

Receiver Code

Arduino
#include <SoftwareSerial.h> // Inclui a biblioteca Software Serial

SoftwareSerial HC12(8,7); // 8 RX vai ligado no Tx do modulo HC 12, 7 TX vai
ligado no RX do módulo

#define red 4
#define blue 3
char comando = 0;

void setup()
{
 pinMode(red,OUTPUT);
 pinMode(blue,OUTPUT);
 Serial.begin(9600);
 HC12.begin(9600);
 Serial.println("Receptor");
 digitalWrite(blue,1);
 delay(300);
 digitalWrite(blue,0);
 delay(300);
}

void loop()
{
 while(HC12.available()>0)
 {
 comando = HC12.read();
 Serial.println(comando);
 switch(comando)
 {
 case '1' : digitalWrite(red,!digitalRead(red));
 break;
 case '2': digitalWrite(blue,!digitalRead(blue));
 break;
 }
 }
} 

Credits

Lima Moreira

Lima Moreira

8 projects • 2 followers

Comments