目次
结构
测量身高是非常困难的, 因为孩子不能长时间静坐。
因此, 我们以低廉的价格找到了一个高精度传感器, 所以我们创建了一个不占用空间和时间的高度测量仪器。
目次
Distance sensor VL53L0X
It is a sensor of the resolution 1mm in a great wide range!The library for Arduino is below.
https://github.com/pololu/vl53l0x-arduino
6 axis motion sensor MPU6050
3-axis gyroscope and 3-axis accelerometer can sensing posture information.This time, we use horizontal x-axis and y-axis acceleration to measure the level of the measuring instrument.But it’s a mess!The library for Arduino is located below (using mpu6050 and I2cdev).
https://github.com/jrowberg/i2cdevlib/tree/master/Arduino
LCD display
https://www.arduino.cc/en/Tutorial/HelloWorld
Microcontroller Arduino Nano compatible
I use a cheap compatible product:-)
距离传感器 vl53l0x 被放置在盒子的底部。该传感器可以测量高达2米的距离, 分辨率为1毫米。
将微机 arduino nano 和6轴运动传感器 mpu6050 放入机箱中, 电源采用9v 电池。
MPU6050 用于测量加速度的 x 轴和 y 轴, 以检测水平方向。当测量水平时, led (nepipxel) 为绿色。当非水平为浅红色时。
距离显示在 lcd 显示屏上。
打开电源开关, 测量在正常模式下运行。在正常模式下, 测量距离始终显示在 lcd 上。当测量水平为水平时, 指示灯为绿色。当非水平为浅红色时。
当你按住梅拉斯的时候。按钮 (键开关), 它将是测量模式。把尺寸放在头上。打开测量模式。当检测到水平状态下的距离时, led 为蓝光, 并保持测量值。
距離センサVL53L0Xで長女ちゃん身長測定 pic.twitter.com/1tMOndvOgy
— HomeMadeGarbage (@H0meMadeGarbage) 2016年9月16日
再次按下测量按钮, 恢复到正常模式。
距离传感器 vl53l0x 用于远距离模式和高精度模式。
在 cm 中, 距离调整到设备, 并对传感器位置进行校正 (1mm)。
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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
#include "I2Cdev.h" #include "MPU6050.h" #include <Adafruit_NeoPixel.h> #include <VL53L0X.h> #include <LiquidCrystal.h> // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation // is used in I2Cdev.h #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE #include "Wire.h" #endif int mode = 0; MPU6050 accelgyro; // class default I2C address is 0x68 int16_t ax, ay, az; int diffAccel = 100; #define PIN 8 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800); //LiquidCrystal lcd(RS[4], E[6], DB4[11], DB5[12], DB6[13], DB7[14]); LiquidCrystal lcd(12, 11, 5, 4, 3, 2); char s[16]; VL53L0X sensor; float height; // Uncomment this line to use long range mode. This // increases the sensitivity of the sensor and extends its // potential range, but increases the likelihood of getting // an inaccurate reading because of reflections from objects // other than the intended target. It works best in dark // conditions. #define LONG_RANGE // Uncomment ONE of these two lines to get // - higher speed at the cost of lower accuracy OR // - higher accuracy at the cost of lower speed //#define HIGH_SPEED #define HIGH_ACCURACY void setup() { // join I2C bus (I2Cdev library doesn't do this automatically) #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE Wire.begin(); #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE Fastwire::setup(400, true); #endif Serial.begin(38400); pinMode(9, INPUT_PULLUP); pixels.begin(); pixels.setBrightness(50); pixels.setPixelColor(0, pixels.Color(0,0,0)); pixels.show(); lcd.begin(16, 2); lcd.setCursor(0, 0); lcd.print("x"); lcd.setCursor(9, 0); lcd.print("y"); lcd.setCursor(0, 1); lcd.print("Height:"); sensor.init(); sensor.setTimeout(500); #if defined LONG_RANGE // lower the return signal rate limit (default is 0.25 MCPS) sensor.setSignalRateLimit(0.1); // increase laser pulse periods (defaults are 14 and 10 PCLKs) sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18); sensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14); #endif #if defined HIGH_SPEED // reduce timing budget to 20 ms (default is about 33 ms) sensor.setMeasurementTimingBudget(20000); #elif defined HIGH_ACCURACY // increase timing budget to 200 ms sensor.setMeasurementTimingBudget(200000); #endif // initialize device Serial.println("Initializing I2C devices..."); accelgyro.initialize(); // verify connection Serial.println("Testing device connections..."); Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); if(accelgyro.testConnection()){ pixels.setPixelColor(0, pixels.Color(255,0,0)); pixels.show(); } // use the code below to change accel/gyro offset values accelgyro.setXAccelOffset(40); //0 accelgyro.setYAccelOffset(-985); //0 accelgyro.setZAccelOffset(968); //16384 } void loop() { //Measurement Mode while(digitalRead(9) == 0 && mode == 0){ // read raw accel accelgyro.getAcceleration(&ax, &ay, &az); lcd.setCursor(1, 0); lcd.print(dtostrf(ax,6,0,s)); lcd.setCursor(10, 0); lcd.print(dtostrf(ay,6,0,s)); if(abs(ax) < diffAccel && abs(ay) < diffAccel){ pixels.setPixelColor(0, pixels.Color(0,255,0)); pixels.show(); if (sensor.timeoutOccurred() == 0) { //Distance measurement height = sensor.readRangeSingleMillimeters()/10.0 + 0.1; lcd.setCursor(8, 1); if(height <= 220.0){ lcd.print(dtostrf(height,5,1,s)); pixels.setPixelColor(0, pixels.Color(0,0,255)); pixels.show(); mode = 1; } } }else{ pixels.setPixelColor(0, pixels.Color(255,0,0)); pixels.show(); } } //Mode Reset if(digitalRead(9) == 1 && mode == 1){ mode = 2; delay(100); } if(digitalRead(9) == 0 && mode == 2){ mode = 0; delay(100); } //Normal Mode if(digitalRead(9) == 1 && mode == 0){ // read raw accel accelgyro.getAcceleration(&ax, &ay, &az); lcd.setCursor(1, 0); lcd.print(dtostrf(ax,6,0,s)); lcd.setCursor(10, 0); lcd.print(dtostrf(ay,6,0,s)); if(abs(ax) < diffAccel && abs(ay) < diffAccel){ pixels.setPixelColor(0, pixels.Color(0,255,0)); pixels.show(); }else{ pixels.setPixelColor(0, pixels.Color(255,0,0)); pixels.show(); } if (sensor.timeoutOccurred() == 0) { //Distance measurement height = sensor.readRangeSingleMillimeters()/10.0 + 0.1; Serial.print(height); Serial.print("\t"); lcd.setCursor(8, 1); if(height <= 220.0){ lcd.print(dtostrf(height,5,1,s)); } } } } |
因为它可以测量在相对较高的速度和精度是高的, 我可以很容易地测量它, 即使在大儿子的高度谁是不安在这