Coding problems regarding designing of my lux meter

Hi Guys please see attached document as I’ve detailed everything. Please assist as I need to complete this project urgently.

Designing a lux meter.pdf (120 KB)

A couple of things.

First, didn’t you notice the “Programming Questions” section?
This section is only for problems with “Installation and Troubleshooting” of Arduino itself, not your code.
That’s clearly written under the section title in the main forums index if you’d taken the time to look:-

Installation & Troubleshooting
For problems with Arduino itself, NOT your project

Also, your problem should be fully described accurately in your post where it’s easily accessible and readable, not in a pdf.

Next, please don’t place your code in a pdf and attach it. Post your code here, between code tags, so it can be easily read as well as selected and pasted into an IDE for verification etc.
Do the same with your error messages, (in a separate code block).

Code tags are generated using the </> button in the post and “Reply” window, or manually typed like this:-

[code]Place your code here[/code]
It will appear in a block like this

Make it easy for people to help you, not hard. You’ve made it quite a chore. Please edit your post and fix the problems. You’ll have a much better chance of getting help. :wink:

I found the problem, and after a little library downloading I got the code to compile fine for me. After you fix your opening post as suggested, I'll show you where you went wrong. Fair enough? ;)

Edit: You're kidding. I just now realised that you've been cross-posting this topic all over the place. Didn't you bother to read the forum rules. If I'd known this earlier, I wouldn't have bothered putting in my time trying to help you.

Desigining a LUX meter Designing a Lux meter using a LDR

Why the @#$%& didn't you just start a single thread and stick with it?

Hi Oldsteve, I know I have made several post mistakes and I’d like to apologise for the inconvenience. Point taken and mistakes won’t be done in the new future. :frowning:

*  LDR Lux Meter
 *  
 *  This sketch calculates the lux from a voltage reading
 *  
 *  The hardware connected to Analog Pin 0 should be a voltage divider circuit between an LDR and a 
 *  resistor (nominally 5kohm).  The resistor should be connected to ground and the LDR should be
 *  connected to 5V.  The point in between should be connected to Analog Pin 0.
 *  1) Calculate voltage based on reading
 *  2) Calculate resistance of LDR based on voltage
 *  3) Calculate the lux that must be falling on LDR based on the resistance
 *  
 *  The lux reading is then output to an Adafruit LCD shield.

#include <Wire.h>
//  I2C and LCD Shield libraries
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

// The shield uses the I2C SCL and SDA pins. On classic Arduinos
// this is Analog 4 and 5 so you can't use those for analogRead() anymore
// However, you can connect other I2C sensors to the I2C bus and share
// the I2C bus.
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();

// These #defines make it easy to set the backlight color
#define RED 0x1
#define YELLOW 0x3
#define GREEN 0x2
#define TEAL 0x6
#define BLUE 0x4
#define VIOLET 0x5
#define WHITE 0x7

// These constants, define values needed for the LDR readings and ADC
#define LDR_PIN                   0
#define MAX_ADC_READING           1023
#define ADC_REF_VOLTAGE           5.0
#define REF_RESISTANCE            5030  // measure this for best results
#define LUX_CALC_SCALAR           12518931
#define LUX_CALC_EXPONENT         -1.405
/*
    Configure the LCD to be 16 char by 2 rows.
    Background is set to white.
    LCD says hello and please wait.

void configureLCD(void)
{
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  lcd.setBacklight(WHITE); 

  // Print a message to the LCD. We track how long it takes since
  // this library has been optimized a bit and we're proud of it :)
  //int time = millis();
  lcd.print(F("Initializing!"));
  delay(555);
  
  lcd.setCursor(0,1);
  lcd.print(F("Please wait..."));
  
  //time = millis() - time;
  //Serial.print("Took "); Serial.print(time); Serial.println(" ms");

  delay(1000);
  lcd.clear();
}


/*
    Arduino setup function (automatically called at startup)

void setup(void) 
{
  Serial.begin(9600);
  Serial.println(F("Light Sensor Test")); Serial.println("");
  
  /* Setup the LCD to be ready to display */
  configureLCD();
  
  /* We're ready to go! */
  Serial.println(F("Sensor, LCD and SD Card are Configured."));
}


