Sensors with Data Shield

Hello all.

I am attempting to make a sunlight logger for my garden to figure out what spots gets how much sun.

Build #1 - Used Arduino Uno with LCD keypad Shield in conjunction with BH1750 light sensor. Works fine until I plug on the Data Logger shield, at that point, no output to LCD, and light readings are pegged out. The data log works and records to Excel, but the reading is being interfered with. (I2C two different addresses verified.)

Since the Data Logger is also using A4 A5, I figured I could circumvent the issue:

Build #2 - Used Arduino Uno with a photoresistor, no LCD, works fine outputted to serial. Connect Data Logger, false or no readings again.

What could this Data Logger be doing that is interfering with both setups? been searching for days with no luck. Battery installed, SD card installed, pre-assembled.

Thank you.

#include <Wire.h>
#include <BH1750.h>
#include <SPI.h> 
#include <SD.h>
const char* filename = "Light.csv";

File file;
 
BH1750 lightMeter;
 
void setup(){
  lightMeter.begin();
  Serial.begin(9600);

  pinMode(10, OUTPUT); 
  
  if (!SD.begin(10)) {
    Serial.println("Error : Push the reset button");
    for (;;); 
  }
  
  file = SD.open(filename, FILE_WRITE);
 
  if (file.size() == 0) {
    file.println("Brightness value per seconds");
    file.flush();
  }
}
 
void loop() {
  uint16_t lux = lightMeter.readLightLevel(); 
  Serial.println(lux);
  file.println(lux);
  file.flush();
  
  delay(1000);
}

What pins are used for the LCD shield? What pins are used for the SD card (SPI)?

The LCD Keypad Shield appears to use A0
The Data Logger Shield uses A4 A5
The Light Sensor uses A4 A5

Thanks

Build #2 - Used Arduino Uno with a photoresistor, no LCD, works fine outputted to serial. Connect Data Logger, false or no readings again.

Post a schematic and the code that you tried, please.

Build #1 - Used Arduino Uno with LCD keypad Shield in conjunction with BH1750 light sensor. Works fine until I plug on the Data Logger shield, at that point, no output to LCD, and light readings are pegged out. The data log works and records to Excel, but the reading is being interfered with. (I2C two different addresses verified.)

From my research and assuming the LCD keypad shield, I have found that the SD card uses pins 13, 12, 11, 10 and the LCD pins 8, 9, 4, 5, 6, 7 and pin 10 is backlight control. So pin 10 us used on both, but that should not prevent the LCD from working. You can change the SD card chip select pin.

