Akshay - Skills Dev II

Made by Akshay Soma · UNLISTED (SHOWN IN POOLS)

Created: November 10th, 2021



    • The project I created is a simple reading time tracker for someone who wants to gauge how long it is taking them to get through each of their Designing for IoT readings each week with an automated reading light built in
    • You can see it in action below, but you will have to imagine it plugged into a bit more of a substantial light and button combination. If it were to be something I designed/prototyped more thoroughly, I would imagine it as a connected "easy button" and lamp
Skills Dev 2: Reading time tracker & Automatic reading light
Akshay - https://youtu.be/_ckd92-Xl58
// This #include statement was automatically added by the Particle IDE.
#include <clickButton.h>
#include <time.h>

// Define a pin that we'll place the photo cell on
// Remember to add a 10K Ohm pull-down resistor too.
int photoCellPin = A0;

// Create a variable to hold the light reading
int photoCellReading = 0;

// Define a pin we'll place an LED on
int ledPin = D2;
// Define a pin for the button
int buttonPin = D3;

// Create a variable to store the LED brightness.
int ledBrightness = 0;

//tracking time
long int startTime;

long int endTime;

long int timeDiff;

int timerRunning = 0;

void setup() {
 Particle.variable("Brightness", ledBrightness);
   // Set up the LED for output
  pinMode(ledPin, OUTPUT);
  analogWrite(ledPin, 0);

  // Create a cloud variable of type integer
  // called 'light' mapped to photoCellReading
  pinMode(buttonPin, INPUT_PULLUP);
//  Serial.begin(9600);

void loop(){
    // Use analogRead to read the photo cell reading
  // This gives us a value from 0 to 4095
  photoCellReading = analogRead(photoCellPin);

  // Map this value into the PWM range (0-255)
  // and store as the led brightness
  ledBrightness = map(photoCellReading, 3971, 4025, 255, 0);

  // fade the LED to the desired brightness
  analogWrite(ledPin, ledBrightness);

if(timerRunning == 0 && digitalRead(buttonPin) == LOW){
    //digitalWriteFast(ledPin, HIGH);
    startTime = Time.now();
    timerRunning = 1;
else if(timerRunning == 1 && digitalRead(buttonPin) == LOW){
//digitalWriteFast(ledPin, LOW);
    endTime = Time.now();
    timeDiff = endTime - startTime;
    Particle.publish("Total Reading time", Time.format(timeDiff,"%X"));
    timerRunning = 0;

Click to Expand


In designing this little device, my first problem I encountered was the mess of wiring I had after learning to use a photovoltaic sensor. It drove me crazy enough that I rewired the whole thing to a similar layout, but one that made more sense to me. The next was in writing the code to control the output of the timer. My program creates an event on the Particle Dashboard when the button is pressed a second time to inform the user of the total time spent reading for that session/chapter. I kept getting some weird readings and had used the light to trouble shoot what was going on. I noticed the light would only stay lit sometimes and eventually realized I needed a short delay to allow the user to remove their finger, so as to not re-trigger the button press on accident. I made use of some time functions to help track the difference in time between button presses and output readings as strings.

From there my next challenge was finding an appropriate range for the photovoltaic sensor. It is rather finnicky and I used the output of the Brightness variable I created to understand what readings I was getting from the sensor. I used a pen cap to create a darker environment for the sensor, but still came to find that it was sensing a large amount of light anyways. Once I mapped the sensor and brightness values appropriately, I reset the brightness variable to what it should actually be tracking. Nonetheless, I came to find the sensor still on the fritz when I moved the board to a new location to record. Setting it up on the laptop, close to where it was before, allowed me to fix the issue.



Overall, I learned how to modify my code to error check and wire my board a little better. In addition, I learned how to use a photovoltaic sensor and buttons. Something I would have done differently is adjust the mapping for the photovoltaic cell. I would have done some more testing to understand the amount of ambient light was in my room in the dark, as opposed to under a pen cap, and created a map based on that. In addition, I may have considered using another button instead of a momentary switch, however I did not feel a switch fit the mold of my concept. If I had a button that would have remained triggered instead, I would have used that.

Share this Project

This project is only listed in this pool. Be considerate and think twice before sharing.