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;
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.
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;
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.
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);
}
}