I'm trying to send input to light 1 of 3 leds using my arduino pro with bluetooth module. Ideally, I want to use the arduino Serial Monitor to send commands like 1,2,3 for the menu choices, then have my arduino board with bluetooth module response to those commands. Please help me. XD
I make the assumption that bluetooth.read() is reading the RX pin 0 and bluetooth.write() is writing to the TX pin 1. The only examples I've seen are using the bluetooth module to send data to other bluetooth devices like an Android phone. What's different is I want my bluetooth module to receive data for input to other operations, such as, controlling the direct of a motor.
Example I've seen for sending with the bluetooth module: (interesting, but that is next program I'll work on)
/*
Evan Johnson
Description: test sending serial input to turn on 1 of 3 leds.
*/
#include <SoftwareSerial.h>
int bluetoothTx = 1;
int bluetoothRx = 0;
int led1 = 2;
int led2 = 3;
int led3 = 4;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
// This code will only run once, after each powerup or reset of the board
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
// This code will loops consecutively
Serial.begin(115200);
bluetooth.begin(115200);
delay(100);
Serial.print("Evan's 3 Leds\n");
Serial.print("1 for led1\n");
Serial.print("2 for led2\n");
Serial.print("3 for led3\n");
Serial.print("Your choice: ");
delay(100);
for(int i=0; i<3; i++)
{
digitalWrite(led1, HIGH);
delay(500);
digitalWrite(led1, LOW);
delay(500);
digitalWrite(led2, HIGH);
delay(500);
digitalWrite(led2, LOW);
delay(500);
digitalWrite(led3, HIGH);
delay(500);
digitalWrite(led3, LOW);
delay(500);
}
}
void loop()
{
if(Serial.available())
{
int inputRX = bluetooth.write(Serial.read());
switch(inputRX)
{
case '1':
{
Serial.println("Light led1 for 2 seconds.");
digitalWrite(led1, HIGH);
delay(2000);
digitalWrite(led1, LOW);
break;
}
case '2':
{
Serial.println("Light led2 for 2 seconds.");
digitalWrite(led2, HIGH);
delay(2000);
digitalWrite(led2, LOW);
break;
}
case '3':
{
Serial.println("Light led3 for 2 seconds.");
digitalWrite(led3, HIGH);
delay(2000);
digitalWrite(led3, LOW);
break;
}
default:
{
break;
}
}
}
delay(1);
}