基于树莓派的智能垃圾桶

该项目利用树莓派3B开发板创建了一个智能垃圾桶,具备自动感应开合盖、OLED屏幕显示温度和时间、以及远程电脑控制移动的功能。主要硬件包括OLED显示屏、超声波模块、舵机和直流电机等。代码中包含了服务端、OLED、超声波及电机驱动程序。
摘要由CSDN通过智能技术生成

基于树莓派的智能垃圾桶项目

预计所需要实现的功能
通过感应能够实现垃圾桶盖子的自动开关。
垃圾桶上装载OLED屏,屏幕上需要显示,温度,时间。
远程控制通过电脑端实现控制垃圾桶的移动。

功能模块:
1树莓派3B开发板一块
2OLED显示屏一块
3超声波模块
4SG90舵机
5直流电机,轮子,电机驱动板
6清洁桶

关于各种树莓派API可以查看

https://www.cnblogs.com/lulipro/p/5992172.html

程序代码:
服务端程序(写在树莓派上的)

include <stdio.h>
#include <netinet/in.h>
#include <errno.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <pthread.h>
#include <wiringPi.h>
#include "oled.h"
#include "log.h"
#include "chao.h"
#include "xiao.h"
#define echo 27
#define trlg 28
float distant;

#define RANGE 200  // 1 means 100 us , 200 means 20 ms
                   // 1等于100微妙,200等于20毫秒
void a_open() {
    softPwmWrite(3, 5);  //将pwm输出复写为使舵机转到0
    delay(100);
}
void b_open() {
    softPwmWrite(3, 15);
    delay(100);
    softPwmWrite(3, 15);
}

void *chaoshenbo() {

    while (1) {
        distant = wiring_distance();
        if (distant < 10) {
             a_open();
             b_open();
        }
         printf("distance=%.2f\n", distant);
    }
    return NULL;
}
int main(int a, char *avg[]) {
    int sock;
    int c_fd;
    pthread_t t1;
    pthread_t t2;
    pthread_t t3;
    softPwmCreate(3, 15, RANGE);

    wiringPiSetup();
    wiring_init();
    che_init();
    struct Msg *rec = (struct Msg *)malloc(sizeof(struct Msg));
    log_creat();
    sock = socket(AF_INET, SOCK_STREAM, 0);
    if (sock == -1) {
        perror("socker failed:\n");
        exit(-1);
    }
    struct sockaddr_in addr1;
    memset(&addr1, 0, sizeof(addr1));
    addr1.sin_family = AF_INET;
    addr1.sin_port = htons(atoi(avg[1]));
    inet_aton("192.168.43.215", &addr1.sin_addr);
    int on = 1;
    sets
  • 7
    点赞
  • 51
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值