Arduino Dishwasher

1. Arduino

Arduino is an open source electronics prototyping platform with flexible, easy-to-use hardware and software. Arduino is designed for designers, craftsmen, hobbyists, and anyone interested in developing interactive installations or interactive development environments.

Arduino can receive input signals from various sensors to detect the operating environment, and affect its surroundings by controlling light sources, motors, and other drivers. The microcontroller on the board is programmed using the Arduino programming language (based on Wiring) and the Arduino development environment (based on Processing). Arduino can run independently or communicate with software (eg, Flash, Processing, MaxMSP) running on the computer. The Arduino development IDE interface is based on open source code, which allows you to download and use it for free to develop more amazing interactive works.
accc

2. Ultrasonic module——HC-SR04

The ultrasonic transmitter emits ultrasonic waves in a certain direction, and starts timing at the same time as the emission. The ultrasonic waves propagate in the air, and return immediately when encountering obstacles on the way, and the ultrasonic receiver stops timing immediately after receiving the reflected waves.

1. Ultrasonic ranging principle: time difference ranging method

The propagation speed of sound waves in the air is 340m/s. According to the time t recorded by the timer, the distance s from the emission point to the obstacle can be calculated, namely: s=340m/s×t/2

2. Working principle:

    1)通过某个引脚(IO)给至少10us的高电平信号触发测距;
    2)触发测距以后模块自动发送8个40khz的方波,自动检测是否有信号返回;
    3)如果有信号返回,通过IO输出一高电平,高电平持续时间就是超声波从发射到返回的时间
    4)测试距离=(高电平时间*声速(340M/S))/2;

VCC is the power supply for the ultrasonic distance sensor, connected to the 5V pin on the Arduino.
The Trig (Trigger) pin is used to trigger an ultrasonic pulse - A0
Echo The pin generates a pulse when a reflected signal is received. The length of the pulse is proportional to the time it takes to detect the transmit signal - A1
GND should be connected to the Arduino's GND

Code example:

int TrgPin = A0;
int EcoPin = A1;
float dist;
void setup()
{
    
       
Serial.begin(9600);//设置TrgPin为输出状态
pinMode(TrgPin, OUTPUT);// 设置EcoPin为输入状态
pinMode(EcoPin, INPUT);
}
void loop()
{
    
    
digitalWrite(TrgPin, LOW);
delayMicroseconds(8);
digitalWrite(TrgPin, HIGH);
delayMicroseconds(10);// 维持10毫秒高电平用来产生一个脉冲
digitalWrite(TrgPin, LOW);
dist = pulseIn(EcoPin, HIGH) / 58.00;// 读取脉冲的宽度并换算成距离
Serial.print("Distance:");
Serial.print(dist);
Serial.println("cm");
delay(300);
}

3. Steering gear——SG90 steering gear

The steering gear is a kind of position (angle) servo driver. The steering gear is just a popular name, and its essence is a servo motor.
Among them, SG90 is an analog steering gear, which needs to continuously send PWM signals of corresponding angles to rotate to the specified position. For example: if I let it rotate 90 degrees now, I need to send 90-degree PWM signals continuously within a certain period of time, and the servo will stop when it turns to the specified position.
The rotation angle of the steering gear is mostly 0~180°, and its internal structure includes three parts: motor, control circuit and mechanical structure. The motor has three leads, which are respectively connected to VCC, GNG and signal lines.

There are mainly two formats of lead wires:
brown, red, orange (brown connects to GND, red connects to VCC, orange connects to signal);
red, black, yellow (red connects to VCC, black connects to GND, yellow connects to signal).

working principle

The control signal of the steering gear is a pulse width modulation (PWM) signal with a period of 20ms, where the pulse width is from 0.5ms to 2.5ms, corresponding to the position of the steering wheel from 0 to 180 degrees, and it changes linearly. That is to say, if it is provided with a certain pulse width, its output shaft will remain at a corresponding angle. No matter how the external torque changes, it will not change the output until it is provided with a pulse signal of another width. Angle to the new corresponding position. There is a reference circuit inside the steering gear, which generates a reference signal with a period of 20ms and a width of 1.5ms. There is a comparator that compares the external signal with the reference signal to determine the direction and magnitude, thereby generating the rotation signal of the motor.

