Help me with serial communication on an ATTINY85

Hello, So I have an HC-06 bluetooth module and an attiny85 set up together. Using my smartphone, I'm sending a signal to it, to light up an LED light. I know the problem is in my programming of the attiny, what am I doing wrong?

#include <SoftwareSerial.h>
const int rx = 3;
const int tx = 1;
int light = 2;
int state;

SoftwareSerial mySerial(rx,tx);

void setup() {
pinMode(rx, INPUT);
pinMode(tx, OUTPUT);
pinMode(light, OUTPUT);
mySerial.begin(9600);
}

void loop() {
if(mySerial.available() > 0){
state = mySerial.read();
}

if (state == '1'){
digitalWrite(light, HIGH);
}

if (state == '4'){
digitalWrite(light, LOW);
}
}

First of all pleas edit your original post and put your code in a code box, it's not a quote. The code box icon is (currently) just to the left of the quote icon - it looks like a scroll with < > in front.

You shouldn't have to deal with the pinmode for your serial I/O pins, that is handled by the library and you may just be messing them up when you try to set the mode.

Don

I did that but it didn't work. Is there something I am missing? I am assuming that there is no difference between using this bluetooth module with an Uno and an attiny85?

#include <SoftwareSerial.h>
const int rx = 3;
const int tx = 1;
const int led = 2;
int state;

SoftwareSerial mySerial(rx,tx);

void setup() {
pinMode(led, OUTPUT);
mySerial.begin(9600);
}

void loop() {
if(mySerial.available() > 0){
state = mySerial.read();
}

if (state == '3'){
digitalWrite(led, HIGH);
delay(1000);
}

if (state == '4'){
digitalWrite(led, LOW);
}
}

If you want us to deal with your code then it is essential that you put it into a code box. This is not only for aesthetics it is because the forum software mangles some code.

If you don't understand how to post your code in a code box then you really should read this: How to use this forum - please read.

You probably should also indicate how you have your Arduino and your bluetooth module 'set up together'.

Don

I have the tx pin of the bluetooth module going to the rx pin of the attiny (which I had set up as pin 3). The rx pin of the bluetooth module is going to the tx pin of the attiny (pin 1). I have attached the pinout diagram that I am using. My bluetooth module is the HC-07 module, commonly found on amazon.
Thanks!

#include <SoftwareSerial.h>
const int rx = 3;
const int tx = 1;
const int led = 2;
int state;

SoftwareSerial mySerial(rx,tx);

void setup() {
  pinMode(led, OUTPUT);
  mySerial.begin(9600);
}

void loop() {
  if(mySerial.available() > 0){
    state = mySerial.read();
  }
  
  if (state == '3'){
    digitalWrite(led, HIGH);
    delay(1000);
  }
  
  if (state == '4'){
    digitalWrite(led, LOW);
  }
}

I got everything to work correctly, within limitations. When I have LEDs attached to simulate the motors, it works great. However, as soon as I attach motors instead of LEDs, the motors pulse. I am assuming the issue here is that the data is being sent in 1mhz updates, so there is a slight delay between the data being received? Does anyone know what might be wrong?

#include <SoftwareSerial.h>
const int rx = 3;
const int tx = 1;
const int lMot = 2;
const int rMot = 4;
int state;

SoftwareSerial mySerial(rx,tx);

void setup() {
  pinMode(lMot, OUTPUT);
  pinMode(rMot, OUTPUT);
  mySerial.begin(9600);
}

void loop() {
  if(mySerial.available() > 0){
    state = mySerial.read();
  }
  
  if (state == '1') {
      digitalWrite(rMot, HIGH);
      digitalWrite(lMot, LOW);
      
  }

  if (state == '2') {
      digitalWrite(lMot, HIGH);
      digitalWrite(rMot, LOW);
  }

  if (state == '3') {
      digitalWrite(lMot, HIGH);
      digitalWrite(rMot, HIGH);
      // delay();
    
  }
  
  if (state == '4') {
    digitalWrite(lMot, LOW);
    digitalWrite(rMot, LOW);
  }
}

I am assuming the issue here is that the data is being sent in 1mhz updates

1mHz is one update every 16 minutes 40 seconds.
What makes you think this might be the case?

However, as soon as I attach motors instead of LEDs, the motors pulse

How are you attaching motors instead of LEDs?

sorry I didnt meant 1mhz, I meant it updates every 1/1000 of a second. And the motors are turned on when a transistor is triggered.

What happens is when i send the signal to move forward, it sort of lurches. The motor turns for a moment, shuts off, then resumes moving, then repeats