当前位置:   article > 正文

【WaterRemind】用Arduino与SSD1306做一款提醒喝水的杯垫(何同学同款)_何同学智能杯垫

何同学智能杯垫

Introduction

看到何同学最新的视频里面出现的办公室标配的提醒喝水的杯垫,感觉很好做,因此就做一个送给女朋友来提醒他按时喝水,项目主要使用了Arduino Nano作为控制器,SSD1306驱动的0.91寸单色OLED作为显示器,屏幕可以显示进度条,以及定制自己想显示的字母或者bmp图片。具体演示效果如下所示。

【WaterRemind】一款何同学视频中出现的提醒喝水杯垫

Method

硬件

硬件很简单,具体清单如下

  • Arduino nano v3.0
  • 0.91寸Oled SSD1306
  • 有源蜂鸣器
  • 红外反射传感器
  • 锂电池充放板
  • 504060锂电池
  • 杜邦线若干
    成本大概在50块钱左右

代码




#include <Arduino.h>
#include <U8g2lib.h>
#include <string.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
#ifdef U8X8_HAVE_HW_I2C
#include <Wire.h>
#endif


U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);   // Adafruit Feather ESP8266/32u4 Boards + FeatherWing OLED
DS1302 rtc(2, 3, 4); // RST, DAT, CLK
Time t1;
Time t2;
int t3;
char tt;
int bee = 13;
int redPin = A0;
int val;

#define bmp1_x 80
#define bmp1_y 16
 
static const unsigned char bmp1[] U8X8_PROGMEM = {
0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x20,0x04,0xE0,0x07,0x00,0x00,0x20,0xF0,
0x01,0x94,0x20,0x04,0x60,0x04,0x02,0x00,0x20,0x60,0xC0,0xD5,0x20,0x1E,0xE7,0x05,0x02,0x24,0x20,0xD0,0x40,0x7C,0xB0,0x14,0x2D,0x07,0x02,0x24,0xA4,0xCC,0xC1,0x7C,
0xB0,0x15,0xED,0xE3,0x1A,0x24,0xA3,0x47,0xC3,0x09,0x30,0x3F,0x97,0x83,0x0E,0x24,0x21,0x01,0x40,0xFC,0x38,0x1C,0xF8,0xC4,0x0E,0x24,0x28,0x04,0x74,0xD5,0x21,0x34,
0xD8,0x48,0x72,0x24,0x38,0xA4,0xED,0x57,0x21,0x66,0xD0,0x29,0xC3,0x64,0x30,0x24,0x19,0xD6,0x21,0x82,0x70,0x0F,0x03,0x44,0x00,0x20,0x00,0x44,0x00,0x02,0xF0,0x05,
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,0x02,0x67,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

};

#define bmp2_x 78
#define bmp2_y 16
static const unsigned char bmp2[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0C,0x00,0x00,0x00,0x00,0x00,0xF0,0x01,0x80,0x00,0x08,0xFE,0x00,0x01,0x00,0x00,0x80,0x00,0x80,0x00,0x08,0x18,0x30,0x01,0x00,0x00,0x80,0x00,0x00,
0x01,0x3E,0x18,0x60,0x31,0x00,0xFC,0x83,0x00,0x30,0x01,0x1F,0x3C,0x60,0x1D,0x00,0x00,0xF8,0x0F,0x10,0x01,0x6A,0x76,0x60,0x05,0x00,0x00,0xC0,0x01,0x08,0x02,0xCB,
0xD2,0x30,0x3D,0x00,0x00,0x60,0x03,0x0C,0x06,0x09,0x10,0x08,0x61,0x00,0x00,0x20,0x02,0x04,0x04,0x08,0x10,0x40,0x01,0x00,0x00,0x10,0x06,0x00,0x08,0x00,0x10,0xC0,
0x01,0x00,0x00,0x18,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

#define bmp3_x 80
#define bmp3_y 16
static const unsigned char bmp3[] U8X8_PROGMEM = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0xC0,0x03,0x80,0x00,
0x20,0x00,0x3C,0x0F,0xFC,0x0F,0xF8,0x00,0x80,0x79,0x78,0x3E,0xE6,0x09,0x40,0x00,0x80,0x00,0xFC,0x63,0x6E,0x32,0xC3,0x10,0x40,0x00,0x80,0x00,0x94,0x3B,0x7A,0x1A,
0xC1,0x10,0xF0,0x03,0xC0,0x07,0xF4,0x71,0x3F,0x1E,0x01,0x18,0x5C,0x00,0xF0,0x00,0xDC,0x17,0xF8,0x1E,0x01,0x08,0x40,0x0C,0x80,0x0C,0x60,0x14,0x98,0x0A,0x03,0x0C,
0x40,0x18,0x80,0x18,0xF0,0x17,0xF0,0x02,0x06,0x04,0x40,0x16,0x80,0x10,0x40,0x16,0x90,0x02,0x0C,0x02,0xF8,0x7B,0xFC,0x3F,0x80,0x13,0xF0,0x02,0x98,0x01,0x0F,0x80,
0x07,0x00,0x00,0x00,0x00,0x02,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};

