Close

Reading a real sensor

A project log for dayTime

sync your microcontroller to the diurnal cycle using sensor data

simon-merrettSimon Merrett 04/25/2021 at 17:450 Comments

While converting to simulated LDR/ADC readings and playing round with different algorithms to find the daily period and current phase from the simulated readings is OK, it would be good to check that a real sensor and ADC would yield the same data. We need to validate the conversion from W/m2 -> ADC counts we conducted in the log Algo's First Dataset

It has taken me several logs to set the scene, but we are finally about to log some of our own data! Almost any microcontroller has an ADC and could be used to measure a voltage divider between a fixed resistor and an LDR. However, I wanted one that would be able to store the data for me reliably and allow almost continual logging for a year. I could have used an SD card connected over SPI to record data, and perhaps I should have done that  - you certainly could if you want to record your own data. 

However, I had an Adafruit Itsybitsy M4 on hand and it has a nice QSPI flash memory chip onboard that plays very nicely with the Adafruit spiflash library. It is very much overkill for this application but it would be powered from a mains supply and the convenience made it worth it. I used it to make a small sketch that saves LDR readings to flash every 10 minutes, after waiting an initial period to see if you want to download data from it. If you plug it in to a PC and start a serial terminal within 20 seconds, it pauses readings and you can use a few single letter key commands to get it to print out all the readings in your serial monitor. You can also key a command to delete readings after you have copied and pasted them out of your serial terminal. If you choose to leave the readings on the flash chip, the next time the board powers up and does not detect a serial connection (ie it is expected to start logging again) it will record a "new session" line in the file record to hopefully help you keep track and not double count readings at the next download event. That said, my readings are not quite aligned/trimmed for any recording overlap so please forgive that - I do intend to clean them up. 

Here is the simple LDR-10k resistor divider:

And how it looks on it's sunny windowsill:

As you can see - it has all the dusty hallmarks of having been sat there for a year!

The overall setup is coarse but I will show you anyway. You do not need much to get going with dataloggin'!


The Itsybitsy has seen better days!

I have uploaded the sketch for this datalogger in the files area for this project. Please use as-is or as a basis for your own simple light logger. 

We will look at the readings this logger took over a 12 month period in a future log.

Discussions