Samantha Song
Published © GPL3+

A Blooming Time

A mechanical flower that will open when touched, you can tell the day from the petals, as well as the date, time, temperature and humidity.

BeginnerWork in progress15 hours2,243
A Blooming Time

Things used in this project

Hardware components

Seeed Studio Grove Beginner Kit
×1
Grove - I2C Touch Sensor(MPR121)
Seeed Studio Grove - I2C Touch Sensor(MPR121)
×1
Grove - RTC
Seeed Studio Grove - RTC
×1
Seeed Studio Grove - OLED Display 0.96"
×1
Grove - Temperature, Humidity, Pressure and Gas Sensor (BME680)
Seeed Studio Grove - Temperature, Humidity, Pressure and Gas Sensor (BME680)
×1
Grove- Servo
×1
Brass Wire (~1.5mm)
×1
Brass Tubing (internal diameter ~5mm)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Laser cutter (generic)
Laser cutter (generic)
3D Printer (generic)
3D Printer (generic)

Story

Read more

Code

A Blooming time

Arduino
#include <Wire.h>
#include <U8x8lib.h>
#include <U8g2lib.h>
#include "DS1307.h"
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11

U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(U8X8_PIN_NONE);
DHT dht(DHTPIN, DHTTYPE);
DS1307 clock;

const int TouchPin=3;

void setup() {
  Serial.begin(9600);
  
  //OLED
  Wire.begin();
  u8x8.begin();
  u8x8.clear();
  
  //clock
  clock.begin();
  clock.fillByYMD(2019,11,9);//Jan 19,2013
  clock.fillByHMS(16,38,00);//15:28 30"
  clock.fillDayOfWeek(SAT);//Saturday
  clock.setTime();//write time to the RTC chip
  
  //temphum
  Serial.println(("DHTxx test!"));
  dht.begin();

  //lights, touch
  pinMode(TouchPin, INPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop() {
    int sensorValue = digitalRead(TouchPin);
    Serial.println("loop");
    dayPetal();
    if(sensorValue==1)
    {
        digitalWrite(13,HIGH);
        digitalWrite(12,HIGH);
        digitalWrite(11,HIGH);
        digitalWrite(10,HIGH);
        digitalWrite(9,HIGH);
        digitalWrite(8,HIGH);
        digitalWrite(7,HIGH);
        printScreen();
        delay(1000);
        //u8x8.clearDisplay();
        Serial.println("clear");
    }
    else
    {
        digitalWrite(13,LOW);
        digitalWrite(12,LOW);
        digitalWrite(11,LOW);
        digitalWrite(10,LOW);
        digitalWrite(9,LOW);
        digitalWrite(8,LOW);
        digitalWrite(7,LOW);
    }
}

void dayPetal(){
   switch (clock.dayOfWeek)
    {
        case MON:
        digitalWrite(13,HIGH);
        break;
        case TUE:
        digitalWrite(12,HIGH);
        break;
        case WED:
        digitalWrite(11,HIGH);
        break;
        case THU:
        digitalWrite(10,HIGH);
        break;
        case FRI:
        digitalWrite(9,HIGH);
        break;
        case SAT:
        digitalWrite(8,HIGH);
        break;
        case SUN:
        digitalWrite(7,HIGH);
        break;
    }
}

void printScreen(){
  u8x8.clearDisplay();
  u8x8.setFont(u8x8_font_chroma48medium8_r);
  u8x8.drawString(1,1,"Hey QT pie!");
  delay(2000);
  u8x8.clearDisplay();
  printTime();
  tempHum();
  Serial.println("Print temp");
  delay(2000);
  u8x8.clearDisplay();
}

void printTime(){
  u8x8.setCursor(0,1);
  switch (clock.dayOfWeek)// Friendly printout the weekday
    {
        case MON:
        u8x8.print("MONDAY");
        break;
        case TUE:
        u8x8.print("TUESDAY");
        break;
        case WED:
        u8x8.print("WEDNESDAY");
        break;
        case THU:
        u8x8.print("THURSDAY");
        break;
        case FRI:
        u8x8.print("FRIDAY");
        break;
        case SAT:
        u8x8.print("SATURDAY");
        break;
        case SUN:
        u8x8.print("SUNDAY");
        break;
    }
  u8x8.drawString(0,2,"Time: ");
  u8x8.setCursor(6,2);
  u8x8.print(clock.hour, DEC);
  u8x8.print(":");
  u8x8.print(clock.minute, DEC);
  u8x8.print(":");
  u8x8.print(clock.second, DEC);
  u8x8.print("  ");

  u8x8.drawString(0,3, "Date: ");
  u8x8.setCursor(6,3);
  u8x8.print(clock.dayOfMonth, DEC);
  u8x8.print("/");
  u8x8.print(clock.month, DEC);
  u8x8.print("/");
  u8x8.print(clock.year+2000, DEC); 
}

void tempHum() 
{
  Serial.print("in ");
    float temp_hum_val[2] = {0};
    
    dht.readTempAndHumidity(temp_hum_val);
   
    u8x8.drawString(0,5,"Temp: ");
    u8x8.setCursor(6,5);
    u8x8.print(temp_hum_val[1]);
    
    u8x8.drawString(0,6, "Humidity: ");
    u8x8.setCursor(10,6);
    u8x8.print(temp_hum_val[0]);
    Serial.println("out");
}

Credits

Samantha Song

Samantha Song

1 project • 1 follower

Comments