void setup(void) {
  u8g2.setBusClock(200000);
  u8g2.begin();
  Serial.begin(9600);
  pinMode(bee,OUTPUT);


void loop(void) {
  int i;
  char a[10];
  val=digitalRead(redPin);//读取模拟接口的值
  Serial.println(val);//输出模拟接口的值
  Serial.println(rtc.getTimeStr());
  u8g2.setFont(u8g2_font_ncenB08_tr);	// choose a suitable font
  if (val==0){
  if (t3<180){
    u8g2.firstPage();
    do{
    //放下杯子开始计时
    u8g2.clearBuffer();
    itoa(t3,tt,10);
    u8g2.drawXBMP(30,0, bmp2_x, bmp2_y, bmp2);
    u8g2.drawLine(0, 25, t3*0.55, 25);
    u8g2.drawLine(0, 26, t3*0.55, 26);
    u8g2.drawLine(0, 27, t3*0.55, 27);
    u8g2.drawLine(0, 28, t3*0.55, 28);
    u8g2.drawLine(0, 29, t3*0.55, 29);
    u8g2.drawLine(0, 30, t3*0.55, 30);
    u8g2.drawLine(0, 31, t3*0.55, 31);
    itoa(t3*0.55,a,10);
    u8g2.drawStr(100,31,a);
    u8g2.drawStr(113,31,"%");  
    t3+=1;
    }while(u8g2.nextPage());
    delay(10000);
  //  }
  }
  else{
    t3=0;
    u8g2.clearBuffer();
    u8g2.drawXBMP(30,0, bmp1_x, bmp1_y, bmp1);
    u8g2.sendBuffer();
    digitalWrite(bee,HIGH);
    delay(200);
    digitalWrite(bee,LOW);
    delay(50);
    digitalWrite(bee,HIGH);
    delay(200);
    digitalWrite(bee,LOW);
    delay(100);
    digitalWrite(bee,HIGH);
    delay(200);
    digitalWrite(bee,LOW);
    delay(50);
    digitalWrite(bee,HIGH);
    delay(200);
    digitalWrite(bee,LOW);
    delay(100);
    digitalWrite(bee,HIGH);
    delay(200);
    digitalWrite(bee,LOW);
    delay(50);
    digitalWrite(bee,HIGH);
    delay(200);
    digitalWrite(bee,LOW);
    delay(10000);
    u8g2.sendBuffer();
    //响
    }
  }
  else{
    //拿起杯子
    t3=0;
    t1 = rtc.getTime();
    u8g2.clearBuffer();
    u8g2.sendBuffer(); 
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135

代码需要依赖u8g2库,具体安装方式可以自行在网络搜索

接线

如图,不多解释了
在这里插入图片描述

更换图或者字

使用pctolcd2002进行取模,字模设置如下图所示。
在这里插入图片描述
随后就可以在点阵区域随意发挥了。
在这里插入图片描述

在这里插入图片描述

外壳模型

外壳模型随意画了一个,已经上传到github:https://github.com/chenziwenhaoshuai/WaterRemind

成品

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/698208
推荐阅读
相关标签
  

闽ICP备14008679号