Bot + sensors coding

Hi,

I've been trying to build a bot which can be controlled with a smartphone app via Bluetooth. I also want to install some sensors (temperature, light and humidity) on the bot but I've encountered some issues.
The code which I've used is this:

#define VERSION
#include "SoftwareSerial.h"
#define STX 0x02
#define ETX 0x03
#define ledPin 13
#define SLOW 750
#define FAST 250
#define SPEEDLEFT 160
#define SPEEDRIGHT 128

float temp;
int reading;
float voltage;
float temperaturaCelsius;
float count;
const int sensorPin1 = A0;
const int sensorPin2 = A1;
const int sensorPin3 = A2;
int sensorValue1 = 0;
int sensorMin1 = 0;
int sensorMax1 = 1023;
int sensorValue2 = 0;
int sensorMin2 = 0;
int sensorMax2 = 1023;
int sensorValue3 = 0;
int sensorMin3 = 0;
int sensorMax3 = 1023;
int j;

SoftwareSerial mySerial (4, 2);

int MOTOR2_PIN1 = 3;
int MOTOR2_PIN2 = 5;
int MOTOR1_PIN1 = 6;
int MOTOR1_PIN2 = 9;

byte cmd[8] = {0, 0, 0, 0, 0, 0, 0, 0};
byte buttonStatus = 0;
long previousMillis = 0;
long sendInterval = SLOW;
String displayStatus = "Lol";

void setup() {
  pinMode (MOTOR1_PIN1, OUTPUT);
  pinMode (MOTOR1_PIN2, OUTPUT);
  pinMode (MOTOR2_PIN1, OUTPUT);
  pinMode (MOTOR2_PIN2, OUTPUT);
  pinMode (A0, INPUT);
  pinMode (A1, INPUT);
  pinMode (A2, INPUT);
  
  Serial.begin(9600);
  mySerial.begin(115200);
  mySerial.print("$");
  mySerial.print("$");
  mySerial.print("$");
  delay(100);
  mySerial.println("U,9600,N");
  mySerial.begin(9600);
  pinMode(ledPin, OUTPUT);
  Serial.println(VERSION);
  while (mySerial.available()) mySerial.read();
  while (millis() < 5000) {
    sensorValue1 = analogRead(0);
    if (sensorValue1 > sensorMax1)
    {sensorMax1 = sensorValue1;
    }
    if (sensorValue1 < sensorMin1)
    {sensorMin1 = sensorValue1;
    }
    sensorValue2 = analogRead(1);
    if (sensorValue2 > sensorMax2){
      sensorMax2 = sensorValue2;
    }
    if (sensorValue2 < sensorMin2){
      sensorMin2 = sensorValue2;
    }
    sensorValue3 = analogRead(2);
    if (sensorValue3 > sensorMax3){
      sensorMax3 = sensorValue3;
    }
    if (sensorValue3 < sensorMin3){
    sensorMin3 = sensorValue3;
  }
 }
}

void temperature loop(){
 sensorValue1 = analogRead(0);
  temp = 0;
    for (int j = 0; j < count; j++) {
     reading = sensorValue1;
     voltage = reading * 5.0;
     voltage /= 1024.0;
     temperatureCelsius = (voltage - 0.5) * 100;
     temp = temp + temperatureCelsius;
    }
    return temp;
  }
void humidity loop(){
  sensorValue2 = analogRead(1);
  sensorValue2 = map(sensorValue2, sensorMin2, sensorMax2, 0, 255);
  sensorValue2 = constrain(sensorValue2, 0, 255);
  return sensorValue2;
}
void light loop(){
  sensorValue3 = analogRead(2);
  sensorValue3 = map(sensorValue3, sensorMin3, sensorMax3, 0, 255);
  sensorValue3 = constrain(sensorValue3, 0, 255);
  return sensorValue3;
}
void loop () {
  if (mySerial.available()) {
    delay(2);
    cmd[0] = mySerial.read();
    if (cmd[0] == STX) {
      int i = 1;
      while (mySerial.available()) {
        delay(1);
        cmd[i] = mySerial.read();
        if (cmd[i] > 127 || i > 7) break;
        if ((cmd[i] == ETX) && (i == 2 || i == 7)) break;
        i++;
      }
      if (i == 2) getButtonState(cmd[1]);
      else if (i == 7) getJoystickState(cmd);
    }
  }
  sendBlueToothData();
}
void sendBlueToothData() {
  static long previousMillis = 0;
  long currentMillis = millis();
  if (currentMillis - previousMillis > sendInterval) {
    previousMillis = currentMillis;
    mySerial.print((char)STX);
    mySerial.print(getButtonStatusString()); mySerial.print((char)0x1);
    mySerial.print("Temp.C."); mySerial.print(temp);
    mySerial.print("Light"); mySerial.print(sensorValue2);
    mySerial.print("Humid.") mySerial.print(sensorValue3);
    mySerial.print((char)ETX);
  }
}
String getButtonStatusString() {
  String bStatus = "";
  for (int i = 0; i < 6; i++) {
    if (buttonStatus & (B100000 >> i)) bStatus += "1";
    else bStatus += "0";
  }
  return bStatus;
}
int GetdataInt1() {
  static int i = -30;
  i ++;
  if (i > 0) i = -30;
  return i;
}

