Attiny85 Serial Communication

I am working with an Attiny85 and an HC-05 bluetooth module trying to turn LEDs on and off using a cell phone. The cell phone is sending number (0-9) and I am trying to get the attiny to respond accordingly. I am using the code below and it is not working. One thing I found was that if I changed the received signal from 1 to -1 it would work, but this did not work with all the numbers, it was also reading the 10 signal as -2. I was wondering if anyone has had something like this happen before where the attiny interprets the signal received as something different than what was sent. I tried changing the baud rate but this did not help either. Please let me know if any additional information is needed.

Thank you,

#include  <SoftwareSerial.h> //Software Serial Port

#define Rx 3
#define Tx 4

SoftwareSerial blueToothSerial(Rx, Tx);

int ledPin1 = 0;      // the pin that the LED is attached to
int ledPin2 = 1;
int ledPin3 = 2;

  //byte serialA;

void setup()
  pinMode(Rx, INPUT);
  pinMode(Tx, OUTPUT);
  // initialize the serial communication:
  // initialize the ledPin as an output:
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);

void loop() {

  digitalWrite(ledPin1, HIGH);
  char recvChar;
    //check if there's any data sent from the remote bluetooth shield
      recvChar =;
        if(recvChar == 0)
          digitalWrite(ledPin1, LOW);
        if(recvChar == 1)
          digitalWrite(ledPin2, LOW);
        if(recvChar == 2)
          digitalWrite(ledPin3, LOW);
        if(recvChar == 3)
          digitalWrite(ledPin1, HIGH);
        if(recvChar == 4)
          digitalWrite(ledPin1, 60);
        if(recvChar == 5)
          digitalWrite(ledPin1, 15);
        if(recvChar == 6)
          digitalWrite(ledPin2, HIGH);
        if(recvChar == 7)
          digitalWrite(ledPin2, 60);
        if(recvChar == 8)
          digitalWrite(ledPin2, 15);
        if(recvChar == 9)
          digitalWrite(ledPin3, HIGH);

        if(recvChar == 0)
          digitalWrite(ledPin1, LOW);

What is sending data to the bluetooth device? Is it really sending binary data? Or should the comparisons be to '0', '1', etc.?

I tried it both ways with just revcChar == 1 and revcChar == '1' and neither way seemed to work correctly.


I am having similar problem with my project were you able to get it to work can you please post me the code if yes :slight_smile: thanks in advance.

I know this is kind of an old topic but didn't see any actual responses to the question and wanted to chime in if anyone finds this topic in the future. I have this same sort of operation running on other atmega chips and wanted to let you know how I made it function. I have no idea if it will work for you on the tiny but I suppose it is worth a shot. Also note i am sending three character codes from my device rather then a single character.

The important bits:

 if (Serial.available()) { 
     char BtInput[]="ZZZ";                      //reset the char array to an unused set
     Serial.readBytes(BtInput, 3);             //read three characters from the array
     if (strcmp(BtInput, "000")== 0) {    
             //stream compare checking stream for 000 an == of 0 is returned if true
         // do something