Attiny85 Bluetooth Relay

Hello guys!

I have a simple question, I want to control my home appliances using Bluetooth, attiny85, and a relay module. It runs perfectly when I simulate it in Proteus.

But after program attiny85 when I connect the relay module and Bluetooth module, it is not working. Please Help me.
no response from attiny85.


#include<SoftwareSerial.h>
#include <util/delay.h>

SoftwareSerial BT_serial(2,3);
char ch;
void setup() 
{
  pinMode(3,OUTPUT);
  pinMode(2,INPUT);
  pinMode(0,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(1,OUTPUT);
  BT_serial.begin(9600); 
  delay(2000);
  BT_serial.println("Bluetooth connected");
}
void loop() 
{   
  while(BT_serial.available())
    {       
       if(BT_serial.available()>0)
        {   
          ch = BT_serial.read();
          if(ch == '1') 
{
  digitalWrite(0,HIGH);
  delay(1000);
  BT_serial.print("TUBE is ON");
}
          if(ch == '2') 
   {
  digitalWrite(0,LOW);
  delay(1000);
  BT_serial.print("TUBE is OFF");
}
if(ch == '3') 
{
  digitalWrite(4,HIGH);
  delay(1000);
  BT_serial.print("FAN is ON");
}
          if(ch == '4') 
   {
  digitalWrite(4,LOW);
  delay(1000);
  BT_serial.print("FAN is OFF");
}
if(ch == '5') 
{
  digitalWrite(1,HIGH);
  delay(1000);
  BT_serial.print("LAMP is ON");
}
          if(ch == '6') 
   {
  digitalWrite(1,LOW);
  delay(1000);
  BT_serial.print("LAMP is OFF");
}
if(ch == '9') 
{
  digitalWrite(0,HIGH);
  digitalWrite(4,HIGH);
  digitalWrite(1,HIGH);
  delay(1000);
  BT_serial.print("ALL Appliences are ON");
}
          if(ch == '0') 
   {
  digitalWrite(0,LOW);
  digitalWrite(4,LOW);
  digitalWrite(1,LOW);
  BT_serial.print("ALL Appliences are OFF");
} 
        }             
    }   
}      

Not sure about simulation but the diodes across the relays are the wrong way around and you’ve no base resistors for the transistors .
It’s a very difficult schematic to read.
There is a guide on this forum for drawing schematics

What is not working ??
Print out the results of the transmission directly to see what you have received as part of your debugging process

Attiny85 is not working

Don't muck with the pins you have assigned to SoftwareSerial. If you remove these two lines, does the Bluetooth device receive the "Bluetooth connected" message?

The 'while' already checked that the function returns a non-zero number and it's not going to be negative so there is no need to check a second time.

Note: This is just the kind of use the switch/case statement was created for:

void loop()
{
  while (BT_serial.available())
  {
    ch = BT_serial.read();
    switch (ch)
    {
      case '1':
        digitalWrite(0, HIGH);
        delay(1000);
        BT_serial.print("TUBE is ON");
        break;

      case '2':
        digitalWrite(0, LOW);
        delay(1000);
        BT_serial.print("TUBE is OFF");
        break;

      case '3':
        digitalWrite(4, HIGH);
        delay(1000);
        BT_serial.print("FAN is ON");
        break;

      case '4':
        digitalWrite(4, LOW);
        delay(1000);
        BT_serial.print("FAN is OFF");
        break;

      case '5':
        digitalWrite(1, HIGH);
        delay(1000);
        BT_serial.print("LAMP is ON");
        break;

      case '6':
        digitalWrite(1, LOW);
        delay(1000);
        BT_serial.print("LAMP is OFF");
        break;

      case '9':
        digitalWrite(0, HIGH);
        digitalWrite(4, HIGH);
        digitalWrite(1, HIGH);
        delay(1000);
        BT_serial.print("ALL Appliences are ON");
        break;

      case '0':
        digitalWrite(0, LOW);
        digitalWrite(4, LOW);
        digitalWrite(1, LOW);
        BT_serial.print("ALL Appliences are OFF");
        break;
    }
  }
}

Thanks, johnwasser Sir,
But I can't understand simulation is running smoothly, After burning the code to Attiny85 the problem is same, the Relay is always on.
I think may be it happens because of power, so I connect the relay module with another power supply then the relay is off No response. I have replaced the relay module with only individual led
But they also no response, always off.
I can't understand whether the microcontroller is receiving the serial from the Bluetooth module or not.
I also change 3 attiny85 and 3 Hc05 Bluetooth Module alternatively but the problem remains same.

When you reset the ATtiny85 are you receiving the "Bluetooth connected" message? If not, you have to get that working first.

Do you have an Arduino UNO you can test on? That would show if the problem was the sketch or the hardware.

No Sir,
I am not receiving "Bluetooth connected" message.

I am programming it using Arduino UNO.

I don't know how can I test it on Arduino UNO.

Move these three functions to spare Arduino UNO pins, like 4, 5, and 6:

  pinMode(0, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(1, OUTPUT);

Connect your Bluetooth device to pins 2 and 3 on the UNO. Select your Arduino UNO in Tools -> Board and Tools -> Port. Then upload your sketch to the UNO.

When I upload this code on Arduino Uno all messages are received And working oppositely while using serial monitor.
At least working. this is okay. I can change opposite to normal.

But when I use Hc 05 and Arduino app terminal mode relay does not work.
Maybe this code is not receiving Bluetooth serial.

#include <SoftwareSerial.h>

SoftwareSerial Serial(1, 2);
Or
SoftwareSerial Serial(0, 1);
Or
SoftwareSerial Serial(3, 4);
Or
SoftwareSerial Serial(2, 3);
Or
SoftwareSerial Serial(4, 0);

No working. Attiny85 is not receiving any serial from Bluetooth.
If receiving then not responding. Please help. :cry: :cry: :cry:

just another example found on the web...

https://create.arduino.cc/projecthub/Arnov_Sharma_makes/attiny85-with-hc-05-bluetooth-module-a36028

https://create.arduino.cc/projecthub/ROBINTHOMAS/attiny85-84-with-bluetooth-579ea0

Thank you so much Sherzaad,
Those examples I also tried.
Does not work.
Maybe the problem is BaudRate.

do you know do to test/setup a HC05? if yes, then check your HC05 settings!

please explain

seriously dude, try using a search engine!!!!

My Bluetooth module default BaudRate is 9600.
I have used the Same BaudRate

SoftwareSerial BT_serial(2,3);
char ch;
void setup() 
{
  pinMode(3,OUTPUT);
  pinMode(2,INPUT);
  pinMode(0,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(1,OUTPUT);
  BT_serial.begin(9600); 
  delay(2000);
  BT_serial.println("Bluetooth connected");
}

But I can't understand why not working. :confused:


But

Simulation is working But after program attiny85, wiring with Bluetooth and led it is not working :disappointed_relieved:

I can't solve the problem till now. Please anyone help me.
I am not receiving any massage.
And also relays are not working when I test in on my breadboard.

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