I am playing around trying to get an infrared sensor to turn on a relay, like a light using 2 Arduino Unos. There are some great tutorials to do this, but the goal is to make them talk through Bluetooth.
Was able to program the HC-05 Modules to master and slave. They are talking to each other.
Goal is:
Slave Code Send
IR sensor detects (1) ==> Open serial.port 38400 and send (1) via HC-05 Bluetooth Slave
Master Code Receive
Serial.port 38400 message received (1) by HC-05 Bluetooth Master ==> Open Relay for 5 minutes
The fire code works, the relay code works, but where in the world do I insert my bluetooth serial lines?
Your problem is unclear, and why you should have one is even less clear, but, if you have blueteeth talking to each other, you have done all the hard stuff. You say your code works, which may be true but I think it is still suss. You should have the transmitter serial port open continuously, i.e. in setup, and simply print through it when needed in the loop. If it works anyway, all you need do is disconnect the wires and put blueteeth in their place. The thing you have to know is that there is no such thing as bluetooth serial code, they use the same code as any other serial. Essentially bluetooth is "serial without wires."
After posting, I realize it was not clear enough. Here is my slave telling the master to turn on a relay after the IR sensor is triggered. Thoughts? Was convinced I had it!
// Slave Code
#define firesensor 8
int firesensorState = 0;
void setup() {
pinMode(firesensor, INPUT);
Serial.begin(38400); // Bluetooth Communication Rate
}
I have programmed the Hc-05's to 38400. Maybe the term "Serial code" is not correct, but I am still trying to know why my code isn't sending a simple on/off via Bluetooth with a delay to keep the light on.
The code looks good and checks out. When I hook it up the relay is stuck on and the slave is only showing Rx lights flashing.
I noticed that I do not have a digitalWrite in the slave setting the low value for the firesensor. Is this causing there to be no distinction between on/off=high/low?
Cjohns44:
I never thought about connecting them by wire to see if it is working. This would be be via tx/rx, of both boards, together?
Correct. By using hardware serial, you can prove your code is kosher before you even connect bluetooth, which can do wonders for your confidence. Disconnect Blueteeth and connect Arduinos Rx>Tx and Tx>Rx. Arduino neither knows nor cares what it is connected to, it is just talking to the serial port - hence my comment about bluetooth serial code.
I'm afraid I don't know anything about relays and LEDs but you said the individual codes worked OK, so now is the time to suspect the wiring. Having said that, I would have guessed a pin set high stays high until set low.