Error message trying to send a value through bluetooth.

im 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

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

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

#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);
}
  
}

}

This

Serial.write(voltage0);

should be

Serial.print(voltage0);

...R

Thank you very much it now complies but still doesn't show up on my LCD. Can you see any other problems maybe in the slave side of things?

Hi,
Welcome to the forum.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks... Tom... :slight_smile:

Can you see any other problems maybe in the slave side of things?

Yes. It is related to the master problem.

You seem to think that you can send a float as one byte. A float is 4 bytes.

Changing the method sending the data, to send a string, instead, means that you need to read MORE THAN ONE BYTE.

But, you really have fundamental problems with your communication. Suppose you read the voltage 4 times, and you get 3.50, 3.64, 3.51, and 3.63. What you are sending to the serial port is "3.503.643.513.63".

How the heck do you expect the receiver to make sense of that crap?

http://forum.arduino.cc/index.php?topic=396450.0

There you go

SLAVE.png

Master

MASTERr.png

Hi,
No problems, if its your first try, well done..
Just need some layout editing, but looks good.
SLAVE.

Tom.. :slight_smile:

Hi,
You have shrunk the master a bit too much.. lol

Tom.. :slight_smile:

Hi,
As promised, edited layout, you will get this better with practice and experience.
The CAD I use is called ExpressPCB.
If you google ExpressPCB download
You will be able to get full version for free, with no extra offers or unwanted luggage that some of these "free" applications want yu to pick up.

Tom.. :slight_smile:

TomGeorge:
The CAD I use is called ExpressPCB.

Do you know if that is a Windows only product as I can't see anything about that on their website?

...R

Robin2:
Do you know if that is a Windows only product as I can't see anything about that on their website?

...R

About what?
Can't Linux run a windows emulator, it seems to be able to do everything else? lol
What I like about ExpressPCB is you click the icon, and in one or two seconds its fully loaded.
Tom.. :slight_smile:

TomGeorge:
Can't Linux run a windows emulator,

Wash your mouth out with red soap for saying something like that :slight_smile:

...R