HM-10 Bluetooth OK+CONLED ON

Hello everyone! I bought an HM-10 bluetooth module to communicate with my Arduino Uno via iPhone. I want to control a TIP120 transistor with a PWM signal to manage an exhaust valve in my car. The valve needs a short 10% PWM signal to open the valve and a short 90% PWM signal to close the valve.

I tested my code with an LED instead of the transistor to see if it works but I now run into the problem where the LED on port ∼9 turns on when my iPhone is initially connected to the HM-10 module, without sending any specific signal/command to turn it on. When I look into the serial monitor I see:

OK+CONLED ON
NLED ON
LED ON
LED ON
LED ON
LED ON
...

This means that irl, once I connect the app to the module on the Arduino, the transistor will let electricity flow through the transistor, which means the valve will be powered with a wrong signal, and for too long.

In conclusion, I don't want it to send any amount of power to the output port all through the connecting process until I actually send a signal/command via Bluetooth to make port ∼9 power on.

Is this something wrong in the code? (I'm quite new to coding). And if so, what can I do about it.

I will post the code I used on this topic ASAP.

Thanks in advance!

#include <SoftwareSerial.h>
SoftwareSerial HM10(2, 3); // TX = 2, RX = 3
char appData;  
String inData = "";
void setup()
{
  Serial.begin(9600);
  Serial.println("HM10 serial started at 9600");
  HM10.begin(9600); // set HM10 serial at 9600 baud rate

}

void loop()

{
{
  HM10.listen();  // listen the HM10 port
  while (HM10.available() > 0) {   // if HM10 sends something then read
    appData = HM10.read();
    inData = String(appData);  // save the data in string format
    Serial.write(appData);
  }
}

  if (Serial.available()) {           // Read user input if available.
    delay(10);
    HM10.write(Serial.read());
  }
  if ( inData == "F") {
    Serial.println("LED OFF");
    analogWrite(9, 25.5); // OPEN VALVE (10% PWM)
    delay(200);
    analogWrite(9, 0); // PWM to 0V
  }
  if ( inData == "N") {
    Serial.println("LED ON");
    analogWrite(9, 229.5); // CLOSE VALVE (90% PWM)
    delay(200);
    analogWrite(9, 0); // PWM to 0V
  }
  
}

Try setting your code so that when the phone connects the HM-10 or when your board is powered on, set the value to be off. (Turning it off when the board powers on can be done through the setup section)

What app are you using to control the HM-10 with the iPhone? I’m stuck on finding a decent app that lets me connect the module to my phone

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.