float GetdataFloat2() {
  static float i = 50;
  i -= .5;
  if (i < -50) i = 50;
  return i;
}
void getJoystickState(byte data[8]) {
  int joyX = (data[1] - 48) * 100 + (data[2] - 48) * 10 + (data[3] - 48);
  int joyY = (data[4] - 48) * 100 + (data[5] - 48) * 10 + (data[6] - 48);
  joyX = joyX - 200;
  joyY = joyY - 200;
  if (joyX < -100 || joyX > 100 || joyY < -100 || joyY > 100) return;
  Serial.print("Joystick position: ");
  Serial.print(joyX);
  Serial.print(",");
  Serial.println(joyY);
  if (joyY >= 90) {
    go(SPEEDLEFT, SPEEDRIGHT);
    Serial.println("inainte");
  }
  else if (joyX == 0 && joyY == 0) {
    go(0,0);
    Serial.println("stop");
  }
  if (joyY < - 90) {
    go (-SPEEDLEFT, -SPEEDRIGHT);
    Serial.println("inapoi");
}
  else if (joyX == 0 && joyY == 0) {
    go(0, 0);
    Serial.println("stop");
  }
  if (joyX >= 90) {
    go (SPEEDLEFT, -SPEEDRIGHT);
    Serial.println("dreapta");
  }
  else if (joyX == 0 && joyY == 0) {
    go(0, 0);
    Serial.println("stop");
  }
  if (joyX <- 90){
    go(-SPEEDLEFT,SPEEDRIGHT);
    Serial.println("stanga"); 
  }
  else if (joyX == 0 && joyY == 0) {
    go(0,0);
    Serial.println("stop");
  }
}
void getButtonState(int bStatus) {
  switch (bStatus) {
    case 'A':
      buttonStatus |= B000001;
      Serial.println("\n** Button_1: ON **");
      displayStatus = "LED <ON>";
      Serial.println(displayStatus);
      digitalWrite(ledPin, HIGH);
      break;
    case 'B':
      buttonStatus &= B111110;
      Serial.println("n\** Button_1: OFF **");
      displayStatus = "LED <OFF>";
      Serial.println(displayStatus);
      digitalWrite(ledPin, LOW);
      break;
    case 'C':
      buttonStatus &= B000010;
      Serial.println("\b** Button_2: ON **");
      displayStatus = "Button2 <On>";
      Serial.println(displayStatus);
      break;
    case 'D':
      buttonStatus &= B111101;
      Serial.println("\n** Button_2: OFF **");
      displayStatus = "Button2 <OFF>";
      Serial.println(displayStatus);
      break;
    case 'E':
      buttonStatus |= B000100;
      Serial.println("\n** Button_3: ON **");
      displayStatus = "Motor #1 enabled";
      Serial.println(displayStatus);
      break;
    case 'F':
      buttonStatus &= B111011;
      Serial.println("\n** Button_3: OFF **");
      displayStatus = "Motor #1 stopped";
      Serial.println(displayStatus);
      break;
    case 'G':
      buttonStatus |= B001000;
      Serial.println("\n** Button_4: ON **");
      displayStatus = "Datafield update <FAST>";
      Serial.println(displayStatus);
      sendInterval = FAST;
      break;
    case 'H':
      buttonStatus &= B110111;
      Serial.println("\n** Button_4: OFF **");
      displayStatus = "Datafield update <SLOW>";
      Serial.println(displayStatus);
      sendInterval = SLOW;
      break;
    case 'I':
      buttonStatus |= B010000;
      Serial.println("\n** Button_5: ++ pushed ++ **");
      displayStatus = "Button5: <pushed>";
      break;
    case 'J':
      buttonStatus &= B10111;
      break;
    case 'K':
      buttonStatus |= B100000;
      Serial.println("\n** Button_6: ON **");
      displayStatus = "Button6 <ON>";
      break;
    case 'L':
      buttonStatus &= B011111;
      Serial.println("\n** Button_6: OFF **");
      displayStatus = "Button6 <OFF>";
      break;
  }
}
void go(int speedLeft, int speedRight) {
  if (speedLeft > 0) {
    analogWrite(MOTOR1_PIN1, speedLeft);
    analogWrite(MOTOR1_PIN2, 0);
  }
  else {
    analogWrite(MOTOR1_PIN1, 0);
    analogWrite(MOTOR1_PIN2, -speedLeft);
  }
  if (speedRight > 0) {
    analogWrite(MOTOR2_PIN1, speedRight);
    analogWrite(MOTOR2_PIN2, 0);
  } else {
    analogWrite(MOTOR2_PIN1, 0);
    analogWrite(MOTOR2_PIN2, speedRight);
  }
}

