Coding quiz mate

Made by Nik Kim

Making circuit version of Time Timer

Created: November 22nd, 2023

0

Outcome



0
0

Product

In this project, I want to combine what I have learned until now. Therefore, I mixed the components of motors, lights, and switches. This product is great mate when you are preparing for time-limited tasks such as quizzes or tests. The Solenoid ticker will run for 30 seconds and will repeat this process until the desired input time.

0

Process

1. Wiring up Timer. The timer in this circuit is a Servo.

2-a. Wiring up Solenoid. The first intention was to make a solenoid sound to indicate a few seconds left until the time was over. However, the solenoid didn't work properly.

2-b. As an alternative, I used Neopixel to gradually glow up when there are less than 1/3 times left compared to the user's input time.

3. Make a switch that starts the whole process. After the user types in the desired time through the console and toggles the switch, the solenoid Time Timer will begin. 

0
// NeoPixel
#include <neopixel.h>

// Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D6
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

// Servo
Servo servo;
int servoPin = A3;

// Switch 
int switchPin = D3;

// User input
int minutes = 0;

void setup() {
    // Setup particle serial monitor
    Serial.begin(9600);
    
    // Setup neopixel
    strip.begin();
    strip.show();
    
    // Setup servo
    servo.attach(servoPin);
    servo.write(0);
    delay(500);
    servo.write(180);
    delay(500);
    
    // Set up switch
    pinMode(switchPin, INPUT_PULLUP);
    
    // Set up particle function
    Particle.function("Set your timer in minutes:", setTime);

}

void loop() {
    // Read switch mode
    int switchState = digitalRead(switchPin);
    int count = 0;
    
    // this loop represents 30 sec timer
    // this loop repeats the number of times of the user input
    if(switchState == LOW) {
        for (int i = 0; i < minutes * 2; i++ ) {
            for (int a = 0; a <= 180; a = a + 6) {
                count++;
                servo.write(a);
                delay(1000);
                // if remaining time is lower that 1/3 of the user input
                // slowly neoPixel glows up into gentle color
                Serial.println(count);
                if (count >= 2 * 60 * minutes / 3) {
                    for (int i = 0; i < strip.numPixels(); i++) {
                        int color = map(count, 0, 60 * minutes, 0, 10);
                        strip.setPixelColor(i, 0, color, 0);
                    }
                    strip.show();                    
                }
            }
        }
        switchState = digitalRead(switchPin);
        // turn off neopixels
        for (int i = 0; i < strip.numPixels(); i++) {
            strip.setPixelColor(i, 0, 0, 0);
        }
        strip.show();  
        count = 0;
    }
}

int setTime(String cmd) {
    minutes = cmd.toInt();
    
    return -1;
}
Click to Expand
x
Share this Project

Courses

48-675 Designing for the Internet of Things 24

· 11 members

A hands-on introductory course exploring the Internet of Things and connected product experiences.


About

Making circuit version of Time Timer