if (!SD.begin(2)) {  // SD CS to pin 2

What does the I2C scanner return with the LCD keypad shield and the data logger shield all connected?

// I2C scanner by Nick Gammon.  Thanks Nick.

#include <Wire.h>

void setup() {
  Serial.begin (115200); //*****  make sure serial monitor baud matches *****

  // Leonardo: wait for serial port to connect
  while (!Serial) 
    {
    }

  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Thank you groundFungus.

When I have the Uno, Data shield, LCD keypad shield and Light sensor connected and run the scanner, I get

⸮5⸮5

This is the schematic I was using for the Photosensor test (not really wanting to use it though)

and the testing code....

#include <SPI.h>
#include <SD.h>

/* Sensor test sketch
  for more information see http://www.ladyada.net/make/logshield/lighttemp.html
  */

#define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!

int photocellPin = 0;     // the cell and 10K pulldown are connected to a0
int photocellReading;     // the analog reading from the analog resistor divider

//TMP36 Pin Variables
int tempPin = 1;        //the analog pin the TMP36's Vout (sense) pin is connected to
                        //the resolution is 10 mV / degree centigrade with a
                        //500 mV offset to allow for negative temperatures
int tempReading;        // the analog reading from the sensor
    
void setup(void) {
  // We'll send debugging information via the Serial monitor
  Serial.begin(9600);   

  // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);
}


void loop(void) {
  photocellReading = analogRead(photocellPin);  
  
  Serial.print("Light reading = ");
  Serial.print(photocellReading);     // the raw analog reading
  
  // We'll have a few threshholds, qualitatively determined
  if (photocellReading < 10) {
    Serial.println(" - Dark");
  } else if (photocellReading < 200) {
    Serial.println(" - Dim");
  } else if (photocellReading < 500) {
    Serial.println(" - Light");
  } else if (photocellReading < 800) {
    Serial.println(" - Bright");
  } else {
    Serial.println(" - Very bright");
  }
  
  tempReading = analogRead(tempPin);  
  
  Serial.print("Temp reading = ");
  Serial.print(tempReading);     // the raw analog reading
  
  // converting that reading to voltage, which is based off the reference voltage
  float voltage = tempReading * aref_voltage / 1024; 
 
  // print out the voltage
  Serial.print(" - ");
  Serial.print(voltage); Serial.println(" volts");
 
  // now print out the temperature
  float temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
                                               //to degrees ((volatge - 500mV) times 100)
  Serial.print(temperatureC); Serial.println(" degrees C");
 
  // now convert to Fahrenheight
  float temperatureF = (temperatureC * 9 / 5) + 32;
  Serial.print(temperatureF); Serial.println(" degrees F");
 
  delay(1000);
}

This is odd. Using the code from my original post, the backlight gives a slight blink in between loops.
However, changing the SD pin to 2 stops the LCD from even lighting. When the both use 10, the LCD at least lights up.
By looking at the physical circuit, from what I can tell, the digital pins used are:
LCD 4-8
SD 11, 13
Thanks

If it helps, here is what I do have working:

Uno + LCD + light sensor getting great readings with this code:

#include <Wire.h>
#include <BH1750.h>
#include <LiquidCrystal.h>
 
 
BH1750 lightMeter;
const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
 
void setup(){
  lightMeter.begin();
    // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Lux:");
}
 
 
void loop() {
  uint16_t lux = lightMeter.readLightLevel();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lx");

  lcd.setCursor(0, 1);
  lcd.print(lux);
  delay(1000);
}

When I have the Uno, Data shield, LCD keypad shield and Light sensor connected and run the scanner, I get
Code:
⸮5⸮5

Are you sure that the baud rate is correct in serial monitor when you ran the I2C scanner? It should be set to 115200.

So, with the data logger shield in place can you upload code to the Uno? Like the blink example?

This is the schematic I was using for the Photosensor test (not really wanting to use it though)

The switches on the LCD keypad shield are connected to pin A0 so if you followed that diagram, you have the LDR wired to A0, too. That will not work.

Try to realize that I can't see what you have, how it is wired or the code that you are using. Without good accurate information I can not help.

Thanks for your patience. Let me reorganize this please.
Let's take the LCD out of the equation for now and I will just use the serial monitor to view values.

With just Uno and Light sensor:

Light Sensor BH1750 Pinout:

VCC to Arduino 5v or 3.3V
Gnd to Gnd
SCL to Arduino A5
SDA to Arduino A4
ADDR to Gnd

#include <BH1750.h>
 
BH1750 lightMeter;

void setup(){
  lightMeter.begin();
  Serial.begin(9600);
}
 
void loop() {
  uint16_t lux = lightMeter.readLightLevel();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lx");
  delay(1000);
}

That code produces accurate readings to the serial monitor.


When I add the Data Logger on, I get only max value readings around 65,000. Data logging works correctly, only the values read are in error using the following code:

#include <Wire.h>
#include <BH1750.h>
#include <SPI.h> 
#include <SD.h>
const char* filename = "Light.csv";

File file;
 
BH1750 lightMeter;
 
void setup(){
  lightMeter.begin();
  Serial.begin(9600);

  pinMode(10, OUTPUT); 
  
  if (!SD.begin(10)) {
    Serial.println("Error : Push the reset button");
    for (;;); 
  }
  
  file = SD.open(filename, FILE_WRITE);
 
  if (file.size() == 0) {
    file.println("Brightness value per seconds");
    file.flush();
  }
}
 
void loop() {
  uint16_t lux = lightMeter.readLightLevel(); 
  Serial.println(lux);
  file.println(lux);
  file.flush();
  
  delay(1000);
}

With: Uno + Data Logger Shield + Sensor
Found address: 35 (0x23)
Found address: 104 (0x68)
Done.
Found 2 device(s).

I am stumped. Without the LCD shield there should be no pin conflicts.

What happens if you run the code without the data logger stuff with the data logger shield installed?
I mean, install this code.

#include <BH1750.h>
 
BH1750 lightMeter;

void setup(){
  lightMeter.begin();
  Serial.begin(9600);
}
 
void loop() {
  uint16_t lux = lightMeter.readLightLevel();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lx");
  delay(1000);
}

and plug in the data logger shield. Do you get good light data in serial monitor? I am trying to see if it is hardware or software causing the problem.

Thank you

So with the shield on and that code I am getting a 65,535 result only.

Here are some more details:

I removed the shield and then rebooted the Arduino, no serial response. I had to reupload code. Then, works correctly again. Add the shield, doesn't work even with reset, reupload same code again, it works, but with the pegged out value.

Im so confused, haha.

The I2C scanner reports the right I2C addresses for the DS1307 and light sensor with the data logging shield installed, but the light sensor will not work with the data logging shield installed, is that right?

Can you try a DS1307 (RTC) library example and see if the DS1307 will work.

I am kind of grasping at straws here cause I can't see any reason that the light sensor will not work.

The data logging shield is on an Uno R3, right?

Thank you,

Your first sentence is correct. They don't seem to play well together on I2C...that's really all they have in common, no?

So I did try an example code to produce a timestamp and that did indeed work correctly. RTC seems fine.

I don't see Uno R3 anywhere on the shield. here is the link to the data shield:

Thanks!

Uno R3 is the Arduino board that the data logger shield fits into.

Sorry, I am using the sparkfun equivalent of the Uno, "Redboard"

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.