Building a Real-Time Wireless Flood Monitoring System with HC-SR04 and AVR ATmega

Contents hide

Objectives

There are a few objectives that need to be met to get this project done: These objectives will act as a guide and restrict the system to be implemented for certain situations:

  • To develop a model of REAL TIME WIRELESS FLOOD MONITORING SYSTEM by using the ultrasonic sensor to measure the water depth in the river.
  • To send this water level value from the transmitter module to the receiver module in the control room using the RF transceiver.
  • To display the water level using LCD. Then Depending on the measurements of the previous years for the same river we also have a set of LEDs to show the current value of the water level located in which level (safe, medium, or risky).
  • To use Keil (IDE) Micro Vision software to generate a computer program for the microcontroller to get signal in real-time.

Significance of the projects

This project aims to conceive a model of a water level detection system as a subsystem of the overall control system of the river flow management system.

  •  LED with a green color means that the water level is still at the safe level.
  • LED with a yellow color means that the water level at the area between the safe level and the level of risk (medium level).
  • LED with a red color means that the water level has reached the level of risk (flood level).

And then if the water level rises or falls rapidly to a dangerous level a buzzer shall be set to go off.

Building a Real-Time Wireless Flood Monitoring System with HC-SR04 and AVR ATmega

Proposed Approach and Methods to Be Employed

  1.  The Ultrasonic ranging module HC – SR04.
  2. RF transceiver.
  3.  Microcontrollers.
  4. The Liquid Crystal Display (LCD).
  5. The Light Emitting Diodes (LEDs) and the buzzer.

Proposed Approach and Methods to Be Employed

Background of ultrasonic distance measurement

Background of ultrasonic distance measurement

 

total distance

 

Selection of the ultrasonic sensor

The radio frequency module (RF module)

What is an RF Module?

Types of RF modules

Most standard, well-known types are covered here:

  • Transmitter modules.
  • Receiver modules.
  • Transceiver modules.
  • System on a chip module.

Transmitter modules

An RF transmitter module is a compact printed circuit board (PCB) component designed to transmit radio waves and modulate them to carry data. These modules are typically used in conjunction with a microcontroller, which supplies the data to be transmitted. RF transmitters must comply with regulatory requirements that set limits on transmitter power output, harmonics, and band edge specifications.

Receiver modules

An RF receiver module receives and demodulates the modulated RF signal. There are two types of RF receiver modules: super-heterodyne receivers and super-regenerative receivers. Super-regenerative modules are typically low-cost, low-power designs that use a series of amplifiers to extract modulated data from a carrier wave. However, they tend to be imprecise, as their operating frequency can vary significantly with changes in temperature and power supply voltage. Super-heterodyne receivers, on the other hand, provide better accuracy and stability across a wide range of voltages and temperatures. This stability is achieved through a fixed crystal design, which makes them more expensive compared to super-regenerative modules.

Transceiver modules

An RF transceiver module combines both a transmitter and a receiver in a single circuit. It is typically designed for half-duplex operation, although full-duplex modules are also available. However, full-duplex modules are usually more expensive due to their increased complexity.

System on a chip module

A system-on-a-chip (SoC) module functions similarly to a transceiver module but often includes an on-board microcontroller. This microcontroller is typically used to handle radio data packetization or manage protocols, such as those compliant with IEEE 802.15.4. Such modules are commonly used in designs that require extra processing for protocol compliance, allowing the designer to avoid incorporating this processing into the host microcontroller.

Main factors affecting RF module performance

Microcontroller

STC Microchip Rabbit Intel
  • Wide availability
  • Free software
  • Debugger unit not required
  • Serial programming capability, support C, C++, and assembly
  • Most familiar with the use
  • Lowest cost
  • Wide availability
  • Extensive collection of application notes
  • The debugger unit is costly
  • Serial programming capability, support C, C++, and assembly
  • unfamiliar with the use
  • low cost
  • high performance
  • free software
  • Debugger unit not required
  • unfamiliar with the use
  • expensive
  • reliable brand
  • Serial programming capability, support C, C++, and assembly
  • unfamiliar with the use
  • most expensive

 

Microcontroller Advantages

  • Highly integrated and powerful – thousands of transistors on a single chip.
  • Can be used to replace a handful of discreet logic chips.
  • Relatively easy to learn and implement.
  • Easier to integrate into a design than discreet logic chips.
  • Very low hardware cost possible.
  • Many types and manufacturers are available.
  • Architectures and programming languages vary somewhat, so what you learn about one microcontroller is good knowledge to apply to another one.
  • Many different IC packages are available (DIP8, SOIC-16, etc.)

Microcontroller Disadvantages

  • Microcontrollers are IC chips and need to be put onto a custom-designed PC board. This takes time and money, which may not suit all applications. Contrast this with an industrial automation PLC, which is a computer-in-a-box that contains simple screw terminals to connect power, communication, and I/O.
  • Programming microcontrollers require a certain amount of skill and training.
  • The programming and debugging software can be quite costly.

I have decided to weigh against a few brands that have adequate technology for the project. By the comparison of pros and cons, I selected the STC microcontroller.

Programming Language Considerations

All microcontrollers come with a range of standard tools provided by the manufacturer. Most include Integrated Development Environments (IDEs) that integrate an editor with an assembler, other compilers, and a simulator. However, if there is a preference not to use the provided tools, or if the microcontroller does not come with any tools, low-level assembler language or any high-level language like C that is supported by the microcontroller can be used instead.

Assembly Language

Assembly languages are a type of low-level language used for programming computers or microcontrollers. They provide a symbolic representation of the numeric machine codes and other constants necessary for CPU architecture programming. Typically defined by the hardware manufacturer, assembly languages use abbreviations called mnemonics, which help the programmer remember individual instructions and registers. Programming in assembly language is made easier by the manufacturer providing an assembler for the chip, along with detailed instructions in the datasheet. Additionally, these assemblers generate the fastest and most optimized code.

‘C’ Programming Language

Selection of Programming Language

The C programming language is often chosen after evaluating other types of software languages. The reasons for this choice include its ease of maintenance and the ability to avoid dealing with memory location details, as these are managed by the cross-compiler in C. Additionally, C is a high-level language that is widely popular and produces compiled code that runs quickly.

Liquid Crystal Display (LCD)

Liquid Crystal Display (LCD)

Light Emitting Diode (LED)

