Setup: 2XArduino Uno 2x XBees S1 2x Sparkfun xbee shields.

My first arduino reads in values from a photoresistor and sends the values to the second arduino. I know for sure the arduino is sending values because when i plugged the second xbee directly into the computer and opened the serial monitor correct values showed up in the serial monitor. But the problem is when i attach the second Xbee onto its sparkfun shield and arduino i get repetitive wrong values .

Can someone please tell me what i am doing wrong? I am doing this to make sure i get the right values before i beef up the project.

Sender sketch

#include <LiquidCrystal.h> 
#include <SoftwareSerial.h>
#include <XBee.h>
int photocellPin = A0;     // the cell and 10K pulldown are connected to a0

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

int photocellReading;     // the analog reading from the analog resistor divider
 SoftwareSerial XBee(2,3);
void setup(void) {

  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Wireless LightDimmer");  

 void loop(void) {
  photocellReading = analogRead(photocellPin);  
  lcd.setCursor(0, 1);
  lcd.print("Photocell= ");
  lcd.setCursor(11, 2); 
  lcd.setCursor(20, 0);
  lcd.print("Measured in lux"); 

  delay (500);
  lcd.setCursor(20, 3);
  lcd.print(" ");
 // Serial.print("Analog reading = ");
 // Serial.print(photocellReading);   
   photocellReading = 1023 - photocellReading;
 unsigned int LEDbrightness = map(photocellReading, 0, 1023, 0, 255);
   Serial.println( LEDbrightness);


recieving sketch

#include <SoftwareSerial.h>
#include <XBee.h>

SoftwareSerial XBee(2,3);

void setup() {
 // Begin Serial communication
void loop(){
 while ( Serial.available() > 0) {
 unsigned int num =  Serial.read();

enter image description here enter image description here

  • Check for Vref u r getting full (1024) ADC value. – Md . Sojib Ahmed Nov 27 '17 at 5:12

The xbee pins can only read up about 1.2V which it will show 256 bit. You should check how much the photoresistor is giving out because it might gives something that is more than the xbee pin can handle.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.