I have an 8 channel relay, an Arduino Uno, and this HM-10 bluetooth module: https://www.amazon.com/dp/B06WGZB2N4
The Goal Send a number (1-8) from my Android phone via bluetooth to turn a relay on.
The Problem I can't seem to get the bluetooth to reply to anything I send. I'm trying to use "Arduino Bluetooth" from the app store to send commands, but it either errors or ignores me and doesn't do anything. I can't communicate with the bluetooth from the Arduino IDE either.
The wiring I'm SUPER new to small electronics, I suspect I'm not giving the system enough power and might need to give my relay its own 5.5v supply, but here's what I've got:
HM-10 | Uno
-------------------
RX | Digital 3
TX | Digital 2
VCC | 3.3V
GND | GND
Uno | Relay
-------------------
Digital 4 | IN8
Digital 5 | IN7
Digital 6 | IN6
Digital 7 | IN5
Digital 8 | IN4
Digital 9 | IN3
Digital 10 | IN2
Digital 11 | IN1
GND | GND
5V | VCC
The code:
#include <SoftwareSerial.h>
const int relayPins[] = {4, 5, 6, 7, 8, 9,10,11};
SoftwareSerial HM10(2, 3);
void setup() {
Serial.begin(9600);
HM10.begin(9600);
for (int i = 0; i < sizeof(relayPins) / sizeof(relayPins[0]); i++) {
pinMode(relayPins[i], OUTPUT);
digitalWrite(relayPins[i], HIGH); // set relays to OFF
}
}
void loop() {
if (HM10.available() > 0) {
int relayNum = HM10.read() - '0'; // convert ASCII to integer
if (relayNum >= 1 && relayNum <= 11){
digitalWrite(relayPins[relayNum - 1], LOW);
Serial.print("Turned on relay ");
Serial.println(relayNum);
delay(1000); // wait for 1 second
digitalWrite(relayPins[relayNum - 1], HIGH);
Serial.print("Turned off relay ");
Serial.println(relayNum);
}
}
}
-
add some debugging codejsotola– jsotola03/09/2023 06:41:37Commented Mar 9, 2023 at 6:41