Multiple choices using bluetooth??

Hello,

I am attempting to create a drink machine that links to my phone and pours different drinks according to which button I press. My plan is to connect the Arduino through a relay to pumps that will pump the liquid for a specified time but I have been experimenting with LED lights to get the code right first.

I have created an app through MIT app creator that links to my Bluetooth module on my Arduino. So far I have 2 buttons in the app. When I press button 1 (Bermuda Triangle drink) it works perfectly… pin 9(Rum comes on for 2 seconds, pin 5(Orange) comes on for 2 seconds, and pin 4(Cranberry) comes on for 5 seconds and then everything turns off. PERFECT. When I press button 2 however the lights just seem to go crazy with no pattern that I can perceive. I know the buttons are sending the right number because the serial monitor displays 1 when I press button 1 and 2 when I press button 2. I have been using “if” statements for the button selection… is this the best way to do this? This is my first Arduino project and any help would be MUCH appreciated!

Here is my code,

char data = 0;                //Variable for storing received data

const int Rum = 9;

const int Tequila = 8;

const int Vodka = 7;

const int Sour = 6;

const int Orange = 5;

const int Cranberry = 4;


void setup() 
{
Serial.begin(9600);         //Sets the data rate in bits per second (baud) for serial data transmission
pinMode(Rum, OUTPUT);

pinMode(Tequila, OUTPUT);

pinMode(Vodka, OUTPUT);

pinMode(Sour, OUTPUT);

pinMode(Orange, OUTPUT);

pinMode(Cranberry, OUTPUT);

digitalWrite(Rum, LOW);

digitalWrite(Tequila, LOW);

digitalWrite(Vodka, LOW);

digitalWrite(Sour, LOW);

digitalWrite(Orange, LOW);

digitalWrite(Cranberry, LOW);

      
}
void loop()
{
if(Serial.available() > 0)  // Send data only when you receive data:
{
  data = Serial.read();      //Read the incoming data and store it into variable data
  Serial.print(data);        //Print Value inside data in Serial monitor
  Serial.print("\n");        //New line 
  if(data == '1')            //Bermuda Triangle 
    digitalWrite(Rum, HIGH); 
    delay(4000); 
    digitalWrite(Rum, LOW); 
    digitalWrite(Orange, HIGH); 
    delay(2000); 
    digitalWrite(Orange, LOW);
    digitalWrite(Cranberry, HIGH);
    delay(10000);
    digitalWrite(Cranberry, LOW);    //If value is 1 then LED turns ON
}

  if(data == '2')  //Caribbean Screwdriver
  {
    digitalWrite(Rum, HIGH);
    delay(4000);
    digitalWrite(Rum, LOW);
    digitalWrite(Orange, HIGH);
    delay(12000);
    digitalWrite(Orange, LOW);
  }
}

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Focus your attention here...

  if(data == '1')            //Bermuda Triangle 
    digitalWrite(Rum, HIGH);

Snowboardendude: Here is my code,

Your { } are all wrong. There are none associated with if(data == '1') and the block

if(Serial.available() > 0)  // Send data only when you receive data:
{

terminates before

if(data == '2')

Use the AutoFormat tool to lay out your code and that should be a lot more obvious

...R

It would be far better to create a function for each drink. Call that function, rather than littering loop() with all the code needed to make a martini, a Manhattan, a screwdriver, etc.

PaulS: It would be far better to create a function for each drink. Call that function, rather than littering loop() with all the code needed to make a martini, a Manhattan, a screwdriver, etc.

+1

Have a look at Planning and Implementing a Program

...R