I connected a bt module (Hc - 06), arduino uno and 5v module. all the connects are perfect. ie: BT module Vcc - Arduino 5v
BT module GND - Arduino GND
BT module RX - Arduino TX
BT module TX - Arduino RX
Relay module (connected with seperate 5v supply) signal pin - Arduino pin 3
When i programmed the following code into the arduino:
const int relayPin = 3; // Relay signal pin to arduino digital pin 3
int state; // State will store income data from serial port
int flag; // Flag variable will help us to control on/off function with only one command
void setup()
{
pinMode(relayPin, OUTPUT); // Set relay pin (3) as output
Serial.begin(9600); // Initialize serial communication at 9600 bits per second
}
void loop()
{
if(Serial.available() > 0){
state = Serial.read(); // Save income data to variable 'state'
}
//If state is equal with letter 'W', turn leds on or of off
if (state == 'W') {
if (flag==0){
digitalWrite(relayPin, HIGH);
flag=1;
}
else if (flag==1){
digitalWrite(relayPin, LOW);
flag=0;
}
state='n';
}
delay(200); // Small delay..
}
..
When i connect the BT with my mobile and try to control the relay with the application (that sends letter "W") nothing happens? IS something wrong with my arduino or BT module?