/*

Attiny 85 version
Working program to command a relay with an Attiny85 over a bluetooth connection.
Using this you can command up to 3 relays using your phone or tablet.
ATTiny 85 : Commands 3 relays using D2 (pin 7) D3 (pin2) and D4 (pin3)
D0 (pin 5) and D2 (pin 6)are used for connection with the bluetooth
module.
Relais 2

|
ATtiny85
| Module Bluetooth
|
|
|
-1° 8-(Vcc)
|
Relay 2 <-----|--(D3)-2 7-(D2)-----|----> Relay 1
Relay 3 <-----|--(D4)-3 6-(D1) RXD-|----> TXD(pin4)
| (GND)-4 5-(D0) TXD-|----> RXD(pin5)
The blueytooth module is a HC06 module and works as a slave module
default baudrate 9600
AVR frequency 8Mhz
*/
#include <SoftwareSerial.h>
//Software Serial Port
#define TxD 0 //pin 5 from Attiny85 to pin RXD of the bluetooth module
#define RxD 1 //pin 6 from Attiny85 to pin TXD of the bluetooth module
SoftwareSerial blueToothSerial(RxD,TxD);
int relay = 2; // pin 2 commands the relay
void setup()
{
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
blueToothSerial.begin(9600);
pinMode(relay,OUTPUT);
}
void loop()
{
char recvChar;
while(1)
{
if(blueToothSerial.available())
{
recvChar = blueToothSerial.read();
if(recvChar == '0')
{
{digitalWrite(relay, LOW);} // relay off
}
else if(recvChar == '1')
{
{digitalWrite(relay, HIGH);} // relay on
}
}
}
}