Pump not turning on when expect, using bluetooth and parsing data

Hi everyone, so I am using the example 5 from

And it has been changed a bit so that just integers can be parsed. This all works great and parses the data correctly and as intended. However when I send the data from the bluetooth app on my phone to control some pumps, it doesnt work for some reason. I know 100% it is not to do with the wiring because I ran a different sketch before and the pump turns on.

Below is my full code and a screen shot showing that it enters the if statement and parses the data as intended.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];        // temporary array for use when parsing

// variables to hold the parsed data
int Shots = 0;
int Glass_Size = 0;
int pump_num = 0;

boolean newData = false;

//LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2); // Change to (0x27,20,4) for 20x4 LCD
void setup() {


void loop() {

  //lcd.setCursor(1, 0); // Set the cursor on the third column and first row.
  //lcd.print("Please Pick A");
  //lcd.setCursor(1, 1); //Set the cursor on the third column and the second row (counting starts at 0!).
  //lcd.print("Drink from App");

  if (newData == true) {
    strcpy(tempChars, receivedChars);

    newData = false;

  if (pump_num == 2)

    //lcd.setCursor(1, 0); 
    //lcd.print("Your Drink is");
    //lcd.setCursor(1, 1); 
    //lcd.print("Being Made");

    digitalWrite(2, HIGH);
    digitalWrite(2, LOW);




void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (Serial.available() > 0 && newData == false) {
    rc = Serial.read();

    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        if (ndx >= numChars) {
          ndx = numChars - 1;
      else {
        receivedChars[ndx] = '\0'; // terminate the string
        recvInProgress = false;
        ndx = 0;
        newData = true;

    else if (rc == startMarker) {
      recvInProgress = true;


void parseData() {      // split the data into its parts

  char * strtokIndx; // this is used by strtok() as an index

  strtokIndx = strtok(tempChars, ","); // this continues where the previous call left off
  pump_num = atoi(strtokIndx);     // convert this part to an integer

  strtokIndx = strtok(NULL, ",");
  Shots = atoi(strtokIndx);

  strtokIndx = strtok(NULL, ",");
  Glass_Size = atoi(strtokIndx);



void showParsedData() {
  Serial.print("Pump Number ");

  Serial.print("Shots ");

  Serial.print("Glass Size ");

Any help with this would be great.
Thanks in advance.

I hate that phrase.

Yes, the screen shot does show "test" which means pin 2 is going HIGH/LOW, but what is it connected to? How do you have this all wired up? A schematic (hand drawn is okay) would be helpful. Often, it is a missing ground connection between everything or a power issue.

I could do a schematic but ik its not to do with like a lose ground or 5v cause if i switch it to a different sketch the pump does turn on.

And it showing test doesnt mean that pin 2 is going high does it?
Doesnt it mean that it just entered the if statement?

Why did you need to comment that?

This is the only bit of code that produces "test", so if you see it on the monitor, the other things are happening as well = pin2 high, wait, pin2 low, print

If you don't want to provide a schematic or let anyone know what pin 2 is connected to, then I can't help.

Good Luck

Could you possibly think of a less useful comment?


Because it is utterly meaningless.

Why did you need to ask?

Because I just thought its odd for people to go out there way to say they dislike something

I think it's odd that people don't go out of their way to help others to help them.

Thats odd cause i was just making the schematic, you know cause it doesnt appear out of thin air

Here is my schematic for the circuit.
Thanks in advance.

Excellent. And where does the +5V come from? Is the Arduino plugged into your PC and you are powering everything through the USB cable? Or do you have it connected to a wall wart to supply 6-9V to Vin?
Starting your pump could take a lot of initial current to get it going and exceed what can be delivered.

And all those GNDs are tied together??

The 5v has came from both the PC usb and from a 9v wall plug, plugged into the barrel jack. And yes all the grounds are tied.

a 9V wall plug going into the barrel jack means the onboard regulator is supplying all the current and it can only do 500mA, max. It is better to get a 5V wall plug (phone charger) and connect that directly to the 5V on the board. This bypasses the voltage regulator and the max current is dictated by your wall plug (2A?)

Ill try that but shouldnt it not matter as I am using a relay? And that the pump does turn on when using a different sketch

Please confirm that the pump with the current wiring still turns on with that different sketch, and if it does turn on, please post that sketch.

Yes I can confirm that with the current wiring the pump does still turn on with the other sketch
Below is the sketch where the pump did turn on.

char Incoming_value = 0;

void setup()
  pinMode(2, OUTPUT);

void loop()
  if (Serial.available() > 0)
    Incoming_value = Serial.read();
    if (Incoming_value == '2')
      digitalWrite(2, HIGH);
    digitalWrite(2, LOW);

Thanks in advance.

The difference between those two sketches is that, in your first one, pump_num gets the value 2 and then retains that value every time through loop() so you always get the ON/delay/OFF to happen.

Your "test" sketch only turns on if something is available on Serial and that something is '2'

Its ok I fixed it, i didnt include the pinMode(2, OUTPUT).

Thanks in advance.