Make a smart trash can with arduino

These days jobs do about it, toss a little time to continue my arduino, arduino last from TB buy suite has a body heat sensor module is used to sense the body close to the signal. Today we use this stuff to do a simple smart trash. To achieve that function: when someone close garbage can lid opens automatically when people leave, the lid can automatically shut down.

First, the necessary materials and tools:

1 Arduino microcontroller I use the Nano the Arduino
Make a smart trash can with arduino
2 body heat sensor module
I use a brand-name, but the wiring and use the same, and HC-SR501
Make a smart trash can with arduino
3 Servo SG90
Make a smart trash can with arduino
. 4 clamshell trash preferably smaller one.
Make a smart trash can with arduino
5 and a mobile phone charging head mini USB cable directly to the microcontroller power supply used, is not a common mobile phone we microUSB TYPE C interface or interfaces.
Make a smart trash can with arduino
6 wire
7 glue gun
8 electric iron
9 blades and other tools
Description:
1, because the steering torque is small SG90 (this can be understood as not much effort steering gear), only a small trash can push the cover, if the garbage barrel is too large, we need more torque servos, and require a separate power supply to the steering gear.
2, my arduiono package the complimentary body heat sensor module is a no-name stuff, but wiring and use the HC-SR501 same.

Second, the program code

The code is simple, only a few lines.

#include <Servo.h>//舵机所需类的头文件
/*
 * 本例结合人体红外感应模块和舵机实现对垃圾桶的自动控制。
 * 当人接近或离开垃圾桶时,单片机根据信号强度的变化,操作舵机旋转到指度角度,实现垃圾桶的自动开关。
 * 人体红外感应模块型号为HC-SR501,三条线分别为+5伏,地线和输出信号口,输出信号接A3
 * 舵机用型号为sg90,本舵机有三条线,红为+5伏,褐色为GND,橙色为信号给,本例接pin9
 * 本例在arduino nano上实验通过
*/

Servo myservo;  // 创建舵机对象来控制舵机
int angle_pos = 0; 
int pin_sensory= A3;//设置A3接人体感应信号的out口

int value; 
void setup() 
{   
   // 初始化串口通信
   Serial.begin(9600); 
   Serial.println("Signal Intensity:");
   // 把连接在引脚9上的舵机赋予舵机对其控制
   myservo.attach(9);  
   pinMode(pin_sensory,INPUT);
   myservo.write(angle_pos);

} 
void loop() 
{ 
      value= analogRead(pin_sensory); 
      Serial.println(value);
      angle_pos=myservo.read(); 
      if (value>=400)//当值大于400时,舵机转到90度,垃圾桶开盖。
      //这个值需要自己根据不同距离调整,距离越近,信号越强,经验数据:在距离探头20公分时,强度值约800,人离开后,强度值约40。
      {
         myservo.write(90);//舵机转到90度
         delay(50);
      }

      else
      {
        delay(50);
        myservo.write(0);//舵机回到0度

      }

        delay(1000);
}

Third, the line connection

实物连接如下图:
Make a smart trash can with arduino
说明一下:
1、SG-90舵机上有三条线,一般情况下棕色是地线,接GND,红色是V+,接正5伏,橙色为控制线,我接在9号接口。
舵机有两种驱动方式,第一种方式是无驱动的,可以用在所有可用的端口上,但程序代码比较复杂,用起来相对麻烦,第二种是有驱动的,代码非常简单,但只能接在9、10两个口上,本例中使用第二种方式(所在我们代码的开头第一行就引用了舵机驱动类的头文件)。
2、HC-SR501人体热能感应模块也有三个接口,上面标的有,VCC接正5伏,GND接地线,OUT我接在A3上。
3、本来还想加一个LED指示灯,用来在夜间指示垃圾桶的位置,但感应模块上有一个蓝色的指示灯,在人体接近时就会自动点亮,所以这个就省了。

四、安装和调试

1、写入程序,这个都会,我用的是arduino IDE(1.8.5版的),将上面的代码复制进去,在面包板上按上图接好,编译后直接点击上传就行了。
Make a smart trash can with arduino

Make a smart trash can with arduino
2、改装垃圾桶
我找的垃圾桶是那种翻盖的桌上小垃圾桶,盖子像一个翘翘板。将盖子从限位销中取出来,用刀片将限位销去掉,然后在限位销的位置打孔。
然后找一个用完的水笔芯(之所以选择水笔芯,是因为他的粗细刚好能套在舵机主轴的齿轮上,而且结合得非常紧。)穿过刚才打的孔和垃圾桶盖子上的孔,并用热熔胶固定。
Make a smart trash can with arduino
然后在垃圾外侧固定舵机、单片机和感应模块,为了外面美观一些,我用3D打印机做了一个小盒子放单片机和感应模块,没有的朋友可以用一个雪茄盒或其它材料代替。
将舵机主轴插入水笔芯的孔中,并用热熔胶将舵机和小盒子固定住。
需要注意的时,舵机主轴固定在水笔芯的时候要注意舵机的0度和90度位置,以免出现初始化时垃圾桶盖子关不严的情况。
Make a smart trash can with arduino

五、运行效果

Use miniUSB charging head to the phone line and through the 5 VDC arduino, can run, see the following operation video connection. It looks to pull the wind it!
https://v.youku.com/v_show/id_XNDM5Nzk3MTQ1Mg==.html?spm=a2h3j.8428770.3416059.1

Guess you like

Origin blog.51cto.com/6273125/2442334