Hello there well im trying to send a analog value from my arduino to another and display that value to a lcd.
so what i have is:
Transmitter:
temp sensor on analog pin to arduino duemilanove > xbee shield > V1 xbee
Receiver:
V1 xbee > xbee shield > arduino mega > Serial 20x4LCD
I have tryd so many times i cant get this to work
has anyone got some code for doin this and would like to send more than 1 analog value aswell
Tansmitter
int sensorPin = 0;
int sensorValue = 0;
void setup() {
 Serial.begin(9600); Â
 Serial.println(" ");Â
 pinMode(sensorPin, INPUT);
}
void loop() {
Â
 int sensorValue = analogRead(sensorPin);
 Serial.print(sensorValue);
 delay(1000);
 }
}
Reciver
void setup()
{
 lcd.init();          Â
 lcd.backlight();
 lcd.begin(20, 4);
 lcd.setCursor(6, 1);
 lcd.print("WELCOME");
 delay(3000);
 lcd.clear();
 Serial.begin(9600);Â
}
void loop()
   Â
 if (Serial.available()){
  char getData = Serial.read();Â
  lcd.setCursor(0, 1);
  lcd.print("DEC");
 }
}
thats what i tryd but not the best i NEED HELP with with
Yes thanks i tryd this but just no luck the lcd just comes up with 0 or 2 or 3
this has just got me ???????????????????/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,21);
byte getData;
void setup()
{
 Serial.begin(9600);Â
 lcd.init();          Â
 lcd.backlight();
 lcd.begin(20, 4);
 lcd.setCursor(6, 1);
 lcd.print("WELCOME");
 delay(3000);
 lcd.clear();
Â
}
void loop(){
lcd.setCursor(0, 1);
lcd.print("xbee");
   Â
 if (Serial.available()) {
  getData = Serial.read();
  Serial.println(getData);
  lcd.setCursor(5, 2);
  lcd.print(getData); // getData prints the analog value sent from the transmitter
 }
}
This is correct as you print a string value (p.e. "768") to the XBee. On the receiving side you get it character for character and print each for itself. So you'll see first a "7", shortly (very shortly) after a "6" and then an "8". The 8 is what you probably will recognise as the other digits were changing to fast.
You have to define start and end of message bytes. Let's say '<' is start of message, '>' is end of message. This way you can clear the display when you receive a '<', print all characters you receive to the display until you receive a '>'.
ok so how do i put that into the code sorry im new to the xbee stuff
i found this code somewhere but its still not what i want it only displays 0 to 255 and not 0 to 1023
// RECIEVER
byte incomingByte, sensor1, sensor2;
void setup() {
// start serial port at 19200 bps
Serial.begin(9600);
Serial.println("Ready");
// led pins
pinMode (5, OUTPUT);
pinMode (6, OUTPUT);
delay(1000);
}
void loop() {
if (Serial.available()) { Â // are there any bytes available on the serial port ???
// assign bytes to the var ‘incomingByte’
incomingByte = Serial.read();
Serial.println(int(incomingByte));
// from now on is pretty clear I guess  :)
if ((int(incomingByte) == 254)) {
sensor1 = Serial.read();
Serial.print("Sensor 1 = ");
Serial.print(int(sensor1));
}
if ((int(incomingByte) == 255)) {
sensor2 = Serial.read();
Serial.print("Sensor 2 = ");
Serial.print(int(sensor2));
}
}
analogWrite (5, sensor1);
analogWrite (6, sensor2);
}
If timing is not critical, the easiest and best debuggable is to use just plain ASCII with start and stop bytes:
Sender:
int value = 345;
Serial.write('<');
Serial.print(value);
Serial.write('>');
Receiver:
#define IDLEÂ 0
#define RECEIVING 1
int remoteval = 0;
byte status = IDLE;
void loop() {
 if (Serial.available()) {
  int c = Serial.read();
  if (status == RECEIVING && c >= '0' && c <= '9') {
   remoteval = remoteval * 10 + (c - '0');
  } else if (status == RECEIVING && c == '>') {
   status = IDLE;
   // remote value received completely, do something with it
  } else if (c == '<') {
   status = RECEIVING;
  }
 }
}
}
I Still dont get it i have been trying this for hours now still no luck have you got code in more detail.
thanks for the help anyway.
How can i send more than 1 analog value like 3 and can i send digital values?
more code would be more help
i have tryd lots of code i found on the net but nothing is what i want i would linke the reciver to display 0, 1023
Have you tried to insert my code into your sketch?
The code does not send an analog or digital value but an integer. Both analog and digital values can be represented by integers. Sending more than one value is simply a loop around that.
If you have a special problem you wanna solve with the Arduino platform that nobody else did exactly the same way before you cannot expect to find code on the internet that exactly matches your needs. You also cannot expect this forum to be your programmer for free doing your whole job. We try to help if your stuck and have to get problem solved. But we expect you to do your work, let us give you hints to go on.
My code transmits an integer value in ASCII with start character '<' and end character '>'. You can extend the same functionality with other start/end characters or with delimiter characters in between the values. All that with only small changes to my code.
yes i understant that. and have tryed puting your bit of code into mine still i didnt get much going.
but i will keep trying. when i have the time ill try some more i just finished designing my new PCB for the arduino lastnite.
Im new to all this xbee stuff but im getting there.
My Job is desing PCBs so going on to the programing side of things is a big step but im enjoying it.