Analog Read & Write between two Arduino's

Thread Starter

Jim_cliff11

Joined Sep 5, 2015
36
Hi all,

Ok, so I have 2 Arduino Nano's. Both with HC-12 RF 433mhz serial wireless boards. I have a basic sketch on both using software serial in which I can transmit and recieve string messages between the two.

My goal is:

Arduino 1:
Read 2 x potentiometer readings using AnalogRead (One pot on each analog pin).
En-code the corrosponding values and send via wifi.

Arduino 2:
Decode and read analog values sent by Arduino 1.
Control 2 seperate FET gates via PWM (AnalogWrite) using the values sent from Arduino 1.

I'm fairly new to the RF HC-12 side of things, but I have this circuit working using just one Arduino without any issues. I just need help with coding to intergrate the transmission of the values from one Arduino to the other.

Ideally, latency rates need to be minimul as to provide rapid responce of the FET's.

Any help grately appreciated.

Many thanks,
Jim
 

Thread Starter

Jim_cliff11

Joined Sep 5, 2015
36
Ok, I've managed to get Arduino 1 transmitting integer values read from a POT to the PC serial port and the software serial which then feeds to the HC-12. Code below:

Code:
//Transmit

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); //RX, TX
const int analogInPin = A0;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() {
 
    mySerial.println(analogRead(analogInPin));
    Serial.println(analogRead(analogInPin));

}
I'm using the following code on Arduino 2:

Code:
//Recieve

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); //RX, TX

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() {
 
    int input = mySerial.read();
    Serial.println(input);   

}
When Arduino 1 is not transmitting Arduino 2 displays -1 per line in the serial window. When Arduino 1 is transmitting the serial monitor on Arduino 2 throws out random numbers between 10 and 60 on each line.

Can anyone help?
Thanks
 
Top