Error message trying to send a value through bluetooth (ardunio)

Thread Starter

SoFarFromBread

Joined Jul 23, 2017
12
I'm having problems reading the analogue pin and sending the value through Bluetooth to my LCD.
can someone tell me whats wrong please, thank you very much.

This is the code for the master device
Code:
int val;
#define button 3
void setup() {
  Serial.begin(38400);
  pinMode(button , INPUT);

}

void loop() {
  val = digitalRead(button);
  if (val == HIGH)
  {
    int sensor = analogRead(A0);
    float voltage0 = sensor * (5.0/1023.0);
    Serial.write(voltage0);
    delay(500);
  }
  delay(50);
}
and then i get this error message

Code:
Arduino: 1.8.4 (Windows 7), Board: "Arduino/Genuino Uno"

C:\Sams Folder\Code_for_master_device__full_\Code_for_master_device__full_.ino: In function 'void loop()':

Code_for_master_device__full_:16: error: call of overloaded 'write(float&)' is ambiguous

     Serial.write(voltage0);

                          ^

C:\Sams Folder\Code_for_master_device__full_\Code_for_master_device__full_.ino:16:26: note: candidates are:

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232:0,

                 from sketch\Code_for_master_device__full_.ino.cpp:1:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:129:20: note: virtual size_t HardwareSerial::write(uint8_t)

     virtual size_t write(uint8_t);

                    ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:130:19: note: size_t HardwareSerial::write(long unsigned int)

     inline size_t write(unsigned long n) { return write((uint8_t)n); }

                   ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:131:19: note: size_t HardwareSerial::write(long int)

     inline size_t write(long n) { return write((uint8_t)n); }

                   ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:132:19: note: size_t HardwareSerial::write(unsigned int)

     inline size_t write(unsigned int n) { return write((uint8_t)n); }

                   ^

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:133:19: note: size_t HardwareSerial::write(int)

     inline size_t write(int n) { return write((uint8_t)n); }

                   ^

exit status 1
call of overloaded 'write(float&)' is ambiguous

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
This is the code for the slave device

Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int val;
int voltage0;
int Intvol;
void setup() {
  Serial.begin(38400);
  lcd.begin(16, 2);
}

void loop() {
  if(Serial.available() > 0)
{
val = Serial.read();
  if (val==voltage0)
{
  
  lcd.setCursor (0,0);
  lcd.print(val);
  delay(200);
}
}

}
 

be80be

Joined Jul 5, 2008
2,072
What board you using never mind I see

Try this Can't use float
Code:
int val;
#define button 3
void setup() {
  Serial.begin(38400);
  pinMode(button , INPUT);
}
void loop() {
  val = digitalRead(button);
  if (val == HIGH)
  {
    int sensor = analogRead(A0);
    int voltage0 = sensor * (5.0/1023.0);
    Serial.write(voltage0);
    delay(500);
  }
  delay(50);
}
This works you need to use Serial.println Not write
Code:
int val;
#define button 3
void setup() {
  Serial.begin(38400);
  pinMode(button , INPUT);
}
void loop() {
    val = digitalRead(button);
    if (val == HIGH)
  {

    int sensor = analogRead(A0);
    int voltage0 = sensor * (5.0/1023.0);
    Serial.println(voltage0);
    delay(500);
  }
}
 
Last edited:

Thread Starter

SoFarFromBread

Joined Jul 23, 2017
12
What board you using never mind I see

Try this Can't use float
Code:
int val;
#define button 3
void setup() {
  Serial.begin(38400);
  pinMode(button , INPUT);
}
void loop() {
  val = digitalRead(button);
  if (val == HIGH)
  {
    int sensor = analogRead(A0);
    int voltage0 = sensor * (5.0/1023.0);
    Serial.write(voltage0);
    delay(500);
  }
  delay(50);
}
thank you, it now compiles fine however it still doesn't display on the LCD, if i set a constant in the serial.print it works fine however as soon as i try and use a variable it doesn't seem to work.
 

be80be

Joined Jul 5, 2008
2,072
Did you try the second code this one
Code:
int val;
#define button 3
void setup() {
  Serial.begin(38400);
  pinMode(button , INPUT);
}
void loop() {
    val = digitalRead(button);
    if (val == HIGH)
  {
    int sensor = analogRead(A0);
    int voltage0 = sensor * (5.0/1023.0);
    Serial.println(voltage0);
    delay(500);
  }
}
 

Thread Starter

SoFarFromBread

Joined Jul 23, 2017
12
Did you try the second code this one
Code:
int val;
#define button 3
void setup() {
  Serial.begin(38400);
  pinMode(button , INPUT);
}
void loop() {
    val = digitalRead(button);
    if (val == HIGH)
  {
    int sensor = analogRead(A0);
    int voltage0 = sensor * (5.0/1023.0);
    Serial.println(voltage0);
    delay(500);
  }
}
i just tried that but that doesn't seem to work either...
 

be80be

Joined Jul 5, 2008
2,072
Well I no that part works I looking at the LCD code now

try this
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int val;
int voltage0;
int Intvol;
void setup() {
  Serial.begin(38400);
  lcd.begin(16, 2);
}
void loop() {
  if(Serial.available() > 0)
{

  lcd.setCursor (0,0);
  lcd.print(val);
  delay(200);

}
}
 

be80be

Joined Jul 5, 2008
2,072
Try this these I think the second if you had was the show stopper

Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int val;
int voltage0;
int Intvol;
void setup() {
  Serial.begin(38400);
  lcd.begin(16, 2);
}
void loop() {
  if(Serial.available() > 0)
{

  lcd.setCursor (0,0);
  lcd.print(val);
  delay(200);

}
}
Code:
int val;
#define button 3
void setup() {
  Serial.begin(38400);
  pinMode(button , INPUT);
}
void loop() {
    val = digitalRead(button);
    if (val == HIGH)
  {
    int sensor = analogRead(A0);
    int voltage0 = sensor * (5.0/1023.0);
    Serial.println(voltage0);
    delay(500);
  }
}
 

Thread Starter

SoFarFromBread

Joined Jul 23, 2017
12
Well I no that part works I looking at the LCD code now

try this
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int val;
int voltage0;
int Intvol;
void setup() {
  Serial.begin(38400);
that printed 0 to the lcd however it should be printing 3v
  lcd.begin(16, 2);
}
void loop() {
  if(Serial.available() > 0)
{

  lcd.setCursor (0,0);
  lcd.print(val);
  delay(200);

}
}
 

be80be

Joined Jul 5, 2008
2,072
Try this it should work
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int val;
int voltage0;

void setup() {
  Serial.begin(38400);
  lcd.begin(16, 2);
}
void loop() {
  if(Serial.available() > 0)
{
  val=Serial.read();
  lcd.setCursor (0,0);
  lcd.print(val);
  delay(200);

}
}
 

be80be

Joined Jul 5, 2008
2,072
First off was it showing up now on the LCD you have to send a byte at time so you break it up into bytes


  • Serial.println(1.23456, 4) gives "1.2346"
 
Last edited:
Top