An LED is a semiconductor diode that emits light when an electrical voltage is applied in the forward direction. When the anode of the LED has a voltage that is more positive than the cathode by at least the forward voltage drop, current flows through the device. This allows electrons to recombine with holes within the LED, releasing energy in the form of photons. This phenomenon, known as electroluminescence, results in light emission, with the color of the light determined by the energy band gap of the semiconductor.

In this project, LEDs will be used as indicators of the prototype. Specifically, a green LED, a yellow LED, and a red LED will indicate different water levels.

Light Emitting Diode (LED)

Buzzer

A buzzer is an audio signaling device that can be either mechanical or electronic. It is commonly used as an alarm, timer, or to confirm user input. The sound output from a buzzer can be continuous or intermittent. With a typical output of at least 75dB, it provides ample auditory alert for the user. In this system, a buzzer is used to sound an alarm if the water level changes rapidly and reaches a potentially dangerous level.

Buzzer

Power Supply Module

Power Supply Module

HARDWARE DESIGN

This chapter outlines the hardware implementation of the project, which is segmented into various essential parts needed to complete the project. It includes a list of the hardware components used, and the design and implementation of these components will be thoroughly discussed in the following sections.

The whole Hardware Design and Implementation

The whole design mainly includes the following parts:

  1. The HC-SR04 Ultrasonic sensors.
  2. nRF24L01 RF transceiver (The radio frequency module).
  3. STC89C52RC Microcontroller: to program and control devices.
  4. Power Supply: to supply voltage power to the whole system.
  5. 12864 LCD: to display the water level.
  6. Buzzer and LEDs: alert panel (to give a signal to the operator or driver).

schematic circuit diagram

receiver module

 

 

 

The HC-SR04 Ultrasonic sensors

In this project, the ultrasonic sensor is required to detect obstacles and objects ranging from a few centimeters up to 400 cm. Given that the system’s power supply is sourced from a battery pack, minimizing power consumption is essential, and the ability to operate at low voltage is crucial. After extensive research comparing the SR04 with other ultrasonic sensors, the SR04 was chosen for its ability to quickly detect obstacles, meeting the project’s specifications.

HC – SR04 features

The HC-SR04 ultrasonic ranging module offers a non-contact measurement capability from 2cm to 400cm, with a precision of up to 3mm. The module includes an ultrasonic transmitter, a receiver, and a control circuit. The basic operating principles are as follows:

  1. Using IO trigger for at least 10µs high-level signal,
  2. The Module automatically sends eight 40 kHz signals and detects whether there is a pulse signal back.
  3. If the signal comes back, through a high level, the time of high output IO duration is the time from sending ultrasonic to returning.

Test distance = (high-level time×velocity of sound (340m/s) .

HC - SR04 features

 

The wire connecting directly as follows:

  • 5V power supply
  • Trigger Pulse Input
  • Echo Pulse Output
  • 0V Ground
Working voltage DC 5V
Working current 15 mA
Working frequency 40Hz
Max range 4m
Min range 2 cm
Measuring angle 15 degree
Trigger input signal 10 µs TTL pulse
Echo output signal Input TTL lever signal and the range in proportion
Dimension 450*20*15 mm

 

HC – SR04 Timing diagram

3.2.2 HC - SR04 Timing diagram

nRF24L01 Single Chip 2.4GHz Transceiver

nRF24L01 features

Features of the nRF24L01 include:
Radio

  • Worldwide 2.4GHz ISM band operation
  • 126 RF channels
  • Common RX and TX interface
  • GFSK modulation
  • 250kbps, 1 and 2Mbps air data rate
  • 1MHz non-overlapping channel spacing at 1Mbps
  • 2MHz non-overlapping channel spacing at 2Mbps

Transmitter

  • Programmable output power: 0, -6, -12 or -18dBm
  • 11.3mA at 0dBm output power

Receiver

  • Fast AGC for improved dynamic range
  • Integrated channel filters
  • 13.5mA at 2Mbps
  • -82dBm sensitivity at 2Mbps
  • -85dBm sensitivity at 1Mbps
  • -94dBm sensitivity at 250kbps

 RF Synthesizer

  • fully integrated synthesizer
  • No external loop filter, VCO varactor diode, or resonator
  • Accepts low-cost ±60ppm 16MHz crystal

•Enhanced ShockBurst

  • 1 to 32 bytes dynamic payload length
  • Automatic packet handling
  • Auto packet transaction handling
  • data pipe MultiCeiver™ for star networks

Power Management

  • Integrated voltage regulator
  • 1.9 to 3.6V supply range
  • Idle modes with fast start-up times for advanced power management
  • μA Standby-I mode, 900nA power down mode
  • Max 1.5ms start-up from power-down mode
  • Max 130us start-up from standby-I mode

nRF24L01 block diagram

nRF24L01 block diagram

 

nRF24L01 Pin functions

Pin Name Pin function Description
1 CE Digital input Chip enable activates RX or TX mode
2 CSN Digital input SPI chip select
3 SCK Digital input SPI clock
4 MOSI Digital input SPI slave data input
5 MISO Digital output SPI slave data output, with a tri-state option
6 IRQ Digital output Maskable interrupt pin, active low
7 VDD Power Power supply (+1.9 up to +3.6V DC)
8 VSS Power Ground (0V)

 

STC Microcontroller

Features

  • Enhanced 80C52 Central Processing Unit,6T or 12T per machine cycle
  • Operation voltage range: 5.5V~3.3V (STC89C52RC/RD+ series) or 2.0V~ 3.6V (STC89LE52RC/RD+ series)
  • Operation frequency range: ~40MHz @ T, or ~80MHz T, the actual operation frequency can up to 48MHz
  • On-chip 4k/8k/13k/16k/32k/40k/48k/56k/61k FLASH program memory with flexible ISP/IAP capability
  • On-chip 1280 byte / 512 byte RAM
  • Be capable of addressing up to 64k bytes of external RAM
  • Be capable of addressing up to 64k bytes of external memory
  • Dual Data Pointer (DPTR) to speed up data movement
  • Three 16-bit timer/counter, Timer 2 is an up/down counter
  • 8 vector-address, 4-level priority interrupt capability
  • One enhanced UART with hardware address recognition, frame-error detection function, and with self-baud- rate generator.
  • One 15 bits Watch-Dog-Timer with 8-bit pre-scaler (one-time-enabled)
  • Two power management modes: idle mode and power-down mode
  • Low EMI: inhibit ALE emission
  • Power down mode can be woken-up by INT0/P3.2 pin, INT1/P3.3 pin, T0/P3.4, T1/P3.5, RXD/P3.0 pin, INT2/P4.3, INT3/P4.2
  • 39 or 35 programmable I/O ports are available
  • Four 8-bit bi-directional ports; extra four-bit additional P4 are available for PLCC-
  • Operating temperature: – + 85oC (industrial) / 0~75oC (commercial)
  • package type : LQFP-44, PDIP-40, PLCC-44

STC Microcontroller

MCU block diagram

The CPU core of the STC89C52RC/RD+ is fully compatible with standard microcontrollers, maintaining all the instruction mnemonics and binary compatibility. The STC89C52 RC/RD+ series is capable of executing the fastest instructions in either 6 or 12-clock cycles, with the performance improvement of specific programs varying based on the actual instructions used.

Recently, the STC series has been enhanced with 8052-core-based special-function microcontrollers. These improvements specifically target areas such as USB, I2C (two-wire interface), SPI, and CAN bus controllers, as well as MP3 decoders and hardware PWM capabilities.

MCU block diagram

MNEMONIC Pin Number DESCRIPTION
P0.0 ~ P0.7 39-32 Port0:Port0 is an 8-bit bi-directional I/O port without pull-up resistance. Except being as GPIO, Port 0 is also the multiplexed low- order address and data bus during accesses to external program and data memory. When P0 ports are as GPIO, they should be connected to 10K~4.7K pull-up resistors. When P0 ports are used as low 8-bit address bus [A0~A7] or data bus [D0~D7], they need not connect

pull-up resistor.

P1.0/T2 1 P1.0 common I/O port PORT1[0]
T2 Timer/Counter 2 external input pin
P1.1/T2EX 2 P1.1 common I/O PORT1[1]
T2EX Timer/Counter 2 trigger control of Capture/Reload

mode

P1.2 3 common I/O PORT1[2]
P1.3 4 common I/O PORT1[3]
P1.4 5 common I/O PORT1[4]
P1.5 6 common I/O PORT1[5]
P1.6 7 common I/O PORT1[6]
P1.7 8 common I/O PORT1[7]
P2.0 ~ P2.7 21-28 Port2 is an 8-bit bi-directional I/O port with pull-up resistance. Except being as GPIO, Port2 emits the high 8-bit address bus

(A8~A15) during accessing to external program and data memory

P3.0/RxD 10 P3.0 common I/O PORT3[0]
RxD Serial receive port
P3.1/TxD 11 P3.1 common I/O PORT3[1]
TxD Serial transmit port
P3.2/INT0 12 P3.2 common I/O PORT3[2]
INT0 External interrupt 0
P3.3/INT1 13 P3.3 common I/O PORT3[3]
INT1 External interrupt 1
P3.4/T0 14 P3.4 common I/O PORT3[4]
T0 \Timer/Counter 0 external input pin
P3.5/T1 15 P3.5 common I/O PORT3[5]
T1 \Timer/Counter 1 external input pin
P3.6/WR 16 P3.6 common I/O PORT3[6]
WR write pulse of external data memory
P3.7/RD 17 P3.7 common I/O PORT3[7]
RD read pulse of external data memory
PSEN 29 Program Store Enable is the read strobe to external program memory.
/ALE 33 Address Latch Enable input pin
EA 31 External Access Enable
RST 9 Reset pin
XTAL1 19 Input to the inverting oscillator amplifier and input to the internal
clock operating circuit.
XTAL2 18 Output from the inverting oscillator amplifier.
VCC 43 Power
GND 23 circuit ground potential

 

Oscillator Circuit

The on-chip oscillator circuit of the STC89C52RC features a single-stage inverter designed to function as a crystal-controlled, positive reactance oscillator. In this configuration, the crystal operates in its fundamental response mode as an inductive reactance in parallel resonance, along with an external capacitance

Oscillator Circuit

External clock drive configuration

parameter Symbol Min Max Unit
Supply voltage for logic VDD -0.3 7.0 V
Supply voltage for LCD VDD-VO -0.3 VDD+ 0.3 V
Input voltage VI -0.3 VDD+ 0.3 V
Operating temperature TOP 0 50 ºC
Storage temperature TST -10 60 ºC
parameter Symbol Condition Min Type Max Unit
Supply voltage for logic VDD 4.5 5.0 5.5 V
Supply current for logic IDD 2.02 4 mA
Operating voltage for LCD 1 VDD-VO 0 ºC 8.4 8.8 9.2 V
Operating voltage for LCD 2 VDD-VO 25 ºC 8.1 8.5 8.9 V
Operating voltage for LCD 3 VDD-VO 50 ºC 7.4 7.8 8.2 V
Supply voltage for sidelight VF 4.2 4.6 V
Supply current for sidelight IF VF=4.2V 180 300 mA
Input voltage H level VIH 0.7 VDD VDD V
Input voltage L level VIL 0 0.3 VDD V
Pin No. Symbol Level Description
1 VSS 0 V ground
2 VDD 5 V Supply voltage for logic
3 VO Input voltage for LCD
4 RS H/L H: data signal, L: instruction signal
5 R/W H/L H: read mode, L: write mode
6 E H, H—— L Chip enabale signal
7 DB0 H/L Data bit 0
8 DB1 H/L Data bit 1
9 DB2 H/L Data bit 2
10 DB3 H/L Data bit 3
11 DB4 H/L Data bit 4
12 DB5 H/L Data bit 5
13 DB6 H/L Data bit 6
14 DB7 H/L Data bit 7
15 CS1 H Chip select signal for KS0108B(1)
16 CS2 H Chip select signal for KS0108B(2)
17 RSTB L Reset signal
18 VUOT -5V Output voltage for LCD
19 SLA 4.2V Sidelight anode
20 SLK 0V Sidelight cathode

 Power Supply

A key goal of this project is to make the device portable for the user. As such, it cannot be directly connected to AC power. Instead, the device will be powered by a 9V battery. Considering the STC89C52 RC microcontroller, which requires a working voltage of 5V, a voltage regulator will be necessary. A voltage regulator is an electrical component designed to maintain a constant voltage output in a circuit. For this project, the LM7805 voltage regulator will be used to ensure a stable 5V output.

12864 LCD

12864 LCD

parameter Symbol Min Max Unit
Supply voltage for logic VDD -0.3 7.0 V
Supply voltage for LCD VDD-VO -0.3 VDD+ 0.3 V
Input voltage VI -0.3 VDD+ 0.3 V
Operating temperature TOP 0 50 ºC
Storage temperature TST -10 60 ºC
parameter Symbol Condition Min Type Max Unit
Supply voltage for logic VDD 4.5 5.0 5.5 V
Supply current for logic IDD 2.02 4 mA
Operating voltage for LCD 1 VDD-VO 0 ºC 8.4 8.8 9.2 V
Operating voltage for LCD 2 VDD-VO 25 ºC 8.1 8.5 8.9 V
Operating voltage for LCD 3 VDD-VO 50 ºC 7.4 7.8 8.2 V
Supply voltage for sidelight VF 4.2 4.6 V
Supply current for sidelight IF VF=4.2V 180 300 mA
Input voltage H level VIH 0.7 VDD VDD V
Input voltage L level VIL 0 0.3 VDD V
Pin No. Symbol Level Description
1 VSS 0 V ground
2 VDD 5 V Supply voltage for logic
3 VO Input voltage for LCD
4 RS H/L H: data signal, L: instruction signal
5 R/W H/L H: read mode, L: write mode
6 E H, H—— L Chip enabale signal
7 DB0 H/L Data bit 0
8 DB1 H/L Data bit 1
9 DB2 H/L Data bit 2
10 DB3 H/L Data bit 3
11 DB4 H/L Data bit 4
12 DB5 H/L Data bit 5
13 DB6 H/L Data bit 6
14 DB7 H/L Data bit 7
15 CS1 H Chip select signal for KS0108B(1)
16 CS2 H Chip select signal for KS0108B(2)
17 RSTB L Reset signal
18 VUOT -5V Output voltage for LCD
19 SLA 4.2V Sidelight anode
20 SLK 0V Sidelight cathode

Currently, the most prevalent LCDs available in the market are the 1 Line, 2 Line, or 4 Line types. These displays typically feature a single controller and support up to 80 characters. Conversely, LCDs that support more than 80 characters generally utilize two HD44780 controllers. In my project, I have employed a 12864 LCD to display the water level.

Light Emitting Diode (LED) and Buzzer

Light Emitting Diode (LED) and Buzzer

PCB Design of the system

transmitter module

SOFTWARE DEVELOPMENT

In this chapter, we will delve into the software development process of the wireless flood monitoring system. This includes the implementation and testing of all the programs using the prototype hardware that I have developed.

Software design

Software development commences once the hardware implementation nears completion. To verify the functionality of the hardware design, programming codes are necessary to test individual hardware modules. For example, specific programming code is written to solely test the LCD functionality. After finalizing the hardware design, comprehensive program instructions are planned, drafted, and programmed into the microcontroller.

Software-design

 

Micro Vision Keil (IDE)

Keil MicroVision is a type of no-cost software that addresses numerous challenges faced by embedded program developers. This software serves as an integrated development environment (IDE), incorporating a text editor for writing source codes and a compiler to convert these codes into hex files.

Here is a straightforward guide to begin using Keil MicroVision, which is suitable for:

  • Writing programs in C/C++ or Assembly language
  • Compiling and Assembling Programs
  • Debugging program
  • Creating Hex and Axf file
  • Testing your program without Available real Hardware (Simulator Mode)

Starting with Keil uVision4 is straightforward. Begin by accessing the Project tab and selecting “Create new uVision project.” Then, designate a new folder and name for the project. Finally, choose the appropriate device model.

4.2 Micro Vision Keil (IDE)

 

After that, proceed to the File menu and create a new file. Save it with the . C extension if you plan to write your code in the C language.

keil file

Lastly, to generate the HEX file that will be loaded onto the microcontroller, follow these steps: Right-click on the target and select “Options for target,” then ensure “Create Hex file” is checked. Next, right-click on the group and choose “Add files to source group” to include your C program file. Finally, click on “Build target.

HEX file

 

 create HEX file procedure

HEX file procedure on keil software

ISP programming

We offer a standardized programming download tool, allowing users to program the target system as described above. For this, you can connect an RS-232 level shifter to the computer to download the program. Programming the chip typically takes a few seconds less than using an ordinary universal programmer. The compilation process involves:

Step1: Select MCU type (E.g. STC89C5 RC)
Step2: Load user program code (*.bin or *.hex)
Setp3: Select the serial port you are using
Setp4: Configure the hardware option
Step 5: Press the ISP programming or Re-Programming button to download the user program.

ISP programming

The system flowchart

The-system-flowchart

 

The system code

The transmitter module code

#include <reg52.h>
#include <intrins.h>
#include <csd.h>
typedef unsigned char uchar;
typedef unsigned char uint;
sbit RX =P2^2;
sbit TX =P2^1;
bit flag =0;
unsigned int time=0;
sbit MISO =P1^2;
sbit MOSI =P3^2;
sbit SCK =P1^6;
sbit CE =P1^5;
sbit CSN =P1^7;
sbit IRQ =P1^3;
uchar seg[10]={0xC0,0xCF,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
//{
//0x01,0x02,0x03,0x4,0x05,0x06,0x07,0x08,
//0x09,0x10,0x11,0x12,0x13,0x14,0x15,0x16,
//0x17,0x18,0x19,0x20,0x21,0x22,0x23,0x24,
//0x25,0x26,0x27,0x28,0x29,0x30,0x ,
//}; //
//******************************************************************************
sbit KEY1=P3^6;
sbit KEY2=P3^7;
sbit led1=P2^1;
sbit led0=P2^0;
sbit led2=P2^2;
sbit led3=P2^3;
//*******************************************NRF24L01*************************************
#define TX_ADR_WIDTH 5 // 5 uints TX address width
#define RX_ADR_WIDTH 5 // 5 uints RX address width
#define TX_PLOAD_WIDTH 32 // 20 uints TX payload
#define RX_PLOAD_WIDTH 32 // 20 uints TX payload
uint const TX_ADDRESS[TX_ADR_WIDTH]= {0x34,0x43,0x10,0x10,0x01};
uint const RX_ADDRESS[RX_ADR_WIDTH]= {0x34,0x43,0x10,0x10,0x01};
#define READ_REG 0x00
#define WRITE_REG 0x20
#define RD_RX_PLOAD 0x61
#define WR_TX_PLOAD 0xA0
#define FLUSH_TX 0xE1
#define FLUSH_RX 0xE2
#define REUSE_TX_PL 0xE3
#define NOP 0xFF
#define CONFIG 0x00
#define EN_AA 0x01
#define EN_RXADDR 0x02
#define SETUP_AW 0x03
#define SETUP_RETR 0x04
#define RF_CH 0x05
#define RF_SETUP 0x06
#define STATUS 0x07
#define OBSERVE_TX 0x08
#define CD 0x09
#define RX_ADDR_P0 0x0A
#define RX_ADDR_P1 0x0B
#define RX_ADDR_P2 0x0C
#define RX_ADDR_P3 0x0D
#define RX_ADDR_P4 0x0E
#define RX_ADDR_P5 0x0F
#define TX_ADDR 0x10
#define RX_PW_P0 0x11
#define RX_PW_P1 0x12
#define RX_PW_P2 0x13
#define RX_PW_P3 0x14
#define RX_PW_P4 0x15
#define RX_PW_P5 0x16
#define FIFO_STATUS 0x17
void Delay(unsigned int s);
void inerDelay_us(unsigned char n);
void init_NRF24L01(void);
uint SPI_RW(uint uchar);
uchar SPI_Read(uchar reg);
void SetRX_Mode(void);
uint SPI_RW_Reg(uchar reg, uchar value);
uint SPI_Read_Buf(uchar reg, uchar *pBuf, uchar uchars);
uint SPI_Write_Buf(uchar reg, uchar *pBuf, uchar uchars);
unsigned char nRF24L01_RxPacket(unsigned char* rx_buf);
void nRF24L01_TxPacket(unsigned char * tx_buf);
//********************************************************************************
void Delay(unsigned int s)
{
unsigned int i;
for(i=0; i<s; i++);
for(i=0; i<s; i++);
}
uint bdata sta; //״̬±êÖ¾
sbit RX_DR =sta^6;
sbit TX_DS =sta^5;
sbit MAX_RT =sta^4;
void inerDelay_us(unsigned char n)
{
for(;n>0;n--)
_nop_();
}
void init_NRF24L01(void)
{
inerDelay_us(100);
CE=0; // chip enable
CSN=1; // Spi disable
SCK=0; // Spi clock line init high
SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH);
SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, RX_ADDRESS, RX_ADR_WIDTH);
SPI_RW_Reg(WRITE_REG + EN_AA, 0x01);
SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01);
SPI_RW_Reg(WRITE_REG + RF_CH, 0);
SPI_RW_Reg(WRITE_REG + RX_PW_P0, RX_PLOAD_WIDTH);
SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07);
//ÉèÖ÷¢ÉäËÙÂÊΪ1MHZ£¬·¢Éä ¦ÂÊΪ×î´óÖµ0dB
SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e)
uint SPI_RW(uint uchar)
{
uint bit_ctr;
for(bit_ctr=0;bit_ctr<8;bit_ctr++) // output 8-bit
{
MOSI = (uchar & 0x80); // output 'uchar', MSB to MOSI
uchar = (uchar << 1); // shift next bit into MSB..
SCK = 1; // Set SCK high..
uchar |= MISO; // capture current MISO bit
SCK = 0; // ..then set SCK low again
}
return(uchar); // return read uchar
}
uchar SPI_Read(uchar reg)
{
uchar reg_val;

CSN = 0; // CSN low, initialize SPI communication...
SPI_RW(reg); // Select register to read from..
reg_val = SPI_RW(0); // ..then read registervalue
CSN = 1; // CSN high, terminate SPI communication

return(reg_val); // return register value
}
uint SPI_RW_Reg(uchar reg, uchar value)
{
uint status;

CSN = 0; // CSN low, init SPI transaction
status = SPI_RW(reg); // select register
SPI_RW(value); // ..and write value to it..
CSN = 1; // CSN high again

return(status); // return nRF24L01 status uchar
}
uint SPI_Read_Buf(uchar reg, uchar *pBuf, uchar uchars)
{
uint status,uchar_ctr;

CSN = 0; // Set CSN low, init SPI tranaction
status = SPI_RW(reg); // Select register to write to and read status uchar

for(uchar_ctr=0;uchar_ctr<uchars;uchar_ctr++)
pBuf[uchar_ctr] = SPI_RW(0); //

CSN = 1;

return(status); // return nRF24L01 status uchar
}
uint SPI_Write_Buf(uchar reg, uchar *pBuf, uchar uchars)
{
uint status,uchar_ctr;

CSN = 0; //SPIÊ ÄÜ
status = SPI_RW(reg);
for(uchar_ctr=0; uchar_ctr<uchars; uchar_ctr++) //
SPI_RW(*pBuf++);
CSN = 1; // رÕSPI
return(status); //
void SetRX_Mode(void)
{
 CE=0;
 SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f);
 CE = 1;
 inerDelay_us(130);
}
unsigned char nRF24L01_RxPacket(unsigned char* rx_buf)
{
 unsigned char revale=0;
 sta=SPI_Read(STATUS);
 if(RX_DR)
 {
 CE = 0;
SPI_Read_Buf(RD_RX_PLOAD,rx_buf,TX_PLOAD_WIDTH); // read receive payload from RX_FIFO buffer
 revale =1;
 }
 SPI_RW_Reg(WRITE_REG+STATUS,sta);
 return revale;
}
void nRF24L01_TxPacket(unsigned char * tx_buf)
{
 CE=0;
 SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH);
 SPI_Write_Buf(WR_TX_PLOAD, tx_buf, TX_PLOAD_WIDTH);
// SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e);
 CE=1;
 inerDelay_us(10);
}
void delayms (unsigned int t) {
unsigned int i;
 while(t--){
 for(i=0;i<125;i++);
 }
}
void StartModule(void) {
 TX=1;
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 _nop_();
 TX=0;
 }
void Conut(void){
 unsigned int S,SS;
 SS=85;
 time=TH0*256+TL0;
 TH0=0;
 TL0=0;
 S=time*1.87/100;
 if (flag==1){
 flag=0;
 //Display (1,1,dist);
 } else {
 disbuff[1]=S%1000/100;
 disbuff[2]=S%1000%100/10;
 disbuff[3]=S%1000%10 %10;
 }
}
void main(void)
{
 uchar temp =0;
 init_NRF24L01() ;
 led0=0;led1=0;led2=0;led3=0;
 TMOD=0x01;
 TH0=0;
 TL0=0;
 TR0=0;
 P0=0x00;
 nRF24L01_TxPacket(disbuff); // Transmit Tx buffer data
 Delay(6000);
 P0=0xBF;
 while(1)
 {
 StartModule();
// sp=0;
 while(!RX);
 TR0=1;
 while(RX);
 TR0=0;
 Conut();
 delayms(80); //80MS
 if(temp==3)
 {
 temp=0;
 }
 nRF24L01_TxPacket(disbuff); // Transmit Tx buffer data
 Delay(200);
 SPI_RW_Reg(WRITE_REG+STATUS,0XFF);
 temp++;
 }
}
void zd0() interrupt 1
{
 flag=1;
 TH0=0;
 TL0=0;
 TR0=0;
}

The receiver module code

#include 
#include 
#include 
#include 
typedef unsigned char uchar;
typedef unsigned char uint;
#define u16 unsigned int
#define u8 unsigned char
sbit led_red=P3^5;
sbit led_yellow=P3^6;
sbit led_green=P3^7;
sbit buzzer=P3^4;
unsigned char code s[]={"dist meter"};
unsigned char code nc[]={"done by bake"};
unsigned char code kc[]={"dist is:"};
unsigned char code dist[] ={"distance over"};
unsigned char code num[]={"0123456789 :.-"};
unsigned char code CM[] = {"CM"};
//****************************************************************************
sbit MISO =P1^2;
sbit MOSI =P3^2;
sbit SCK =P1^6;
sbit CE =P1^5;
sbit CSN =P1^7;
sbit IRQ =P1^3;
sbit KEY1=P3^6;
sbit KEY2=P3^7;
//******************************************NRF24L01*************************************
#define TX_ADR_WIDTH 5 // 5 uints TX address width
#define RX_ADR_WIDTH 5 // 5 uints RX address width
#define TX_PLOAD_WIDTH 32 // 20 uints TX payload
#define RX_PLOAD_WIDTH 32 // 20 uints TX payload
uint const TX_ADDRESS[TX_ADR_WIDTH]= {0x34,0x43,0x10,0x10,0x01};
uint const RX_ADDRESS[RX_ADR_WIDTH]= {0x34,0x43,0x10,0x10,0x01};
//***************************************
#define READ_REG 0x00
#define WRITE_REG 0x20
#define RD_RX_PLOAD 0x61
#define WR_TX_PLOAD 0xA0
#define FLUSH_TX 0xE1
#define FLUSH_RX 0xE2
#define REUSE_TX_PL 0xE3
#define NOP 0xFF
#define CONFIG 0x00
#define EN_AA 0x01
#define EN_RXADDR 0x02
#define SETUP_AW 0x03
#define SETUP_RETR 0x04
#define RF_CH 0x05
#define RF_SETUP 0x06
#define STATUS 0x07
#define OBSERVE_TX 0x08
#define CD 0x09
#define RX_ADDR_P0 0x0A 
#define RX_ADDR_P2 0x0C
#define RX_ADDR_P3 0x0D
#define RX_ADDR_P4 0x0E
#define RX_ADDR_P5 0x0F
#define TX_ADDR 0x10
#define RX_PW_P0 0x11
#define RX_PW_P1 0x12
#define RX_PW_P2 0x13
#define RX_PW_P3 0x14
#define RX_PW_P4 0x15
#define RX_PW_P5 0x16
#define FIFO_STATUS 0x17
void Delay(unsigned int s);
void inerDelay_us(unsigned char n);
void init_NRF24L01(void);
uint SPI_RW(uint uchar);
uchar SPI_Read(uchar reg);
void SetRX_Mode(void);
uint SPI_RW_Reg(uchar reg, uchar value);
uint SPI_Read_Buf(uchar reg, uchar *pBuf, uchar uchars);
uint SPI_Write_Buf(uchar reg, uchar *pBuf, uchar uchars);
unsigned char nRF24L01_RxPacket(unsigned char* rx_buf);
void nRF24L01_TxPacket(unsigned char * tx_buf);
//******************************************************************************
void Delay(unsigned int s)
{
 unsigned int i;
 for(i=0; i<s; i++);
 for(i=0; i<s; i++); } uint bdata sta; //״̬±êÖ¾ sbit RX_DR =sta^6; sbit TX_DS =sta^5; sbit MAX_RT =sta^4; void inerDelay_us(unsigned char n) { for(;n>0;n--)
 _nop_();
}
void init_NRF24L01(void)
{
 inerDelay_us(100);
 CE=0; // chip enable
 CSN=1; // Spi disable
 SCK=0; // Spi clock line init high
 SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH);
 SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, RX_ADDRESS, RX_ADR_WIDTH);
 SPI_RW_Reg(WRITE_REG + EN_AA, 0x01);
 SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01);
 SPI_RW_Reg(WRITE_REG + RF_CH, 0);
 SPI_RW_Reg(WRITE_REG + RX_PW_P0, RX_PLOAD_WIDTH);
 SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07);
 SPI_RW_Reg(WRITE_REG + CONFIG, 0x0f);
}
uint SPI_RW(uint uchar)
{
 uint bit_ctr;
 for(bit_ctr=0;bit_ctr<8;bit_ctr++) // output 8-bit
 {
MOSI = (uchar & 0x80); // output 'uchar', MSB to MOSI
 uchar = (uchar << 1); // shift next bit into MSB..
 SCK = 1; // Set SCK high..
 uchar |= MISO; // capture current MISO bit
 SCK = 0; // ..then set SCK low again
 }
 return(uchar); // return read uchar
}
uchar SPI_Read(uchar reg)
{
 uchar reg_val;

 CSN = 0; // CSN low, initialize SPI communication...
 SPI_RW(reg); // Select register to read from..
 reg_val = SPI_RW(0); // ..then read registervalue
 CSN = 1; // CSN high, terminate SPI communication

 return(reg_val); // return register value
}
uint SPI_RW_Reg(uchar reg, uchar value)
{
 uint status;

 CSN = 0; // CSN low, init SPI transaction
 status = SPI_RW(reg); // select register
 SPI_RW(value); // ..and write value to it..
 CSN = 1; // CSN high again

 return(status); // return nRF24L01 status uchar
}
uint SPI_Read_Buf(uchar reg, uchar *pBuf, uchar uchars)
{
 uint status,uchar_ctr;

 CSN = 0; // Set CSN low, init SPI tranaction
 status = SPI_RW(reg); // Select register to write to and read status uchar

 for(uchar_ctr=0;uchar_ctr<uchars;uchar_ctr++)
 pBuf[uchar_ctr] = SPI_RW(0); //

 CSN = 1;

 return(status); // return nRF24L01 status uchar
}
uint SPI_Write_Buf(uchar reg, uchar *pBuf, uchar uchars)
{
 uint status,uchar_ctr;

 CSN = 0; //SPIÊ ÄÜ
 status = SPI_RW(reg);
 for(uchar_ctr=0; uchar_ctr<uchars; uchar_ctr++) //
 SPI_RW(*pBuf++);
 CSN = 1; // رÕSPI
 return(status); //
}
void SetRX_Mode(void)
{
 CE=0;
 CE = 1;
 inerDelay_us(130);
}
unsigned char nRF24L01_RxPacket(unsigned char* rx_buf)
{
 unsigned char revale=0;
 sta=SPI_Read(STATUS);
 if(RX_DR)
 {
 CE = 0;
 SPI_Read_Buf(RD_RX_PLOAD,rx_buf,TX_PLOAD_WIDTH);
 revale =1;
 }
 SPI_RW_Reg(WRITE_REG+STATUS,sta);
void nRF24L01_TxPacket(unsigned char * tx_buf)
{
 CE=0;
 SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH);
 SPI_Write_Buf(WR_TX_PLOAD, tx_buf, TX_PLOAD_WIDTH);
 SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e);
 CE=1;
 inerDelay_us(10);
}
void main(void)
{
 u8 RxBuf[5]={0,0,0,0,0};
 unsigned int S;
 init_NRF24L01() ;
 LCD_Init(); Delay(6000);
 Display (0, 2, s);
 Display (1, 0, nc);
 Display (2, 0, kc);
 while(1)
 {
 SetRX_Mode();
 if(nRF24L01_RxPacket(RxBuf))
 {
 LCD_Locate( 2, 4 );
 LCD_WriteData(0x30+RxBuf[1]);
 LCD_WriteData(0x30+RxBuf[2]);
 LCD_WriteData(0x30+RxBuf[3]);
 LCD_WriteData(CM[0]);
 LCD_WriteData(CM[1]);
 }
 //Send_sfm1(3,S);
 //S = atoi(RxBuf+1);
 S = RxBuf[1]*100+ RxBuf[2]*10+RxBuf[3];
 if((2<=S)&&(S<20))
 {
 led_red=0;
 led_green=1;
 led_yellow=1;
 buzzer=0;
 }
 if((20<=S)&&(S<80))
 {
 led_red=1;
 led_green=1;
 led_yellow=0;
 buzzer= 
}
 if((80<=S)&&(S<100))
 {
 led_red=1;
 led_green=0;
 led_yellow=1;
 buzzer=1;
 }
 if(100<S)
 {
 led_red=1;
 led_green=0;
 led_yellow=1;
 buzzer=1;
 }
 }

The LCD code

#include 
#include 
#include "LCD12864.H"
sbit LCD_RS = P2^2;
sbit LCD_RW = P2^1;
sbit LCD_EN = P2^0;
sbit LCD_PSB = P2^3;
void LCD_Wait(void)
{
 LCD_DATA_PORT=0xff;
 LCD_RS=0;
 LCD_RW=1;
 LCD_EN=1;
 _nop_();
 while( LCD_DATA_PORT&0x80 );
 LCD_EN=0;
}
void LCD_WriteCommand(unsigned char content)
{
 LCD_Wait();
 LCD_RS=0;
 LCD_RW=0;
 LCD_DATA_PORT=content;
 _nop_();
 LCD_EN=1;
 _nop_();
 LCD_EN=0;
}
void LCD_WriteData(unsigned char content)
{
 LCD_Wait();
 LCD_RS=1;
 LCD_RW=0;
 LCD_DATA_PORT=content;
 _nop_();
 LCD_EN=1;
 _nop_();
 LCD_EN=0;
}
unsigned char LCD_ReadData(void)
{
 unsigned char dat=0;
 LCD_Wait();
 LCD_DATA_PORT=0xff;
 LCD_RS=1;
 LCD_RW=1;
 LCD_EN=0;
 LCD_EN=1;
 _nop_();
 dat=LCD_DATA_PORT;
 LCD_EN=0;
 return dat;
}
void LCD_Init(void)
{
 unsigned char i=0xff;
 LCD_PSB=1;
 while(i--);
 LCD_WriteCommand ( 0x30 );
 LCD_WriteCommand ( 0x30 );
 LCD_WriteCommand ( 0x0c );
 LCD_WriteCommand ( 0x06 );
 LCD_WriteCommand ( 0x01 );
}
void Display (unsigned char x, unsigned char y, unsigned char *s) {
 if (x == 0)
 x=0x80;
 else if(x==1)
 x=0x90;
 else if(x==2)
 x=0x88;
 else if(x==3)
 x=0x98;
 LCD_WriteCommand(x+y); //дµØÖ· addr_tab[8*x+y]
 while(*s>0){
 LCD_WriteData(*s);
 s++;
 }
}
void LCD_Clear(void)
{
 LCD_WriteCommand(0x01);
}
void LCD_Locate(unsigned char y,unsigned char x)
{
 switch( y ){
 case 0 :
 LCD_WriteCommand ( 0x80+x );
 break;
 case 1 :
 LCD_WriteCommand ( 0x90+x );
 break;
 case 2 :
 LCD_WriteCommand ( 0x88+x );
 break;
 case 3 :
 LCD_WriteCommand ( 0x98+x );
 break;
default :
 break;
 }
}
void LCD_PutString(unsigned char *ptr)
{
 while(*ptr != ' )
 {
 LCD_WriteData(*ptr++);
 }
}
void LCD_PutString_Add(unsigned char y,unsigned char x,unsigned char *ptr)
{
 LCD_Locate(y,x);
 LCD_PutString(ptr);
}
void LCD_ClearScreen(void)
{
 unsigned char i;
 unsigned char j;

 LCD_WriteCommand( 0x34 );
 LCD_WriteCommand( 0x36 );

 for(j=0;j<64;j++)
 {
 LCD_WriteCommand( 0x80+j ) ; //y
 LCD_WriteCommand( 0x80 ) ; //x
 for(i=0;i<16;i++)
 {
 LCD_WriteData( 0x00 ) ;
 LCD_WriteData( 0x00 ) ;
 }
 }
 LCD_WriteCommand( 0x36 );
void LCD_huitu(unsigned char *bmp){
 unsigned char i;
 unsigned char j;
 LCD_WriteCommand( 0x34 );
 LCD_WriteCommand( 0x36 );
 for(j=0;j<6;j++)
 {
 LCD_WriteCommand( 0x80+j ) ; //y
 LCD_WriteCommand( 0x80 ) ; //x
 for(i=0;i<1;i++) { //LCD_WriteData( 0x00 ) ; LCD_WriteData( *bmp++ ) ; } LCD_WriteCommand( 0x36 ); } } void LCD_DrawPixel(unsigned char x, unsigned char y, unsigned char Color) { unsigned char Row , Tier , Tier_bit ; unsigned char temp_h, temp_l ; if((x>127)||(y>63))
 {
 return ;
 }
 LCD_WriteCommand( 0x34 ) ;
LCD_WriteCommand( 0x36 ) ;
 Tier = x>>4;
 Tier_bit = x&0x0f;
 if(y < 32)
 {
 Row = y;
 }
 else
 {
 Row = y -
 Tier += 8 ;
 }
 LCD_WriteCommand( Row + 0x80 ) ;
 LCD_WriteCommand( Tier + 0x80 ) ;
 LCD_ReadData() ;
 temp_h = LCD_ReadData() ;
 temp_l = LCD_ReadData() ;
 LCD_WriteCommand( Row + 0x80 ) ;
 LCD_WriteCommand( Tier + 0x80 ) ;
 if( Tier_bit < 8 )
 {
 switch( Color)
 {
 case 0 : temp_h &=( ~( 0x01 << ( 7 - Tier_bit ))) ; break ;
 case 1 : temp_h |= ( 0x01 << ( 7 - Tier_bit )) ; break ;
 case 2 : temp_h ^= ( 0x01 << ( 7 - Tier_bit )) ; break ;
 default : break ;
 }
 }
 else
 {
 switch(Color)
 {
 case 0 : temp_l &= (~( 0x01 << ( 15 - Tier_bit ))) ; break ;
 case 1 : temp_l |= ( 0x01 << ( 15 - Tier_bit )) ; break ;
 case 2 : temp_l ^= ( 0x01 << ( 15 - Tier_bit )) ; break ; default : break ; } } LCD_WriteData( temp_h ) ; LCD_WriteData( temp_l ) ; LCD_WriteCommand( 0x30 ) ; void LCD_DrawLine_X(unsigned char y0, unsigned char x0, unsigned char x1, unsigned char fColor) { unsigned char n; if(x0 > x1)
 {
 n = x1;
 x1 = x0;
 x0 = n;
 }
 if(fColor==2)
 {
 for(n=x0; n <= x1; n++)
 {
 if(n%2==0)
 {
 LCD_DrawPixel(n, y0, 0);
 }
else
 {
 LCD_DrawPixel(n, y0, 1);
 }
 else
 {
 for(n=x0; n <= x1; n++) { LCD_DrawPixel(n, y0, fColor); } void LCD_DrawLine_X_t(unsigned char y ,unsigned char x0, unsigned char x1 ,unsigned char clour ) { unsigned char temp; if(x0>x1) {
 temp=x1;
 x1=x0;
 x0=temp;
 }
 for(; x0<x1; x0++) { if((x0%2)!=0) LCD_DrawPixel(x0 ,y ,clour); } } void LCD_DrawLine_Y(unsigned char x0, unsigned char y0, unsigned char y1, unsigned char fColor) { unsigned char n; if(y0 > y1)
 {
 n = y1;
 y1 = y0;
 y0 = n;
 }
 if(fColor==2)
 {
 for(n=y0; n <= y1; n++)
 {
 if(n%2==0)
 {
 LCD_DrawPixel(x0, n, 1);
 }
 else
 {
 LCD_DrawPixel(x0, n, 0);
 }
 }
 }
 else
 {
 for(n=y0; n <= y1; n++) { LCD_DrawPixel(x0, n, fColor); } void LCD_DrawLine(unsigned char x0, unsigned char y0, unsigned char x1, unsigned char y1, unsigned char Color ) { unsigned char t, distance; unsigned char x=0, y=0; char delta_x, delta_y ; char incx, incy; if((x0>127)||(x1>127)||(y0>63)||(y1>63))
{
 return ;
 }
 delta_x = x1 - x0;
 delta_y = y1 - y0;
 if(delta_x > 0)
 {
 incx = 1;
 }
 else if(delta_x == 0)
 {
 LCD_DrawLine_Y(x0, y0, y1, Color);
 return;
 }
 else
 {
 delta_x = -delta_x;
 incx = -
 }
 if(delta_y > 0)
 {
 incy = 1;
 }
 else if(delta_y == 0)
 {
 LCD_DrawLine_X(y0, x0, x1, Color);
 return;
 }
 else
 {
 delta_y = -delta_y;
 incy = -
 }
 if(delta_x > delta_y)
 {
 distance = delta_x ;
 }
 else
 {
 distance = delta_y ;
 }
 for(t=0; t <= distance+1; t++ ) { LCD_DrawPixel(x0, y0, Color) ; x += delta_x ; y += delta_y ; if(x > distance)
 {
 x -= distance ;
 x0 += incx ;
 }
 if(y > distance)
 {
 y -= distance ;
 y0 += incy ;
 }
}

The System Integration

The System Integration

 

Receiver module prototype

The System testing and results

Case 1, if the water level is within the safe range, the LED designated with the color green will be turned on.

Case 1 water level is at the safe level

Case 2, if the water level is at a medium level, the LED assigned the color yellow will be turned on.

Case 2 water level is at the medium level

Case 3, if the water level reaches a risky level, the LED designated with the color red will be turned on, and the buzzer will be activated.

Case 3 water level is at the risky level

CONCLUSIONS AND FUTURE WORK

CONCLUSIONS

I have completed the project on time and met all the project objectives. This experience has enhanced my hardware design skills, programming skills, and planning abilities. I am confident that the knowledge and experience gained from this project will be valuable in my future career.

FUTURE WORK

This system has great potential for further improvement to enhance its performance. Here are some suggestions for future work:

  • The better radio frequency module can be used, to reach longer distances.
  • This tool can be developed to measure water depth using other types of ultrasonic sensors such as SRF02 or SRF.
  • Better display applications can be developed for example by displaying time series data in graphic form.
  • The better receiver module can be developed to receive the water level data from multiple transmitter modules.

Follow this link for complete project: Building a Real-Time Wireless Flood Monitoring System with HC-SR04 and AVR ATmega


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top