Go Down

Topic: control analog signal using xbee and arduino uno (Read 111 times) previous topic - next topic

MostafaHamdy

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: [Select]
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: [Select]
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: [Select]
void setup()
{
  Serial.begin(9600);
}

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


Receiver
________
Code: [Select]
#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);


         
            }
}

Go Up