MisterBotBreak
Published

How to Make the SmartBox ( Weather, Time & Lux Station )

This project will show you how to make the SmartBox.

BeginnerFull instructions provided1 hour699
How to Make the SmartBox ( Weather, Time & Lux Station )

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
RTC clock module
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Photo resistor
Photo resistor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Oled screen 128per64
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
( Optional )
3D Printer (generic)
3D Printer (generic)
( Optional )

Story

Read more

Custom parts and enclosures

Main Body SmartBox

Face SmartBox

Code

First Code to Transfer

Arduino
This code is the code with your actual timetable to set the clock
#include "U8glib.h"
#include <Wire.h>
#include <ds3231.h>
#include "DHT.h"
#define DHTPIN 2     
#define DHTTYPE DHT22   
DHT dht(DHTPIN, DHTTYPE);
struct ts t; 
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);  

void setup() { 
    dht.begin();
  Wire.begin();
  DS3231_init(DS3231_INTCN);
 t.hour=22; 
  t.min=29;
  t.sec=0;
  t.mday=12;
  t.mon=12;
  t.year=2019;
  DS3231_set(t); 

 if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(100);    
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(1);        
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(3);         
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
} 
  
  

void loop(){
  DS3231_get(&t);

u8g.firstPage();
  do {  
    draw(); 
  } while( u8g.nextPage() );
  delay(2000); 
  u8g.firstPage();
  do {  
    draw2();      
  } while( u8g.nextPage() ); 
 delay(2000);     
 u8g.firstPage();
  do {  
    draw3();      
  } while( u8g.nextPage() ); 
 delay(2000); 
   u8g.firstPage();
  do { 
  draw4();      
  } while( u8g.nextPage() ); 
 delay(2000);                  
}
 void draw(){
int a = t.hour;
int b = t.min;
  u8g.setFont(u8g_font_gdr25r);
char bb[2];
sprintf (bb, "%d", b);
u8g.drawStr(65, 40, bb);
char aa[2];
sprintf (aa, "%d", a);
u8g.drawStr(20, 40, aa);
u8g.drawStr(56,40 ,":");
 }
 void draw2(){
int c = t.mday;
int d = t.mon; 
u8g.setFont(u8g_font_gdr25r);
char cc[2];
sprintf (cc, "%d", c);
u8g.drawStr(22, 40, cc);
char dd[2];
sprintf (dd, "%d", d);
u8g.drawStr(70, 40, dd);
u8g.drawStr(56, 40, "/");
 }
 void draw3(){
int h = dht.readHumidity();
int t = dht.readTemperature();
u8g.setFont(u8g_font_gdr25r);
char hh[2];
sprintf (hh, "%d", h);
u8g.drawStr(35, 61, hh);
char tt[2];
sprintf (tt, "%d", t);
u8g.drawStr(28, 30, tt);
u8g.drawStr(0, 30, "t:");
u8g.drawStr(0, 61, "h:");
u8g.drawStr(64, 30, "°C");
u8g.drawStr(71, 61, "%");
 }
  void draw4(){
u8g.setFont(u8g_font_gdr25r);
int val = analogRead(A0);
char vv[3];
sprintf (vv, "%d", val);
u8g.drawStr(72, 40, vv);
u8g.drawStr(0, 40, "Lux:");
 }

 

Second Code to Transfer

Arduino
This code is the previous code without the portion of the clock's setting. Transfer the first code, and THEN the second code to synchronize properly your SmartBox.
#include "U8glib.h"
#include <Wire.h>
#include <ds3231.h>
#include "DHT.h"
#define DHTPIN 2     
#define DHTTYPE DHT22   
DHT dht(DHTPIN, DHTTYPE);
struct ts t; 
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);  

void setup() { 
    dht.begin();
  Wire.begin();
  DS3231_init(DS3231_INTCN);
/*
t.hour=22; 
  t.min=29;
  t.sec=0;
  t.mday=12;
  t.mon=12;
  t.year=2019;
  
  DS3231_set(t); 
*/
 if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(100);    
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(1);        
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(3);         
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
} 
  
void loop(){
  DS3231_get(&t);

u8g.firstPage();
  do {  
    draw(); 
  } while( u8g.nextPage() );
  delay(2000); 
  u8g.firstPage();
  do {  
    draw2();      
  } while( u8g.nextPage() ); 
 delay(2000);     
 u8g.firstPage();
  do {  
    draw3();      
  } while( u8g.nextPage() ); 
 delay(2000); 
   u8g.firstPage();
  do { 
  draw4();      
  } while( u8g.nextPage() ); 
 delay(2000);                  
}
 void draw(){
int a = t.hour;
int b = t.min;
  u8g.setFont(u8g_font_gdr25r);
char bb[2];
sprintf (bb, "%d", b);
u8g.drawStr(65, 40, bb);
char aa[2];
sprintf (aa, "%d", a);
u8g.drawStr(20, 40, aa);
u8g.drawStr(56,40 ,":");
 }
 void draw2(){
int c = t.mday;
int d = t.mon; 
u8g.setFont(u8g_font_gdr25r);
char cc[2];
sprintf (cc, "%d", c);
u8g.drawStr(22, 40, cc);
char dd[2];
sprintf (dd, "%d", d);
u8g.drawStr(70, 40, dd);
u8g.drawStr(56, 40, "/");
 }
 void draw3(){
int h = dht.readHumidity();
int t = dht.readTemperature();
u8g.setFont(u8g_font_gdr25r);
char hh[2];
sprintf (hh, "%d", h);
u8g.drawStr(35, 61, hh);
char tt[2];
sprintf (tt, "%d", t);
u8g.drawStr(28, 30, tt);
u8g.drawStr(0, 30, "t:");
u8g.drawStr(0, 61, "h:");
u8g.drawStr(64, 30, "°C");
u8g.drawStr(71, 61, "%");
 }
  void draw4(){
u8g.setFont(u8g_font_gdr25r);
int val = analogRead(A0);
char vv[3];
sprintf (vv, "%d", val);
u8g.drawStr(72, 40, vv);
u8g.drawStr(0, 40, "Lux:");
 }

 

Credits

MisterBotBreak
48 projects • 152 followers
I love electronics and cats :D !
Contact

Comments

Please log in or sign up to comment.