void loop(void) 
{  
  
  int   ldrRawData;
  float resistorVoltage, ldrVoltage;
  float ldrResistance;
  float ldrLux;
  
  // Perform the analog to digital conversion  
  ldrRawData = analogRead(LDR_PIN);
  
  // RESISTOR VOLTAGE_CONVERSION
  // Convert the raw digital data back to the voltage that was measured on the analog pin
  resistorVoltage = (float)ldrRawData / MAX_ADC_READING * ADC_REF_VOLTAGE;

  // voltage across the LDR is the 5V supply minus the 5k resistor voltage
  ldrVoltage = ADC_REF_VOLTAGE - resistorVoltage;
  
  // LDR_RESISTANCE_CONVERSION
  // resistance that the LDR would have for that voltage  
  ldrResistance = ldrVoltage/resistorVoltage * REF_RESISTANCE;
  
  // LDR_LUX
  // Change the code below to the proper conversion from ldrResistance to
  // ldrLux
  ldrLux = LUX_CALC_SCALAR * pow(ldrResistance, LUX_CALC_EXPONENT);
 
  // print out the results
  Serial.print("LDR Raw Data   : "); Serial.println(ldrRawData);
  Serial.print("LDR Voltage    : "); Serial.print(ldrVoltage); Serial.println(" volts");
  Serial.print("LDR Resistance : "); Serial.print(ldrResistance); Serial.println(" Ohms");
  Serial.print("LDR Illuminance: "); Serial.print(ldrLux); Serial.println(" lux");

  // Print out the LDR Illuminance to the LCD
  lcd.setCursor(0,0); // set cursor to column 0, line 1
  lcd.print("LDR Lux Meter");
    
  lcd.setCursor(0,1); // set cursor to column 0, line 2
  lcd.print(ldrLux);
  lcd.setCursor(7, 1); // set cursor to column 4, line 1
  lcd.print(" lux");
  
  delay(250);
}

[error message]Arduino: 1.6.8 (Windows 7), Board: “Arduino/Genuino Uno”

libraries\Adafruit-RGB-LCD-Shield-Library-master\utility\Adafruit_MCP23017.cpp.o: In function `Adafruit_MCP23017::begin(unsigned char)’:

C:\Program Files (x86)\Arduino\libraries\Adafruit-RGB-LCD-Shield-Library-master\utility/Adafruit_MCP23017.cpp:52: multiple definition of `Adafruit_MCP23017::begin(unsigned char)’

libraries\Adafruit-MCP23017-Arduino-Library-master\Adafruit_MCP23017.cpp.o:C:\Program Files (x86)\Arduino\libraries\Adafruit-MCP23017-Arduino-Library-master/Adafruit_MCP23017.cpp:113: first defined here

libraries\Adafruit-RGB-LCD-Shield-Library-master\utility\Adafruit_MCP23017.cpp.o: In function `wiresend’:

C:\Program Files (x86)\Arduino\libraries\Adafruit-RGB-LCD-Shield-Library-master\utility/Adafruit_MCP23017.cpp:36: multiple definition of `Adafruit_MCP23017::begin()’

libraries\Adafruit-MCP23017-Arduino-Library-master\Adafruit_MCP23017.cpp.o:C:\Program Files (x86)\Arduino\libraries\Adafruit-MCP23017-Arduino-Library-master/Adafruit_MCP23017.cpp:57: first defined here

libraries\Adafruit-RGB-LCD-Shield-Library-master\utility\Adafruit_MCP23017.cpp.o: In function `wiresend’:

C:\Program Files (x86)\Arduino\libraries\Adafruit-RGB-LCD-Shield-Library-master\utility/Adafruit_MCP23017.cpp:36: multiple definition of `Adafruit_MCP23017::writeGPIOAB(unsigned int)’

libraries\Adafruit-MCP23017-Arduino-Library-master\Adafruit_MCP23017.cpp.o:C:\Program Files (x86)\Arduino\libraries\Adafruit-MCP23017-Arduino-Library-master/Adafruit_MCP23017.cpp:57: first defined here

libraries\Adafruit-RGB-LCD-Shield-Library-master\utility\Adafruit_MCP23017.cpp.o: In function `wiresend’:

C:\Program Files (x86)\Arduino\libraries\Adafruit-RGB-LCD-Shield-Library-master\utility/Adafruit_MCP23017.cpp:36: multiple definition of `Adafruit_MCP23017::pullUp(unsigned char, unsigned char)’

