Bluetooth module
Wiring
Wiring diagram for HC-05 Bluetooth module ()
The voltage divider is needed for the RX pin because it can't tolerate 5V from the Arduino (needs 3.3 or lower). I think I broke one HC-05 by hooking it up without the voltage divider.
As a reminder, RX on the module goes to TX on the board, and TX on the board goes to RX on the module.
https://howtomechatronics.com/tutorials/arduino/arduino-and-hc-05-bluetooth-module-tutorial/
Code
This is the base code I used:
// This program shown how to control arduino from PC Via Bluetooth
// Connect ...
// arduino>>bluetooth
// D11 >>> Rx
// D10 >>> Tx
//Written By Mohannad Rawashdeh
//for http://www.genotronex.com/
// you will need arduino 1.0.1 or higher to run this sketch
#include <SoftwareSerial.h>// import the serial library
SoftwareSerial Genotronex(10, 11); // RX, TX
int ledpin=13; // led on D13 will show blink on / off
int BluetoothData; // the data given from Computer
void setup() {
// put your setup code here, to run once:
Genotronex.begin(9600);
Genotronex.println("Bluetooth On please press 1 or 0 blink LED ..");
pinMode(ledpin,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if (Genotronex.available()){
BluetoothData=Genotronex.read();
if(BluetoothData=='1'){ // if number 1 pressed ....
digitalWrite(ledpin,1);
Genotronex.println("LED On D13 ON ! ");
}
if (BluetoothData=='0'){// if number 0 pressed ....
digitalWrite(ledpin,0);
Genotronex.println("LED On D13 Off ! ");
}
}
delay(100);// prepare for next data ...
}
From here: https://www.instructables.com/Arduino-AND-Bluetooth-HC-05-Connecting-easily/
When turning the Bluetooth module on and off, it seems to stay paired pretty well.
Relay for motor
Transistor control for relay
I had to use two transistors (I think in a Darlington pair) for the Arduino to actually actuate the relay.
Also see Arduino Bluetooth with NodeJS