The control circuit board receives the corresponding PWM control signal from the signal line, and then controls the rotation of the motor. The motor drives a series of gear sets, and after deceleration, it is transmitted to the output steering wheel. The output shaft of the steering gear is connected to the position feedback potentiometer. When the steering wheel rotates, the position feedback potentiometer is driven. The potentiometer will output a voltage signal to the control circuit board for feedback, and then the control circuit board determines the motor according to its position. The direction and speed of rotation, so as to achieve the target stop.
The control of the steering gear requires the MCU to generate a pulse signal with a period of 20ms, and control the rotation angle of the steering gear with a high level of 0.5ms to 2.5ms.
insert image description here

Code example:

#include <Servo.h>  //加入含有舵机控制库的头文件

#define PIN_SERVO 9  //舵机信号控制引脚
Servo myservo;  
int pos=0;

void setup()  
{
    
      
  myservo.attach(PIN_SERVO);  //舵机初始化
}  
  
void loop()  //0到180,再从180到0 
{
    
      
  for (pos=0;pos<=180;pos+=1){
    
    
    myservo.write(pos);
    delay(10);
    }
    for (pos=180;pos<=0;pos-=1){
    
    
    myservo.write(pos);
    delay(10);
    }
  //myservo.write(90);  //PWM输出
} 

4. Water pump & relay

To put it bluntly, it is a motor controlled by a relay, and it starts to work when the circuit is turned on.

Relay principle: weak current controls strong current

accc

NC: Normally closed terminal NO: Normally open terminal COM: Common terminal
VCC: Positive pole of power supply GND: Negative pole of power supply IN: Signal input terminal

5. Voice broadcast——SYN6288

insert image description here
The core board interface is: BUSY GND TXD RXD VCC BIN0 NP0, where VCC GND is used for power supply, the voltage supports 3-5V, 5V is recommended; BUSY is a busy sign, high level is busy (in playback), low level Idle; TXD RXD is serial port communication, where TXD is the sending end, connected to the peripheral receiving end; BIN0 BP0 is the speaker interface, which can be directly connected to the 8R 0.5W speaker. Remember the speaker must be 8R 0.5W.
Example given by the official: (The content of the broadcast was changed by me)

/*
1.项目名称:Arduino综合测试板SYN6288语音合成模块测试程序
2.配套APP:无
3.主要原理:具体参考SYN6288数据手册,通过串口发送语音对应的数据
4.配套上位机:无
5.项目组成:SYN6288语音合成模块、Arduino综合测试板
6.项目功能:将文字转换为语音朗读出来。具体操作请看演示视频

*/

//此处发送内容为:[m4][v16][t5]欢迎使用SYN6288语音合成模块
//v[0~16]:0背景音乐为静音,16背景音乐音量最大
//m[0~16]:0朗读音量为静音,16朗读音量最大
//t[0~5]:0朗读语速最慢,5朗读语速最快
//其他不常用功能请参考数据手册
void xiwan(){
    
          //语音播报
  unsigned char i = 0;
  unsigned char head[20];
 
  head[0] = 0xFD;  //FD 00 22 01 01 0D 0A
  head[1] = 0x00;
  head[2] = 0x0B;
  head[3] = 0x01;
  head[4] = 0x01;
  head[5] = 0xBF;
  head[6] = 0xAA; // C4 E3 BA C3 20 CE D2 CA C7 C8 AB 
  head[7] = 0xCA;
  head[8] = 0xBC;
  head[9] = 0xCF;
  head[10] = 0xB4;
  head[11] = 0xCD;
  head[12] = 0xEB;
  head[13] = 0xC8;


  for(i=0; i<43; i++){
    
    
    Serial.write(head[i]);
  }
}



