bluetooth and irreceiving

Would someone be kind enough to show me how to fix this problem… i’m controlling a mini bot from my phone and sending an ir signal too but when i send the signal i can’t receive the signal as if its blocking my receiving code

ROBOTWARSV2.ino (4.64 KB)

SoftwareSerial BT(50,51 ); //TX, RX respetively

This implies that you have a Mega.

void setup() {
 BT.begin(9600);
 strip.begin();
  strip.show(); 
 Serial.begin(9600);
 irrecv.enableIRIn();
  pinMode(12, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(11, OUTPUT);
  colorWipe(strip.Color(0, 0, 255), 10);
}

This makes it perfectly clear that you are NOT using Serial1, Serial2, or Serial3. So, why the hell are you using SoftwareSerial?

how should it be implied?

SAMHAWK:
how should it be implied?

How should what be implied?

You need to get rid of the #include statement for SoftwareSerial.h. You need to get rid of the creation of the BT instance. You need to rename all the BT appearances to Serial1, Serial2, or Serial3, after you connect the BT device to the appropriate hardware serial instance's pins.

ok thanks for your help i'll give it a try

how to code the serial 1 instead of the BT?

SAMHAWK:
how to code the serial 1 instead of the BT?

I do not understand the question. The Serial1 instance already exists, and has code behind it. Just use it (in place of the BT instance).

OK ILL GIVE IT ANOTHER TRY

Serial1 (50, 51);//TX, RX respetively

Arduino: 1.6.12 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

ROBOTWARSV2:8: error: 'Serial1' does not name a type

Serial1 BT(50, 51);//TX, RX respetively

^

C:\Users\sambo\Desktop\SSFBC_BT\ROBOTWARSV2\ROBOTWARSV2.ino: In function 'void loop()':

ROBOTWARSV2:31: error: 'serial' was not declared in this scope

while (serial.available()){ //Check if there is an available byte to read

^

exit status 1
'Serial1' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

ROBOTWARSV2:8: error: 'Serial1' does not name a type

It isn't a type.

I said

You need to get rid of the creation of the BT instance.

which meant to delete line 8 completely.

ROBOTWARSV2:31: error: 'serial' was not declared in this scope

while (serial.available()){ //Check if there is an available byte to read

The instances of the HardwareSerial class for which you might want to see whether there is data to read are Serial, Serial1, Serial2, and Serial3. Nowhere in that list is anything called serial.

OK ive done that and it compiled perfectly. it worked like before but with also the same problem as before.

Once connected to the bluetooth, i send an IR code through the bluetooth using a button in an app. after shooting this code i cannot receive a 'HIT' it's like the receive code is jammed or blocked in some way.

I appreciate your patience

So, you've made some changes, and want us to guess what your code now looks like. I'll pass.

i only made the changes you said to do.

#include <IRremote.h>
#include <Adafruit_NeoPixel.h>
#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(11*1, PIN, NEO_GRB + NEO_KHZ800);
IRsend irsend;//TX, RX respetively
String readdata;
int vSpeed=100;
int RECV_PIN = 2;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {
Serial1.begin(9600);
strip.begin();
strip.show();
Serial.begin(9600);
irrecv.enableIRIn();
pinMode(12, OUTPUT);
pinMode(10, OUTPUT);
pinMode(5, OUTPUT);
pinMode(11, OUTPUT);
colorWipe(strip.Color(0, 0, 255), 10);

}
//-----------------------------------------------------------------------//
void loop(void) {
while (Serial1.available()){ //Check if there is an available byte to read
delay(10); //Delay added to make thing stable
char c = Serial1.read(); //Conduct a serial read
readdata += c; //build the string- “forward”, “reverse”, “left” and “right”
}
if (readdata.length() > 0) {
Serial.println(readdata);

if(readdata == “forward”)
{
analogWrite(10, vSpeed);
analogWrite (12, LOW);
analogWrite(5,vSpeed);
analogWrite(11,LOW);
delay(100);
}

else if(readdata == “back”)
{
analogWrite(10, LOW);
analogWrite(12, vSpeed);
analogWrite(5, LOW);
analogWrite(11,vSpeed);
delay(100);
}

else if (readdata == “right”)
{
analogWrite (10,vSpeed);
analogWrite (12,LOW);
analogWrite (5,LOW);
analogWrite (11,LOW);
delay (100);

}

else if ( readdata == “left”)
{
analogWrite (10, LOW);
analogWrite (12, HIGH);
analogWrite (5, vSpeed);
analogWrite (11, LOW);
delay (100);
}

else if ( readdata == “reload”)
{
rainbowCycle(5);
}

else if (readdata == “stop”)
{
digitalWrite (10, LOW);
digitalWrite (12, LOW);
digitalWrite (5, LOW);
digitalWrite (11, LOW);
delay (100);
}

else if (readdata == “shoot”)
{
irsend.sendNEC(0x189710EF, 32);
delay(40);
}

readdata="";

}

//Reset the variable
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);

if (results.value == 0xFF30CF) {
Serial.println(“Button1”);
colorWipe(strip.Color(255, 0, 0), 1); // Red
delay(100);
colorWipe(strip.Color(0, 0, 255), 10);
}
irrecv.resume(); // Receive the next value
}
delay(100);
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
#ifdef DEBUG
Serial.print(“set pixel “);
Serial.print(i);
Serial.print(” of “);
Serial.print(strip.numPixels());
#endif
strip.setPixelColor(i, c);
#ifdef DEBUG
Serial.println(” - ok”);
#endif
//delay(wait);
}
strip.show();
}

void rainbow(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(wait);

}
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();

delay(wait);

for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();

delay(wait);

for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}

IRsend irsend;//TX, RX respetively

What does that comment have to do with that code?

Once connected to the bluetooth, i send an IR code through the bluetooth using a button in an app.

What, exactly, is the bluetooth device paired to? If it is paired with the phone, and handling serial data, then it is NOT being used to receive IR data.

What does your Serial output tell you is happening?

that //tx rx part was when i removed the Softwareserial code that you said to delete so ignore that.

i think you hit the answer with the receive code not being included in the BT serial data. how to add the receive code into the bt serial with the rest of the code?

also the serial monitor doesnt show the receive code after i shoot. would i have to use a while function? for example while serial1 is connected allow the receive code to operate?

Do you actually have an IR receiver connected to the Arduino? Your phone is sending IR data using a IR diode, modulated at some frequency. It is NOT sending IR data over the bluetooth device.