libraries\Adafruit-MCP23017-Arduino-Library-master\Adafruit_MCP23017.cpp.o:C:\Program Files (x86)\Arduino\libraries\Adafruit-MCP23017-Arduino-Library-master/Adafruit_MCP23017.cpp:57: first defined here

libraries\Adafruit-RGB-LCD-Shield-Library-master\utility\Adafruit_MCP23017.cpp.o: In function `wiresend’:

C:\Program Files (x86)\Arduino\libraries\Adafruit-RGB-LCD-Shield-Library-master\utility/Adafruit_MCP23017.cpp:36: multiple definition of `Adafruit_MCP23017::digitalRead(unsigned char)’

libraries\Adafruit-MCP23017-Arduino-Library-master\Adafruit_MCP23017.cpp.o:C:\Program Files (x86)\Arduino\libraries\Adafruit-MCP23017-Arduino-Library-master/Adafruit_MCP23017.cpp:57: first defined here

libraries\Adafruit-RGB-LCD-Shield-Library-master\utility\Adafruit_MCP23017.cpp.o: In function `wiresend’:

C:\Program Files (x86)\Arduino\libraries\Adafruit-RGB-LCD-Shield-Library-master\utility/Adafruit_MCP23017.cpp:36: multiple definition of `Adafruit_MCP23017::readGPIOAB()’

libraries\Adafruit-MCP23017-Arduino-Library-master\Adafruit_MCP23017.cpp.o:C:\Program Files (x86)\Arduino\libraries\Adafruit-MCP23017-Arduino-Library-master/Adafruit_MCP23017.cpp:57: first defined here

libraries\Adafruit-RGB-LCD-Shield-Library-master\utility\Adafruit_MCP23017.cpp.o: In function `wiresend’:

C:\Program Files (x86)\Arduino\libraries\Adafruit-RGB-LCD-Shield-Library-master\utility/Adafruit_MCP23017.cpp:36: multiple definition of `Adafruit_MCP23017::pinMode(unsigned char, unsigned char)’

libraries\Adafruit-MCP23017-Arduino-Library-master\Adafruit_MCP23017.cpp.o:C:\Program Files (x86)\Arduino\libraries\Adafruit-MCP23017-Arduino-Library-master/Adafruit_MCP23017.cpp:57: first defined here

libraries\Adafruit-RGB-LCD-Shield-Library-master\utility\Adafruit_MCP23017.cpp.o: In function `wiresend’:

C:\Program Files (x86)\Arduino\libraries\Adafruit-RGB-LCD-Shield-Library-master\utility/Adafruit_MCP23017.cpp:36: multiple definition of `Adafruit_MCP23017::digitalWrite(unsigned char, unsigned char)’

libraries\Adafruit-MCP23017-Arduino-Library-master\Adafruit_MCP23017.cpp.o:C:\Program Files (x86)\Arduino\libraries\Adafruit-MCP23017-Arduino-Library-master/Adafruit_MCP23017.cpp:57: first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.
[/error message]

Thanks for fixing it. :slight_smile:
(Even though I have your answer, it was still important for others that read this thread in the future.)


Now, to business.

First up, I assume that you downloaded and installed the “Adafruit_RGBLCDShield” library.
If not, you’ll need to do that.
Of course you have it already - the error messages tell us that. :blush:

Then, remove the “Adafruit-MCP23017” library from your ‘libraries’ folder. If you look in the “Adafruit_RGBLCDShield” library, under “utility”, you’ll find there’s already a copy there. (You can’t have two copies of the same library.)

Next, remove this line from the top of the *.ino file:-
#include <Adafruit_MCP23017.h>(The “Adafruit_RGBLCDShield” library automatically includes “Adafruit_MCP23017.h”, so it doesn’t need to be explicitly included in the sketch, and because it’s no longer installed as a separate library, this line will otherwise throw an error.)

Now the sketch should compile without errors. I compiled both for the UNO and the Mega2560 without errors or warnings. (Arduino IDE V1.6.5)

Let me know if you have further trouble.

Edit: Just one other thing. The full name including “master” isn’t needed on libraries. It’s generally a good idea to remove the “master”, since it serves no purpose.

Thank you OldSteve, much appreciated... it's working. :) :)

Nethan0542: Thank you OldSteve, much appreciated... it's working. :) :)

Excellent. Glad to hear it. :) Somehow I became unsubscribed from this thread, so missed your reply until now.