Arduino Relay Bluetooth control

Looking for someone who is able to write arduino code, and possibly give me a hand on what pins go where on the relay board. Here is all the information I have.

The relay board is a sain smart 16 channel relay board.

The bluetooth module I used is an HC-05

and I am using an Arduino UNO bought right from Arduino.

I am using a custom android app made, that conencts via bluetooth.Will update thread with all the outputs of the app.

Looks interesting. May I ask what the purpose of this project is? What do you want the finished project to look like?

This is for my car. I have a car that I've done allot of work to and I fiberglassed a phone into my vehicle. so I am now looking to control all of my lights I installed etc..

OK. So is each piece of data on a separate line?

I fiberglassed a phone into my vehicle.

Which was likely obsolete before the fiberglass cured.

Isaac96: OK. So is each piece of data on a separate line?

Yes each piece of data is on a seperate line.

10 11 20 21

Data appears like that.

You can use Switch-Case for decoding that, Use Serial.readStringUntil('/n') and read that into a string. Then, use switch(myString){} and use the proper cases to switch each relay. They just use DigitalWrite, correct?

All chinese to me :P Honestly I'd be willing to pay to have it coded out for me. what is digitalwrite?

digitalWrite(pin,level);
you can replace ‘pin’ with whatever pin you are using. Level can be HIGH or LOW or 1 or 0 or True or False.
It will write the pin with the level.
Here is some example code:

#include <SoftwareSerial.h>
SoftwareSerial BT(9, 10);
int relayPin = 5;//Random number: Connect your relay to this pin.
String inString = "";//An empty string
void setup() {
  pinMode(relayPin, OUTPUT); //this configures pin 5 as an output
  digitalWrite(relayPin, LOW); //Sets the pin to 0V.
  BT.begin(9600);//whatever baud rate worked for the other example I gave you
}
void loop() {
  if (BT.available() > 0) {
    inString = BT.readStringUntil('\n');
    if(inString == "11"){
      digitalWrite(relayPin,HIGH);//turns on the LED
    }
    else if (inString == "10"){
      digitalWrite(relayPin,LOW);//turns off the LED
    }
    else{
    }
  }
}

This code will, assuming you have a LED connected to pin 5 and your bluetooth module to pins 9 and 10, switch the LED on and off when you press and release the first button of the android app.
Make sure to put a 330 ohm resistor between it and the Arduino pin.
If it doesn’t work, post pictures.

any diagrams? Gonna try that. whats the resistor for? the led? I have 12v leds would I still need a resistor?

I am guessing the 12V LEDS have resistors built in? Do you have the part information? Anyway, here is a diagram. Switch the TX and RX lines if it doesn't work.

I don't see no resistor in it, I just know that they work off of 12 volts. Here is the product info http://www.oznium.com/prewired-surface-mount-led

Also I did not see any diagram.

Sorry, forgot to attach it. :-![
But do you not have any standard LEDs? Those will be easiest.

circuit.png

Hmm I unfortunately only have the 12v ones. What about my relay board anyway to hook that up to it?

I just tried the code with the 12v led connected to the pin. No luck, do the pins not output 12 volts?

The Arduino pins only output 5V. You could test with a different version of the program which uses the serial monitor.

#include <SoftwareSerial.h>
SoftwareSerial BT(9, 10);
String inString = "";//An empty string
void setup() {
  Serial.begin(9600);//Open the serial monitor with  a baud rate of 9600.
  BT.begin(9600);//whatever baud rate worked for the other example I gave you
}
void loop() {
  if (BT.available() > 0) {
    inString = BT.readStringUntil('\n');
    if(inString == "11"){
       Serial.println("Button pressed!");
    }
    else if (inString == "10"){
     Serial.println("Button released!");
    }
    else{
    }
  }
}

The Serial Monitor is the button in the upper right corner of the Arduino IDE. It has a small magnifying glass on it. When it opens, go to the bottom left corner of the window and there will be a " baud" button. Click it and a small list will pop up. Select “9600 baud”. Start pressing the first button in your android app. Watch the serial monitor.

Is this not what i did the first time to find out the readings? Or will this show a different reading.

Alright, I’ve uploaded the code and I opened the serial monitor. I am not getting any readings. I’ve tried all the baud rates and have swapped rx and tx and still get nothing.

The myserialbegins that worked was 9600 and baud was 57600 so I changed the code acordingly
#include <SoftwareSerial.h>
SoftwareSerial BT(9, 10);
String inString = “”;//An empty string
void setup() {
Serial.begin(9600);//Open the serial monitor with a baud rate of 9600.
BT.begin(57600);//whatever baud rate worked for the other example I gave you
}
void loop() {
if (BT.available() > 0) {
inString = BT.readStringUntil(’\n’);
if(inString == “11”){
Serial.println(“Button pressed!”);
}
else if (inString == “10”){
Serial.println(“Button released!”);
}
else{
}
}
}

And nothing apears to be happening on the serial monitor.

I have tried the led code you previously sent me but used my relay board with my 12v led. The relay clicks when I put the pin 5 onto the relay board, and stays lit up, however I still can't get any reading or change of state using the bluetooth. Unsure as to what is the issue.

Alright did some more troubleshooting, went back to the first codes you gave me and I got the same readings as before 10,11,20,21 etc.. So bluetooth seems to still be working. I then went to the led code you gave me, and the pin 5 does activate the relay, but the relay stays activated and clicking any button on the bluetooth app does nothing, and still no readings on the serial monitor either.