Pages: [1]   Go Down
Author Topic: control analog signal using xbee and arduino uno  (Read 287 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 88
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i need to read any analog sensor like variable resistance and show it in another board on lcd
i try to control digital signal and i success in this code

Receiver
_______
Code:
int LEDredPin =12;
int LEDgreenPin = 13;
void setup() {

  Serial.begin(9600);
 pinMode(LEDredPin, OUTPUT);
 pinMode(LEDgreenPin, OUTPUT);

}

void loop() {
  if (Serial.available()) { //If there is data in the Serial Line
    int dataByte = Serial.read();


          if(dataByte == 'H'){
              digitalWrite(LEDredPin, HIGH);
              digitalWrite(LEDgreenPin, LOW); 

            }

          if(dataByte == 'L') {
           
            digitalWrite(LEDgreenPin, HIGH);
            digitalWrite(LEDredPin, LOW);
                          }
                  }
            }
 

Transmitter
___________
Code:
const int sw1=2;
const int sw2=3;
void setup()
{
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  Serial.begin(9600);
}

void loop()
{
  if(digitalRead(sw1)==1)
{
  Serial.print('H');
}
  if(digitalRead(sw2)==1)
{
Serial.print('L');
}
}

but when i try to make analog signal i failed like this code

transmitter
__________

Code:
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.println(analogRead(A0));
}

Receiver
________
Code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,8,9,10,11,12);
void setup()
{
  Serial.begin(9600);
  lcd.begin(16, 2);
}

void loop() {
  if (Serial.available()) { //If there is data in the Serial Line
   int dataByte = Serial.read();
       lcd.setCursor(0, 1);
       lcd.print(dataByte);


         
            }
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26630
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A digital pin only needs a single character ('H' or 'L') to print its state, but an analogue read will return a value 0..1023, which your "Serial.println" will convert to an ASCII string "0\n".."1023\n", but you're only reading and interpreting a single character.
Code:
Serial.println(analogRead(A0));
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: