Music toilet based on single chip microcomputer design

Publisher:浅唱清风Latest update time:2015-08-07 Source: dzsc Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
The last course project before graduation, each student in the class has a topic. Mine is: Musical Toilet.
This program is not difficult, and only two I/O ports of the 51 single-chip microcomputer are used, but the idea of ​​the program is independent of the teacher. If there are any problems when you look back later, reflect on them. If it works, that's the best.
Because it was copied from WORD, it took time to format and the illustration errors would have to be corrected later. (The introduction of 51 single chip microcomputer was copied from the Internet)
 

Chapter 1: Introduction

1.1 Background:

When using the toilet, the noise makes the user embarrassed, especially in public places. If the noise can be covered by music, this problem can be solved well. The production of the music toilet originated from this.
There is no such product on the market now. The actual solution to this problem is to play music on public speakers, which can be seen in large supermarkets and high-end shopping malls. But for ordinary families and more public places, a simpler, low-cost and easy-to-maintain device is needed to achieve this function.
Searching on the Internet with "music toilet" as the keyword, there are only some patents related to the available finished products, which are about multi-functional toilets. These designs combine many functions with toilets, including showers, music playing, massages, etc. There is no entry point for music playing to resolve the noise in the toilet, so the finished product of this task can grasp the key to the problem well and solve a single problem on the basis of controlling costs.

1.2 Music Toilet Overview:

The music toilet is a circuit module embedded in the current toilet structure. It plays music for a certain length of time by sensing the vibration of the toilet. The circuit combined into a module is easy to implant and maintain, and the vibration sensing control is reliable and effective.

1.3 Task requirements:

Solve the embarrassing sound when using the toilet
Use the sound sensor device to activate the sound control switch inside the toilet. When the switch is activated, the toilet will automatically play music.
Sound control circuit
Music playing system
Sound sensor
Overall circuit
Software (program)

Chapter 2: Proposal Demonstration

2.1 Scheme 1:

The voice control module is triggered, the single chip is controlled, and the sound module outputs.
Advantages: It meets the requirements of the task book, and the voice control module is common and commonly used. In public toilets, multiple switches can be used to trigger the same music module, saving costs.
Negative reasons: The voice control module is complex and the sensitivity cannot be well controlled.

Musical Toilet (囧)
It can be seen from the typical voice control circuit that not only a small microphone for the sound recording device is required, but also a voice control IC, which undoubtedly increases the cost. Integration increases the size. If it is not integrated, the communication between modules must be considered. The large number of peripheral circuit components makes it difficult to work in the toilet environment and inconvenient to maintain.

2.2 Scheme 2:

Infrared photoelectric module triggers, single chip microcomputer controls, and sound module outputs.
Advantages: Placing the infrared module at the foot can be used for both squat toilets and toilets. In addition, the infrared integrated receiving component has a compact structure and is easy to use.
Negative reasons: The infrared module and the single chip microcomputer music module cannot be integrated together and installed under the foot, otherwise it will be difficult to maintain. If they are separated, the communication between the modules needs to be considered.

2.3 Scheme 3:

Using a vibration switch as a trigger, all modules are integrated into a circuit board. Stick it on the right position of the toilet (in actual production, it can be embedded in the toilet structure, leaving a battery replacement port).
Advantages: The vibration switch is simple and reliable (size: diameter 4.5mm, body length 11mm) and is completely sealed, waterproof and dustproof. It is beneficial for module integration, making the structure compact and easy to maintain. At the same time, solid-conducting vibration is more reliable and effective.

Chapter 3 Hardware Design

3.1 Schematic diagram drawing and analysis
After selecting scheme 3, the schematic diagram is drawn as follows: The system mainly consists of several main components: MSC-51 series microcontroller. Music module (connected to the P2.1 port of the microcontroller). Vibration switch (connected to the P3.2 port of the microcontroller). The system power supply is three 1.5V dry batteries. The open circuit and conduction states of the vibration switch are similar to those of a key switch, so it is directly used as an independent key. The IC chip module in the music module is an integrated product sold at a very low price. It is recommended to use it directly with the peripheral circuit. Since the operating voltage of the module is required to be 2.5V-4.5V. In order to provide a stable voltage of about 3V to the sound module under the operating voltage of the 4.5V microcontroller, the software simulation results show that when a common 47Ω resistor is connected in series, the voltage can be stabilized at about 3.16V. [page]
Musical Toilet (囧)











 
  Musical Toilet (囧)

The simulation effect diagram is as follows:

3.2 System hardware composition and functions:

Vibration switch*1

The correct name is: vibration sensor. It is divided into two categories: spring switch and ball switch. The vibration switch has flexible and sensitive triggering, and can be used as a trigger switch. The biggest difference between the ball switch and the spring switch is that the spring switch senses the size of the vibration force or centrifugal force, and it is best to use it upright. The ball switch senses the change of angle, and it is best to use it flat. You can use the appropriate type according to the actual location of the toilet.
The vibration switch is in an open circuit state when it is stationary. When it is touched by an external force and reaches an appropriate vibration force, or when the moving speed reaches an appropriate centrifugal (eccentric) force, the conductive foot will produce an instantaneous conduction state, causing the electrical characteristics to change. When the external force disappears, the electrical characteristics return to the open circuit state. The vibration switch is divided into high-sensitivity, sensitive, standard, and slow types. Different types can be selected according to the actual debugging situation. This design uses a sensitive type.



 
  Musical Toilet (囧)
















a. Bronze cover
b. Bronze beads - bottom nickel-plated - surface gold-plated
c. Bronze tube - bottom nickel-plated - surface gold-plated
Musical Toilet (囧)d. ABS or PC rubber seat
e. VC heat shrink tubing
f. Hard bronze guide pin - bottom nickel-plated - surface gold-plated
g. Phosphor bronze spring clip

 

 
  Musical Toilet (囧)

Music module*1:


 
  Musical Toilet (囧)

The shape is 18.5mm*9.5mm, the working voltage is 2.5V-4.5V. This kind of music piece is a type of continuous cycle sound when powered on. It can drive a speaker above 16 ohms or an active buzzer to sound when connected to an amplified NPN transistor. It can output internal audio signals without an amplifier. The specific use and working principle are described in the following diagram.
Musical Toilet (囧)

AT89S51 microcontroller

AT89S51 is a low-power, high-performance CMOS 8-bit single-chip microcomputer. It contains 4k Bytes ISP (In-system programmable) Flash read-only program memory that can be repeatedly erased and written 1000 times. The device is manufactured using ATMEL's high-density, non-volatile storage technology, compatible with the standard MCS-51 instruction system and 80C51 pin structure. The chip integrates a general 8-bit central processor and ISP Flash storage unit. The powerful microcomputer AT89S51 can provide cost-effective solutions for many embedded control application systems. [page]
AT89S51 has the following features: 40 pins, 4k Bytes Flash on-chip program memory, 128 bytes of random access data memory (RAM), 32 external bidirectional input/output (I/O) ports, 5 interrupt priority levels, 2 levels of interrupt nesting, 2 16-bit programmable timer counters, 2 full-duplex serial communication ports, watchdog (WDT) circuit, and on-chip clock oscillator.
1. Main features:

· 8031 ​​CPU compatible with MCS-51
· 4K bytes of programmable FLASH memory (life: 1000 write/erase cycles)
· Fully static operation: 0Hz-24KHz
· Three-level program memory security lock
· 128*8-bit internal RAM
· 32 programmable I/O lines
· Two 16-bit timers/counters
· 6 interrupt sources
· Programmable serial channel
· Low-power idle and power-down modes
· On-chip oscillator and clock circuit
2. Pin description:
VCC: power supply voltage
GND: ground.
P0 port: P0 port is an 8-bit open-drain bidirectional I/O port, each pin can absorb 8TTL gate current. When the pin of P1 port is written 1 for the first time, it is defined as a high-impedance input. P0 can be used for external program data storage, and it can be defined as the eighth bit of data/address. During FLASH programming, the P0 port is used as the original code input port. When the FLASH is verified, the P0 port outputs the original code. At this time, the P0 port must be pulled high externally.
P1 port: The P1 port is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P1 port buffer can receive and output 4 TTL gate currents. After the P1 port pin is written with 1, it is internally pulled up to high and can be used as an input. When the P1 port is externally pulled down to a low level, it will output current. This is due to the internal pull-up. During FLASH programming and verification, the P1 port is used as the eighth address to receive.
P2 port: The P2 port is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P2 port buffer can receive and output 4 TTL gate currents. When the P2 port is written with "1", its pin is pulled high by the internal pull-up resistor and used as an input. Therefore, when used as an input, the P2 port pin is externally pulled down and outputs current. This is due to the internal pull-up.
When the P2 port is used to access the external program memory or the 16-bit address external data memory, the P2 port outputs the upper eight bits of the address. When the address "1" is given, it takes advantage of the internal pull-up. When reading and writing the external eight-bit address data memory, the P2 port outputs the contents of its special function register. The P2 port receives the upper eight-bit address signal and control signal during FLASH programming and verification.
P3 port: The P3 port pins are 8 bidirectional I/O ports with internal pull-up resistors, which can receive and output 4 TTL gate currents. When "1" is written to the P3 port, they are internally pulled up to a high level and used as input. As an input, since the external pull-down is a low level, the P3 port will output current (ILL) due to the pull-up.
The P3 port can also be used as some special function ports of the AT89C51, as shown in the following table:

P3 port pinout special function
P3.0 RXD (serial input port)
P3.1 TXD (serial output port)
P3.2 Musical Toilet (囧)(External interrupt 0)
P3.3 Musical Toilet (囧)(External interrupt 1)
P3.4 T0 (Timer 0 external input)
P3.5 T1 (Timer 1 external input)
P3.6 WR (external data memory write strobe)
P3.7 RD (external data memory read first)

3.3 Implementation principle of music toilet:

The main program continuously scans the two situations of the play flag being 0 and the play flag being 1. The initial state of the play flag is 0, the music module is set to 0 (not playing), and the timing variable is always set to 0, waiting for the timing to start. When the vibration switch negatively jumps to trigger the external interrupt 0, the external interrupt program sets the music play flag to 1. At this time, the main program sets the music module to 1 (play), and the timing variable is no longer cleared to 0. When the timing variable reaches 3 minutes, the play flag is cleared to 0.

Chapter 4 System Software Design


4.1 System program flow chart:


Musical Toilet (囧)

4.2 Simulation and debugging:

The software is written in keil uvision2
programming language and uses C51
simulation software. The simulation diagram using proteus 7
is as follows:


 
  Musical Toilet (囧)

The single-chip microcomputer is already in the minimum system state.
D1 replaces the sound module and works at high power.
D2 is only used to display the timing status during simulation, 1S off and 1S on.
The key switch replaces the vibration switch, and the working principle is the switching of the open circuit state.
The simulation effect is as follows: when the key is pressed and released (equivalent to the vibration switch responding to a vibration and making a negative jump), D1 lights up (the single-chip microcomputer outputs high power, which is equivalent to the sound module being powered), and D2 starts to flash (proving that the timer is working normally). After 3 minutes, D1 goes out (equivalent to the sound module being powered off), D2 stops flashing (stops timing), and waits for the next key press (vibration trigger). [page]



Music toilet implementation diagram:
 
The ceramic wall marked with an ellipse is where the music toilet control module is installed. It is suitable for opening and replacing batteries. It can better transmit vibration. Musical Toilet (囧)


Conclusion

It has been a while since I started to learn MCU. When I think back to the beginning, I felt that MCU involves too many fields of knowledge, including electronics, microcomputer principles, programming, etc. Moreover, there are many obscure concepts in the initial theoretical learning stage. Through this course design practice, I thought about the relationship between theory and practice.
In the initial stage, facing a brand-new, huge new knowledge system, the guiding role of theory cannot be replaced. At least we must first establish our interest and hobbies in it, and then plan the development. Otherwise, we will have no idea how to start with the best prospect planning.
Although I am still in the entry stage, I can deeply feel that it is precisely because the knowledge involved in MCU is very broad that it brings unparalleled freedom, adaptability and flexibility. From the dazzling array of modules and ICs to the countless combinations of peripheral electronic components, there are basically no restrictions on software programming. All of this makes the MCU not the only way to solve problems, but also makes it easy to solve practical problems and can fit various actual situations and environments.
This course design requires the design of a musical toilet to solve the practical problem of people making sounds when going to the toilet and encountering embarrassment. During the learning process, I also did some questions and small objects. The biggest difference is that before this course design, I practiced in order to apply a specific knowledge point. This time, it is to solve a practical problem and apply the knowledge learned. Perhaps this is the basic starting point for engineers.
According to the solution ideas given by the teacher. Voice-controlled circuits, voice-controlled sensors, these common and commonly used functional modules in life, do give clear and concise answers as if at the first time. However, after in-depth analysis, the things we see in daily life exist somewhere, and perhaps we are all accustomed to them. In fact, they are all well in line with the actual requirements of the environment, and then become a habit. So for toilets and toilets, these environments with little contact, are these modules and circuits suitable?
Imagine that toilets and toilets must be often in contact with water. If the circuit is complicated and the module is not compact enough, it cannot be well ventilated and waterproof, and it must not adapt to the environment. In my opinion, this point cannot be met by voice-controlled control. If waterproof and moisture-proof external protection is added, its sensitivity will be affected. Furthermore, in a noisy environment in public places, voice control will not work well.
Based on the above analysis, it was finally decided to use simple and reliable vibration conduction as a trigger. Of course, there are many solutions for single-chip microcomputers, and it cannot be said that this one is more appropriate, but only by continuous thinking and argumentation can there be better, and there is no best answer. This is the charm of single-chip microcomputers and embedded systems.

appendix:

program:


//12MHZ
#include

sbit sound_mod = P2^1;

#define uchar unsigned char
uchar second;
uchar minute;
bit play_flag; //Music module play control bit
sbit shine = P2^0; //LED flashes in seconds during simulation

void run(void);

void init(void) //Timer, interrupt initialization function
{
sound_mod = 0;
TH0 = -50000/256;
TL0 = -50000%6;
TMOD = 0x01;
TR0 = 1;
IE = 0x83;
IT0 = 1;
}

void main(void)
{
init();
while (1)
{
run();
}
}
void run(void)
{
if (play_flag) //When the play flag is 1, the music module is powered
{
sound_mod = 1;
}
else if (!play_flag) //When the play flag is 0, the music module is not powered and the timer is reset to 3 minutes
{
minute = 0;
sound_mod = 0;
}
}

void timer(void) interrupt 1
{
static uchar counter;

counter++;
if (20 == counter) //20 timers overflow to 1 second
{
counter = 0;
second++;
shine = !shine;
if (60 == second) //minute carry
{
second = 0;
minute++;
{
if (3 == minute)//After the timer sets to 3 minutes, the play flag is cleared to 0
{
minute = 0;
play_flag = 0;
}
}
}
}


}
void shake(void) interrupt 0
{
play_flag = 1; //The vibration switch jump triggers the interrupt, the play flag position is 1
}
Reference address:Music toilet based on single chip microcomputer design

Previous article:Infrared decoding based on 8952 microcontroller (TC9012F encoding)
Next article:Our ADC0809 voltmeter

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号