Hi.
I'm making a trollingmotor control with 2 arduino nano and 2 hc-05. But when everthing is connected the servo twitches. After googling i find out that softwareserial is the problem and i want to change to hardwareserial instead, but i don't know how to do it.
Here is the sketch for the receiver
#include <SoftwareSerial.h>
#define BT_SERIAL_TX 4
#define BT_SERIAL_RX 3
SoftwareSerial BluetoothSerial(BT_SERIAL_TX, BT_SERIAL_RX);
#include <Servo.h>
Servo myservo;
unsigned int val ;
void setup()
{
Serial.begin(9600);
BluetoothSerial.begin(9600);
myservo.attach(10);
}
void loop() // run over and over
{
if (BluetoothSerial.available()>0){
val = BluetoothSerial.read();
myservo.write(val);
}
}
And the transmitter
#include <SoftwareSerial.h>
#define BT_SERIAL_TX 4
#define BT_SERIAL_RX 3
SoftwareSerial BluetoothSerial(BT_SERIAL_TX, BT_SERIAL_RX);
int potpin = A0;
unsigned int val;
void setup()
{
Serial.begin(9600);
BluetoothSerial.begin(9600);
}
void loop()
{
val = analogRead(potpin);
val = map(val, 0, 1023, 0, 179);
BluetoothSerial.write(val);
delay(100);
}
edit the post and select the code part and press the </> icon in the tool bar to mark it as code. It's barely readable as it stands. (also make sure you indented the code in the IDE before copying, that's done by pressing ctrlT on a PC or cmdT on a Mac)
the arduino nano has only one hardware serial port and it's used to upload the code so you would have to unplug the BT module every time you want to upload the code.
Software Serial should work at 9600 bauds , just don't use the shotgun approach. Send the new value only when it has changed to minimise traffic. (assuming you don't have to update at fast speed)