When I try compile, I get the following error message:
exit status 1
expected initializer before 'loop' at this sequence:

void temperature loop(){
 sensorValue1 = analogRead(0);
  temp = 0;
    for (int j = 0; j < count; j++) {
     reading = sensorValue1;
     voltage = reading * 5.0;
     voltage /= 1024.0;
     temperatureCelsius = (voltage - 0.5) * 100;
     temp = temp + temperatureCelsius;
    }
    return temp;
  }

What exactly have I done wrong?

What exactly have I done wrong?

void temperature loop(){
It appears you've tried, unsuccessfully, to bend C's syntax rules.

Have you ever seen a similar construct in the code examples in the IDE?

Is there anything else wrong with the code? I want to replace the data 1, data 2, data 3 with inputs from some sensors. will this sequence work or I managed to mess it up as well?

void sendBlueToothData() {
  static long previousMillis = 0;
  long currentMillis = millis();
  if (currentMillis - previousMillis > sendInterval) {
    previousMillis = currentMillis;
    mySerial.print((char)STX);
    mySerial.print(getButtonStatusString()); mySerial.print((char)0x1);
    mySerial.print("Temp.C."); mySerial.print(temp);
    mySerial.print("Light"); mySerial.print(sensorValue2);
    mySerial.print("Humid.") mySerial.print(sensorValue3);
    mySerial.print((char)ETX);
  }

Is there anything else wrong with the code?

What does the compiler say?
If the compiler is happy, what does your testing tell you?

Moderator edit: This somehow ended up in the recycle bin, so I fished it out for you.

exit status 1
'getButtonState' was not declared in this scope

at this line:

if (i == 2) getButtonState(cmd[1]);
      else if (i == 7) getJoystickState(cmd);

in this sequence:

void loop () {
  sensorValue1 = analogRead(0);
  temp = 0;
    for (int j = 0; j < count; j++) {
     reading = sensorValue1;
     voltage = reading * 5.0;
     voltage /= 1024.0;
     temperatureCelsius = (voltage - 0.5) * 100;
     temp = temp + temperatureCelsius;
     sensorValue2 = analogRead(1);
  sensorValue2 = map(sensorValue2, sensorMin2, sensorMax2, 0, 255);
  sensorValue2 = constrain(sensorValue2, 0, 255);
  sensorValue3 = analogRead(2);
  sensorValue3 = map(sensorValue3, sensorMin3, sensorMax3, 0, 255);
  sensorValue3 = constrain(sensorValue3, 0, 255);
  return temp;
  return sensorValue2;
  return sensorValue3;
  if (mySerial.available()) {
    delay(2);
    cmd[0] = mySerial.read();
    if (cmd[0] == STX) {
      int i = 1;
      while (mySerial.available()) {
        delay(1);
        cmd[i] = mySerial.read();
        if (cmd[i] > 127 || i > 7) break;
        if ((cmd[i] == ETX) && (i == 2 || i == 7)) break;
        i++;
      }
      if (i == 2) getButtonState(cmd[1]);
      else if (i == 7) getJoystickState(cmd);
    }
  }
  sendBlueToothData();
}

I can't see your code - have you fixed all the other crazy named loop() functions?

Yep. I removed the 'loop' part and the compiler seems to be happy. I wonder if I'll get what I want...

Something still isn't how it should be, but I can't put my finger on it. The data fields from the app don't show the inputs from the sensors...

I've tried 2 methods and they both fail:
Method 1:

void sendBlueToothData() {
  static long previousMillis = 0;
  long currentMillis = millis();
  if (currentMillis - previousMillis > sendInterval) {
    previousMillis = currentMillis;
    mySerial.print((char)STX);
    mySerial.print(getButtonStatusString()); mySerial.print((char)0x1);
    mySerial.print(GetdataInt1()); mySerial.print((char)0x4);
    mySerial.print(GetdataFloat2()); mySerial.print((char)0x5);
    mySerial.print(displayStatus);
    mySerial.print((char)ETX);
  }
}

Method 2:

void sendBlueToothData() {
  static long previousMillis = 0;
  long currentMillis = millis();
  if (currentMillis - previousMillis > sendInterval) {
    previousMillis = currentMillis;
    mySerial.print((char)STX);
    mySerial.print(getButtonStatusString()); mySerial.print((char)0x1);
    mySerial.print(getButtonStatusString()); mySerial.print((char)0x1);
    mySerial.print(temp); mySerial.print((char)0x4);
    mySerial.print(sensorValue2); mySerial.print((char)0x5);
    mySerial.print(sensorValue3);
    mySerial.print((char)ETX);
  }
}

What needs to be changed so that the "data" fields in the app will display the inputs?

What needs to be changed so that the "data" fields in the app will display the inputs?

You need to consult the documentation for the app. It is NOT an Arduino app, so we can't help you with that.

PaulS:
You need to consult the documentation for the app. It is NOT an Arduino app, so we can't help you with that.

I've managed to solve that, but something else happened. I get no data from my sensors. I want to get inputs as long as the robot stays active, yet I get nothing. The code is:

#define VERSION
#include "SoftwareSerial.h"
#define STX 0x02
#define ETX 0x03
#define ledPin 13
#define SLOW 750
#define FAST 250
#define SPEEDLEFT 160
#define SPEEDRIGHT 128

float temp;
float reading1;
float voltage1;
float reading2;
float voltage2;
float humidity;
float reading3;
float voltage3;
float light;
float temperatureCelsius;
float count;
float power;
float current;

const int sensorPin1 = A0;
const int sensorPin2 = A1;
const int sensorPin3 = A2;

int sensorValue1;
int sensorValue2;
int sensorValue3;



SoftwareSerial mySerial (4, 2);

int MOTOR2_PIN1 = 3;
int MOTOR2_PIN2 = 5;
int MOTOR1_PIN1 = 6;
int MOTOR1_PIN2 = 9;

byte cmd[8] = {0, 0, 0, 0, 0, 0, 0, 0};
byte buttonStatus = 0;
long previousMillis = 0;
long sendInterval = SLOW;
String displayStatus = "Lol";

void setup() {
  pinMode (MOTOR1_PIN1, OUTPUT);
  pinMode (MOTOR1_PIN2, OUTPUT);
  pinMode (MOTOR2_PIN1, OUTPUT);
  pinMode (MOTOR2_PIN2, OUTPUT);
  pinMode (A0, INPUT);
  pinMode (A1, INPUT);
  pinMode (A2, INPUT);

  Serial.begin(9600);
  mySerial.begin(115200);
  mySerial.print("$");
  mySerial.print("$");
  mySerial.print("$");
  delay(100);
  mySerial.println("U,9600,N");
  mySerial.begin(9600);
  pinMode(ledPin, OUTPUT);
  Serial.println(VERSION);
  while (mySerial.available()) mySerial.read();
  }

void Temperature() {
  sensorValue1 = analogRead(0);
  reading1 = sensorValue1;
  voltage1 = reading1 * 5.0;
  voltage1 /= 1024.0;
  temperatureCelsius = (voltage1 - 0.5) * 100;
  temp = temperatureCelsius;
  return temp;
}

void Humidity () {
  sensorValue2 = analogRead(1);
  reading2 = sensorValue2;
  voltage2 = reading2 * 5.0;
  voltage2 /= 1024.0;
  light = voltage2 * 300;
  return light;
}

void Light() {
  sensorValue3 = analogRead(2);
  reading3 = sensorValue3;
  voltage3 = reading3 * 5.0;
  voltage3 /= 1024.0;
  humidity = voltage3 * 3000;
  return humidity;
}

void loop () {
  if (mySerial.available()) {
    delay(2);
    cmd[0] = mySerial.read();
    if (cmd[0] == STX) {
      int i = 1;
      while (mySerial.available()) {
        delay(1);
        cmd[i] = mySerial.read();
        if (cmd[i] > 127 || i > 7) break;
        if ((cmd[i] == ETX) && (i == 2 || i == 7)) break;
        i++;
      }
      if (i == 2) getButtonState(cmd[1]);
      else if (i == 7) getJoystickState(cmd);
    }
  }
  sendBlueToothData();
}

void sendBlueToothData() {
  static long previousMillis = 0;
  long currentMillis = millis();
  if (currentMillis - previousMillis > sendInterval) {
    previousMillis = currentMillis;
    mySerial.print((char)STX);
    mySerial.print(getButtonStatusString()); mySerial.print((char)0x1);
    mySerial.print(getButtonStatusString()); mySerial.print((char)0x1);
    mySerial.print(temp); mySerial.print((char)0x4);
    mySerial.print(light); mySerial.print((char)0x5);
    mySerial.print(humidity);
    mySerial.print((char)ETX);
  }
}

String getButtonStatusString() {
  String bStatus = "";
  for (int i = 0; i < 6; i++) {
    if (buttonStatus & (B100000 >> i)) bStatus += "1";
    else bStatus += "0";
  }
  return bStatus;
}
int GetdataInt1() {
  static int i = -30;
  i ++;
  if (i > 0) i = -30;
  return i;
}

float GetdataFloat2() {
  static float i = 50;
  i -= .5;
  if (i < -50) i = 50;
  return i;
}

void getJoystickState(byte data[8]) {
  int joyX = (data[1] - 48) * 100 + (data[2] - 48) * 10 + (data[3] - 48);
  int joyY = (data[4] - 48) * 100 + (data[5] - 48) * 10 + (data[6] - 48);
  joyX = joyX - 200;
  joyY = joyY - 200;
  if (joyX < -100 || joyX > 100 || joyY < -100 || joyY > 100) return;
  Serial.print("Joystick position: ");
  Serial.print(joyX);
  Serial.print(",");
  Serial.println(joyY);
  Serial.println(temp);
  Serial.println(humidity);
  Serial.println(light);

  if (joyY >= 90) {
    go(SPEEDLEFT, SPEEDRIGHT);
    Serial.println("inainte");
  }
  else if (joyX == 0 && joyY == 0) {
    go(0,0);
    Serial.println("stop");
  }
  if (joyY < - 90) {
    go (-SPEEDLEFT, -SPEEDRIGHT);
    Serial.println("inapoi");

  }
  else if (joyX == 0 && joyY == 0) {
    go(0, 0);
    Serial.println("stop");
  }
  if (joyX >= 90) {
    go (SPEEDLEFT, -SPEEDRIGHT);
    Serial.println("dreapta");

  }
  else if (joyX == 0 && joyY == 0) {
    go(0, 0);
    Serial.println("stop");
  }
  if (joyX <- 90){
    go(-SPEEDLEFT,SPEEDRIGHT);
    Serial.println("stanga"); 
  }
  else if (joyX == 0 && joyY == 0) {
    go(0,0);
    Serial.println("stop");
  }
}

void getButtonState(int bStatus) {
  switch (bStatus) {
    case 'A':
      buttonStatus |= B000001;
      Serial.println("\n** Button_1: ON **");
      displayStatus = "LED <ON>";
      Serial.println(displayStatus);
      digitalWrite(ledPin, HIGH);
      break;
    case 'B':
      buttonStatus &= B111110;
      Serial.println("n\** Button_1: OFF **");
      displayStatus = "LED <OFF>";
      Serial.println(displayStatus);
      digitalWrite(ledPin, LOW);
      break;
    case 'C':
      buttonStatus &= B000010;
      Serial.println("\b** Button_2: ON **");
      displayStatus = "Button2 <On>";
      Serial.println(displayStatus);
      break;
    case 'D':
      buttonStatus &= B111101;
      Serial.println("\n** Button_2: OFF **");
      displayStatus = "Button2 <OFF>";
      Serial.println(displayStatus);
      break;
    case 'E':
      buttonStatus |= B000100;
      Serial.println("\n** Button_3: ON **");
      displayStatus = "Motor #1 enabled";
      Serial.println(displayStatus);
      break;
    case 'F':
      buttonStatus &= B111011;
      Serial.println("\n** Button_3: OFF **");
      displayStatus = "Motor #1 stopped";
      Serial.println(displayStatus);
      break;
    case 'G':
      buttonStatus |= B001000;
      Serial.println("\n** Button_4: ON **");
      displayStatus = "Datafield update <FAST>";
      Serial.println(displayStatus);
      sendInterval = FAST;
      break;
    case 'H':
      buttonStatus &= B110111;
      Serial.println("\n** Button_4: OFF **");
      displayStatus = "Datafield update <SLOW>";
      Serial.println(displayStatus);
      sendInterval = SLOW;
      break;
    case 'I':
      buttonStatus |= B010000;
      Serial.println("\n** Button_5: ++ pushed ++ **");
      displayStatus = "Button5: <pushed>";
      break;
    case 'J':
      buttonStatus &= B10111;
      break;
    case 'K':
      buttonStatus |= B100000;
      Serial.println("\n** Button_6: ON **");
      displayStatus = "Button6 <ON>";
      break;
    case 'L':
      buttonStatus &= B011111;
      Serial.println("\n** Button_6: OFF **");
      displayStatus = "Button6 <OFF>";
      break;
  }
}

void go(int speedLeft, int speedRight) {
  if (speedLeft > 0) {
    analogWrite(MOTOR1_PIN1, speedLeft);
    analogWrite(MOTOR1_PIN2, 0);
  }
  else {
    analogWrite(MOTOR1_PIN1, 0);
    analogWrite(MOTOR1_PIN2, -speedLeft);
  }

  if (speedRight > 0) {
    analogWrite(MOTOR2_PIN1, speedRight);
    analogWrite(MOTOR2_PIN2, 0);
  } else {
    analogWrite(MOTOR2_PIN1, 0);
    analogWrite(MOTOR2_PIN2, speedRight);
  }
}

Is there something wrong with the code?

void Temperature() {
  sensorValue1 = analogRead(0);
  reading1 = sensorValue1;
  voltage1 = reading1 * 5.0;
  voltage1 /= 1024.0;
  temperatureCelsius = (voltage1 - 0.5) * 100;
  temp = temperatureCelsius;
  return temp;
}

You lied. You said this function doesn't return a value. But, then you tried, anyway. Why? Make up your mind.

SoftwareSerial mySerial (4, 2);

Can you post a picture of the mySerial object that you have attached to these pins? If you don't really have a mySerial connected to the pins, why did you give whatever you have attached to the pins such a meaningless name?

What ARE you getting from the mysterious device connected to the pins?

It should return a temperature. I've tried it anyway, because in a separate code, with the sensors connected directly to the Arduino board, it worked. Yet in this one, it did not. All I got was "0.0".
I'll explain from the top:
I have an Arduino Uno board. I've connected a driver and a bluetooth mate to it. Through the driver I power 4 servos and control them from an app on my phone using a bluetooth connection. In the original code, inside the "data" fields in my app are displayed the joystick's coordinates. I've connected my sensors to the driver, added to the original code the functions for each sensor and modified the display options so that, in theory, the inputs from the sensors will be displayed in the "data" fields instead of the joystick's coordinates. The problem was, it returned "0.0" in each field. When I've used separate stand-alone codes, with the sensors connected directly to the board, I got the inputs from the sensors.
I've altered the code again, today and it hits me with this error:
exit status 1
call of overloaded 'print(void (&)())' is ambiguous
at the line:

mySerial.print(light); mySerial.print((char)0x6);

In this sequence:

void sendBlueToothData() {
  static long previousMillis = 0;
  long currentMillis = millis();
  if (currentMillis - previousMillis > sendInterval) {
    previousMillis = currentMillis;
    mySerial.print((char)STX);
    mySerial.print(getButtonStatusString()); mySerial.print((char)0x1);
    mySerial.print(getButtonStatusString()); mySerial.print((char)0x1);
    mySerial.print(temp); mySerial.print((char)0x4);
    mySerial.print(humidity); mySerial.print((char)0x5);
    mySerial.print(light); mySerial.print((char)0x6);
    mySerial.print((char)ETX);
  }
}

If you want the full re-altered code, to better understand, I'll post it as well.

And this is the app I was talking about:

and a bluetooth mate to it.

So, it isn't a mySerial, after all. Can't you think of a better name? You didn't name your dog myDog did you?

at the line:

If you put ONE statement per line, like you are supposed to, you'd know which statement on that line was causing the problem.

How about you give me an actual answer instead of irony? I asked for some ideas not for pointless irony :neutral_face: . If you don't have anything useful for me, don't reply. Is that simple.

If you don't have anything useful for me, don't reply. Is that simple.

Well, I do, but you don't seem to want to listen, so I won't reply.

My apologies. It wasn't my intention to lash out on you, but I've had a hard day and your irony pushed me over the edge.
The problem seems to be here:

mySerial.print(light);

I've erased the lines:

 mySerial.print(light);
 mySerial.print((char)0x6);

and the error moved here:

mySerial.print(humidity);

If you want the full re-altered code, to better understand, I'll post it as well.

Well, yes. Along with the complete error message(s), too.

#define VERSION
#include "SoftwareSerial.h"
#define STX 0x02
#define ETX 0x03
#define ledPin 13
#define SLOW 750
#define FAST 250
#define SPEEDLEFT 160
#define SPEEDRIGHT 128

float temp;
int reading;
float voltage;
float temperatureCelsius;
float count;

const int sensorPin1 = A0;
const int sensorPin2 = A1;
const int sensorPin3 = A2;

int sensorValue1 = 0;
int sensorMin1 = 0;
int sensorMax1 = 1023;

int sensorValue2 = 0;
int sensorMin2 = 0;
int sensorMax2 = 1023;

int sensorValue3 = 0;
int sensorMin3 = 0;
int sensorMax3 = 1023;

int j;



SoftwareSerial mySerial (4, 2);

int MOTOR2_PIN1 = 3;
int MOTOR2_PIN2 = 5;
int MOTOR1_PIN1 = 6;
int MOTOR1_PIN2 = 9;

byte cmd[8] = {0, 0, 0, 0, 0, 0, 0, 0};
byte buttonStatus = 0;
long previousMillis = 0;
long sendInterval = SLOW;
String displayStatus = "Lol";

void setup() {
  pinMode (MOTOR1_PIN1, OUTPUT);
  pinMode (MOTOR1_PIN2, OUTPUT);
  pinMode (MOTOR2_PIN1, OUTPUT);
  pinMode (MOTOR2_PIN2, OUTPUT);
  pinMode (A0, INPUT);
  pinMode (A1, INPUT);
  pinMode (A2, INPUT);
  
  Serial.begin(9600);
  mySerial.begin(115200);
  mySerial.print("$");
  mySerial.print("$");
  mySerial.print("$");
  delay(100);
  mySerial.println("U,9600,N");
  mySerial.begin(9600);
  pinMode(ledPin, OUTPUT);
  Serial.println(VERSION);
  while (mySerial.available()) mySerial.read();
  while (millis() < 5000) {
    sensorValue1 = analogRead(0);
    if (sensorValue1 > sensorMax1)
    {sensorMax1 = sensorValue1;
    }
    if (sensorValue1 < sensorMin1)
    {sensorMin1 = sensorValue1;
    }
    sensorValue2 = analogRead(1);
    if (sensorValue2 > sensorMax2){
      sensorMax2 = sensorValue2;
    }
    if (sensorValue2 < sensorMin2){
      sensorMin2 = sensorValue2;
    }
    sensorValue3 = analogRead(2);
    if (sensorValue3 > sensorMax3){
      sensorMax3 = sensorValue3;
    }
    if (sensorValue3 < sensorMin3){
    sensorMin3 = sensorValue3;
  }
 }
}

void temperature(){
 sensorValue1 = analogRead(0);
 reading = sensorValue1;
 voltage = reading * 5.0;
 voltage /= 1024.0;
 temperatureCelsius = (voltage - 0.5) * 100;
 temp = temp + temperatureCelsius;
 return temp;
  }

void humidity (){
  float sensorValue3 = analogRead(2);
  float reading3 = sensorValue3;
  float voltage3 = reading3 * 5.0;
  voltage3 /= 1024.0;
  float humidity = ((voltage3)/3)*10;
  Serial.println(humidity); 
  return humidity;
}

void light(){
  float sensorValue2 = analogRead(1);
  float reading2 = sensorValue2;
  float voltage2 = reading2 * 5.0;
  voltage2 /= 1024.0;
  float light = (voltage2)*(voltage2);
  Serial.println(light); 
  return light;
}

void loop () {
  if (mySerial.available()) {
    delay(2);
    cmd[0] = mySerial.read();
    if (cmd[0] == STX) {
      int i = 1;
      while (mySerial.available()) {
        delay(1);
        cmd[i] = mySerial.read();
        if (cmd[i] > 127 || i > 7) break;
        if ((cmd[i] == ETX) && (i == 2 || i == 7)) break;
        i++;
      }
      if (i == 2) getButtonState(cmd[1]);
      else if (i == 7) getJoystickState(cmd);
    }
  }
  sendBlueToothData();
}

void sendBlueToothData() {
  static long previousMillis = 0;
  long currentMillis = millis();
  if (currentMillis - previousMillis > sendInterval) {
    previousMillis = currentMillis;
    mySerial.print((char)STX);
    mySerial.print(getButtonStatusString());
    mySerial.print((char)0x1);
    mySerial.print(getButtonStatusString());
    mySerial.print((char)0x1);
    mySerial.print(temp);
    mySerial.print((char)0x4);
    mySerial.print(humidity);
    mySerial.print((char)0x5);
    mySerial.print(light);
    mySerial.print((char)0x6);
    mySerial.print((char)ETX);
  }
}

String getButtonStatusString() {
  String bStatus = "";
  for (int i = 0; i < 6; i++) {
    if (buttonStatus & (B100000 >> i)) bStatus += "1";
    else bStatus += "0";
  }
  return bStatus;
}

int GetdataInt1() {
  static int i = -30;
  i ++;
  if (i > 0) i = -30;
  return i;
}

float GetdataFloat2() {
  static float i = 50;
  i -= .5;
  if (i < -50) i = 50;
  return i;
}

void getJoystickState(byte data[8]) {
  int joyX = (data[1] - 48) * 100 + (data[2] - 48) * 10 + (data[3] - 48);
  int joyY = (data[4] - 48) * 100 + (data[5] - 48) * 10 + (data[6] - 48);
  joyX = joyX - 200;
  joyY = joyY - 200;
  if (joyX < -100 || joyX > 100 || joyY < -100 || joyY > 100) return;
  Serial.println(temp);
  Serial.println(sensorValue2);
  Serial.println(sensorValue3);

  if (joyY >= 90) {
    go(SPEEDLEFT, SPEEDRIGHT);
    Serial.println("inainte");
    Serial.println(temp);
    Serial.println(sensorValue2);
    Serial.println(sensorValue3);
  }
  else if (joyX == 0 && joyY == 0) {
    go(0,0);
    Serial.println("stop");
    Serial.println(temp);
    Serial.println(sensorValue2);
    Serial.println(sensorValue3);
  }
  if (joyY < - 90) {
    go (-SPEEDLEFT, -SPEEDRIGHT);
    Serial.println("inapoi");
    Serial.println(temp);
    Serial.println(sensorValue2);
    Serial.println(sensorValue3);

  }
  else if (joyX == 0 && joyY == 0) {
    go(0, 0);
    Serial.println("stop");
    Serial.println(temp);
    Serial.println(sensorValue2);
    Serial.println(sensorValue3);
  }
  if (joyX >= 90) {
    go (SPEEDLEFT, -SPEEDRIGHT);
    Serial.println("dreapta");
    Serial.println(temp);
    Serial.println(sensorValue2);
    Serial.println(sensorValue3);
  }
  else if (joyX == 0 && joyY == 0) {
    go(0, 0);
    Serial.println("stop");
    Serial.println(temp);
    Serial.println(sensorValue2);
    Serial.println(sensorValue3);
  }
  if (joyX <- 90){
    go(-SPEEDLEFT,SPEEDRIGHT);
    Serial.println("stanga");
    Serial.println(temp);
    Serial.println(sensorValue2);
    Serial.println(sensorValue3); 
  }
  else if (joyX == 0 && joyY == 0) {
    go(0,0);
    Serial.println("stop");
    Serial.println(temp);
    Serial.println(sensorValue2);
    Serial.println(sensorValue3);
  }
}

void getButtonState(int bStatus) {
  switch (bStatus) {
    case 'A':
      buttonStatus |= B000001;
      Serial.println("\n** Button_1: ON **");
      displayStatus = "LED <ON>";
      Serial.println(displayStatus);
      digitalWrite(ledPin, HIGH);
      break;
    case 'B':
      buttonStatus &= B111110;
      Serial.println("n\** Button_1: OFF **");
      displayStatus = "LED <OFF>";
      Serial.println(displayStatus);
      digitalWrite(ledPin, LOW);
      break;
    case 'C':
      buttonStatus &= B000010;
      Serial.println("\b** Button_2: ON **");
      displayStatus = "Button2 <On>";
      Serial.println(displayStatus);
      break;
    case 'D':
      buttonStatus &= B111101;
      Serial.println("\n** Button_2: OFF **");
      displayStatus = "Button2 <OFF>";
      Serial.println(displayStatus);
      break;
    case 'E':
      buttonStatus |= B000100;
      Serial.println("\n** Button_3: ON **");
      displayStatus = "Motor #1 enabled";
      Serial.println(displayStatus);
      break;
    case 'F':
      buttonStatus &= B111011;
      Serial.println("\n** Button_3: OFF **");
      displayStatus = "Motor #1 stopped";
      Serial.println(displayStatus);
      break;
    case 'G':
      buttonStatus |= B001000;
      Serial.println("\n** Button_4: ON **");
      displayStatus = "Datafield update <FAST>";
      Serial.println(displayStatus);
      sendInterval = FAST;
      break;
    case 'H':
      buttonStatus &= B110111;
      Serial.println("\n** Button_4: OFF **");
      displayStatus = "Datafield update <SLOW>";
      Serial.println(displayStatus);
      sendInterval = SLOW;
      break;
    case 'I':
      buttonStatus |= B010000;
      Serial.println("\n** Button_5: ++ pushed ++ **");
      displayStatus = "Button5: <pushed>";
      break;
    case 'J':
      buttonStatus &= B10111;
      break;
    case 'K':
      buttonStatus |= B100000;
      Serial.println("\n** Button_6: ON **");
      displayStatus = "Button6 <ON>";
      break;
    case 'L':
      buttonStatus &= B011111;
      Serial.println("\n** Button_6: OFF **");
      displayStatus = "Button6 <OFF>";
      break;
  }
}

void go(int speedLeft, int speedRight) {
  if (speedLeft > 0) {
    analogWrite(MOTOR1_PIN1, speedLeft);
    analogWrite(MOTOR1_PIN2, 0);
  }
  else {
    analogWrite(MOTOR1_PIN1, 0);
    analogWrite(MOTOR1_PIN2, -speedLeft);
  }

  if (speedRight > 0) {
    analogWrite(MOTOR2_PIN1, speedRight);
    analogWrite(MOTOR2_PIN2, 0);
  } else {
    analogWrite(MOTOR2_PIN1, 0);
    analogWrite(MOTOR2_PIN2, speedRight);
  }
}

This is the complete error message: "exit status 1
call of overloaded 'print(void (&)())' is ambiguous"
which occurs at the line: mySerial.print(light);

void light(){
...
...
  float light =

Oopsie.

Why are your void functions still trying to return values? Don't you understand that the type of value in the return statement must match the return type of the function? Since the return type of the function is void, that's where you need to put the return statements.

Global variables, local variables, and functions all with the same name is NOT a good idea.

Global variables and functions with the same name are not allowed.