void setup() {
    
    
  Serial.begin(9600);
}

void loop() {
    
    
  xiwan();
  delay(2000);
}

The whole code is as follows:

#include <Servo.h>
//水泵+————继电器常开  -————地
//继电器公共端————正极
//各模块与arduino共地

int relayPin = 13;  //继电器引脚负也接到单片机上
int TrgPin = A0;    //超声波引脚
int EcoPin = A1;    //超声波引脚

Servo myservo;  //定义Servo对象来控制舵机
int pos = 0;    //角度存储变量
float dist;     //距离

void xiwan() {
    
      //语音播报--开始洗碗
  unsigned char i = 0;
  unsigned char head[20];

  head[0] = 0xFD;
  head[1] = 0x00;
  head[2] = 0x0B;
  head[3] = 0x01;
  head[4] = 0x01;
  head[5] = 0xBF;
  head[6] = 0xAA;
  head[7] = 0xCA;
  head[8] = 0xBC;
  head[9] = 0xCF;
  head[10] = 0xB4;
  head[11] = 0xCD;
  head[12] = 0xEB;
  head[13] = 0xC8;

  for (i = 0; i < 43; i++) {
    
    
    Serial.write(head[i]);
  }
}

void end() {
    
      //语音播报--洗碗完成
  unsigned char s = 0;
  unsigned char head1[20];

  head1[0] = 0xFD;
  head1[1] = 0x00;
  head1[2] = 0x0B;
  head1[3] = 0x01;
  head1[4] = 0x01;
  head1[5] = 0xCF;
  head1[6] = 0xB4;
  head1[7] = 0xCD;
  head1[8] = 0xEB;
  head1[9] = 0xCD;
  head1[10] = 0xEA;
  head1[11] = 0xB3;
  head1[12] = 0xC9;
  head1[13] = 0xF6;

  for (s = 0; s < 53; s++) {
    
    
    Serial.write(head1[s]);
  }
}

void setup() {
    
    

  myservo.attach(9, 500, 2500);  //修正脉冲宽度
  pinMode(TrgPin, OUTPUT);       //设置TrgPin为输出状态
  pinMode(EcoPin, INPUT);        // 设置EcoPin为输入状态
  pinMode(relayPin, OUTPUT);     //设置引脚13为输出接口
  Serial.begin(9600);            //设置波特率为9600,这里要跟软件设置相一致。当接入特定设备时,我们也要跟其他设备的波特率达到一致。
  digitalWrite(relayPin, HIGH);  //防止一上电继电器就工作
}

void loop() {
    
    

  digitalWrite(TrgPin, LOW);
  delayMicroseconds(8);
  digitalWrite(TrgPin, HIGH);
  delayMicroseconds(10);  // 维持10毫秒高电平用来产生一个脉冲
  digitalWrite(TrgPin, LOW);
  dist = pulseIn(EcoPin, HIGH) / 58.00;  // 读取脉冲的宽度并换算成距离

  if (dist <= 6 && dist > 1)  // 距离小等于6cm
  {
    
    
    digitalWrite(relayPin, LOW);  //水泵开始工作
    xiwan();                      //语音播报
    delay(2000);                  //等待语音播报完成

    for (pos = 0; pos <= 180; pos++) {
    
      // 0°到180°
      myservo.write(pos);               // 舵机角度写入
      delay(5);                         // 等待转动到指定角度
    }
    for (pos = 180; pos >= 0; pos--) {
    
      // 从180°到0°
      myservo.write(pos);               // 舵机角度写入
      delay(5);                         // 等待转动到指定角度
    }
  }

  else {
    
    
    digitalWrite(relayPin, HIGH);  //水泵停止工作
    end();                         //语音播报
    delay(2000);                   // 等待播报
  }
}

Guess you like

Origin blog.csdn.net/weixin_52051554/article/details/129844419