how do i calculate resistance from LDR

this is my code together with xively

/*
##Xively WiFi Sensor Tutorial##
This sketch is designed to take sensors (from photocell) and upload the values to Xively
at consistant intervals. At the same time it gets a setable value from Xively to adjust the brigthness
of an LED. This sketch is reusable and can be adapted for use with many different sensors.
Derived from Xively Ardino Sensor Client by Sam Mulube.
 
By Calum Barnes 3-4-2013
BSD 3-Clause License - [http://opensource.org/licenses/BSD-3-Clause]
Copyright (c) 2013 Calum Barnes
*/
#include <SPI.h>
#include <WiFi.h>
#include <HttpClient.h>
#include <Xively.h>
   float RLDR;                   // Resistance calculation of potential divider with LDR
   float Vout;                   // voltage ouput from potential divider to Anolg input
int resistance;
   float Lux;
   int Luminosity;
char ssid[] = "WTCAP3"; //  your network SSID (name) 
char pass[] = "admin54321";    // your network password (use for WPA, or use as key for WEP)
           // your network key Index number (needed only for WEP)
 
int status = WL_IDLE_STATUS;
 
// Your Xively key to let you upload data
char xivelyKey[] = "UwNj0U4DVlT4iLRXsuRUrJO9bZEVtyWlk3berKSCGYA43qjD";
//your xively feed ID
#define xivelyFeed 1727888101
//datastreams
char sensorID[] = "LDR"; // CHANNEL NAME
char ledID[] = "LED";
 

// Analog pin which we're monitoring (0 and 1 are used by the Ethernet shield)
#define sensorPin A2
//led connected pin
#define ledPin 9
 
// Define the strings for our datastream IDs
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorID, strlen(sensorID), DATASTREAM_FLOAT),
  XivelyDatastream(ledID, strlen(ledID), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xivelyFeed, datastreams, 2 /* number of datastreams */);
 
WiFiClient client;
XivelyClient xivelyclient(client);
 
void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
 
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
 
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm \n");
}
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  //pin setup
  pinMode(sensorPin, INPUT);
  pinMode(ledPin, OUTPUT);
 
  Serial.println("Starting single datastream upload to Xively...");
  Serial.println();
 
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  } 
  Serial.println("Connected to wifi");
  printWifiStatus();
}
 
void loop() {
  //adjust LED level. set from Xively
  int getReturn = xivelyclient.get(feed, xivelyKey);    //get data from xively
  if(getReturn > 0){
    Serial.println("LED Datastream");
    Serial.println(feed[1]);
  }else Serial.println("HTTP Error");
  
  //write value to LED - change brightness
  int level = feed[1].getFloat();
  if(level < 0){
    level = 0;
  }else if(level > 255){
    level = 255;
  }
  //actually write the value
  digitalWrite(ledPin, level);
 
///////////////////////////////////////////////////////
  //read sensor values
 
  
   int sensorValue = analogRead(sensorPin);
     // Equation to calculate Resistance of LDR, [R-LDR =(R1 (Vin - Vout))/ Vout]
   // R1 = 10,000 Ohms , Vin = 5.0 Vdc.
                                         
   Vout = (sensorValue * 0.0048828125);           // Vout = Output voltage from potential Divider. [Vout = ADC * (Vin / 1024)] 
   resistance = 10.0 * ((5/Vout)-1);
   datastreams[0].setFloat(resistance);
  
  //print the sensor valye
  Serial.print("Read sensor value ");
  Serial.println(datastreams[0].getFloat());
 
  //send value to xively
  Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);
  //return message
  Serial.print("xivelyclient.put returned ");
  Serial.println(ret);
  Serial.println("");
  
  
  //delay between calls
  delay(150);
}

how do i calculate resistance and lux

Hi,

Can you explain exactly what you want to do.
Consider me ignorant of things IT,(some people would not disagree)
What is xively?
What do you want to do with the LDR?
What hardware do you have.
And;

What is your electronics, programming, arduino, hardware experience?

We are here to help, but need information to give you any advice.

Tom....... :slight_smile:

TomGeorge:
Hi,

Can you explain exactly what you want to do.
Consider me ignorant of things IT,(some people would not disagree)
What is xively?
What do you want to do with the LDR?
What hardware do you have.
And;

What is your electronics, programming, arduino, hardware experience?

We are here to help, but need information to give you any advice.

Tom....... :slight_smile:

i use xively to store my data. i want to calculate the light intensity(lux) and the resistance of the ldr. And a total noob

You can't measure the resistance of the LDR directly. You need to make a voltage divider and measure the voltage at the junction and use Ohm's law to calculate the resistance of the LDR.

Arduino 5v --------Fixed Resistor ----------X-----------LDR----------- Arduino GND

Measure the voltage at point X

...R

LDR's are not really accurate enough to tell you how many lux.

Have you ever hooked up an LDR to an ohm meter, and then played with the lights in the room, and tried to get consistent numbers?

Something like the BH1750 (available in cheap modules on ebay) is a much better choice if you want quantitative measurement of light level. LDR's are only good for very course measurements.