hi, i'm new to wireless communication . I've been trying out and testing HC-12 modules since the past couple of weeks, I have referred to dozens of videos , articles on how to use the HC-12 , but none of them properly address my doubt, that is , if i am using a sensor to print data onto the Serial monitor , how (through code), will i send that data of the sensor from one arduino device to another arduino device. My project is , i want to send the GPS time from one arduino device to another arduino device , via the HC-12 long range communication module.
If anybody could tell me how to frame the transmitter - receiver code , it would be of great help, because i've been stuck here and constantly trying.
My project code so-far , is attatched for reference (removed the HC-12 part)
#include <NMEAGPS.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
#include <DS3231.h>
#include<Wire.h>
SoftwareSerial gpsPort( 3, 2 );
LiquidCrystal_I2C lcd(0X27, 16, 2);
NMEAGPS gps;
DS3231 rtc(SDA, SCL);
gps_fix currentfix;
NeoGPS::time_t localTime;
void setup()
{
Serial.begin(9600);
gpsPort.begin(9600);
lcd.init();
lcd.backlight();
rtc.begin();
}
void loop()
{
// Dispatch incoming characters
while (gps.available( gpsPort))
{
currentfix = gps.read();
if (currentfix.valid.date && currentfix.valid.time)
{
NeoGPS::clock_t localSeconds;
NeoGPS::time_t localTime;
{
using namespace NeoGPS;
localSeconds = (clock_t) currentfix.dateTime; // convert structure to a second count
localSeconds += 5 * SECONDS_PER_HOUR + 30 * SECONDS_PER_MINUTE; // shift timezone
localTime = localSeconds; // convert back to a structure
}
lcd.setCursor(3,0);
lcd.print( localTime.date );
lcd.print( '/' );
lcd.print( localTime.month );
lcd.print( '/' );
lcd.print( localTime.year );
lcd.setCursor(3,1);
lcd.print( localTime.hours );
Serial.print( localTime.hours );
lcd.print( ':' );
Serial.print( ':' );
if (localTime.minutes < 10) lcd.print(F("0"));
lcd.print( localTime.minutes );
Serial.print( localTime.minutes );
lcd.print( ':' );
Serial.print(':');
if (localTime.seconds < 10) lcd.print(F("0"));
lcd.print(localTime.seconds);
Serial.print( localTime.seconds );
Serial.println();
int a = localTime.hours;
int b = localTime.minutes;
int c = localTime.seconds;
rtc.setTime(a, b, c);
}
else
{
lcd.clear();
lcd.setCursor(3,1);
lcd.print(rtc.getTimeStr());
}
}
}
P.S, i have tried the codes , where i take input through keyboard into the serial monitor , and am successfully able to send the data from Arduino1 to Arduino2. I have also learnt about how to change the channels, set baud rate etc. I haven't been able to connect all the dots by myself.