Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

PARKED VEHICLE MONITOR

By Fayaz Hassan September 17, 2020

Nowadays most of the people have cars for daily commuting, thanks to easily available loans with variety of instalment options. With explosive growth of sales in auto sector, traffic management and parking are now two major problems especially in metropolitan cities. Leave aside the traffic problem, parking has become a great issue whether at office premises or home. One may not always find place at a parking spot and may need to manage by parking the car anywhere space available. This has lead to another problem of car theft. One’s car remains safe in a parking lot, but when parked to some distant spot, it is all vulnerable to be damaged or stolen by mischievous elements. There comes central locking system, but it only protects one’s precious vehicle from theft and not any intentional damage.

In this project, an ATMega8 based Car Anti Theft and Security System has been designed which can be installed along with the Central Locking Systems. The embedded system designed in this project equips the user with a remote car monitoring device which by default work as a digital clock and is capable of alerting the user if any mischievous element tries to damage car, try to break into doors or is somehow able to self-start the car illicitly.

The system involves two embedded device, one which has to be installed in car and other a digital clock which is at the same time a car security alert system. Both devices are built on ATMega8 microcontroller. The installable system has been designed by interfacing GY-61 Accelerometer module which can detect any jerks to the car and HC-12 Bluetooth module that makes possible communicating alert messages to remote digital clock cum car security system.  The remote monitor system is built by interfacing RTC-DS1307 and 16×2 character LCD to display alert messages otherwise current date and time. The monitoring device too communicates with the  installed embedded system via HC-12 Bluetooth module.

In-Car Embedded Device for Car Anti Theft and Security

Fig. 1: Prototype of In-Car Embedded Device for Car Anti Theft and Security

Both devices have been designed on AVR ATMega8 microcontrollers and are programmed using embedded C. The code has been written, compiled and burnt to the respective systems using AVR Studio.

Remote Car Status Monitoring Cum Real Time Digital Clock Device
Fig. 2: Prototype of Remote Car Status Monitoring Cum Real Time Digital Clock Device
Component Required –
Block diagram –
Block Diagram of AVR ATmega8 based Car Anti Theft and Security System
Fig. 3 : Block Diagram of AVR ATmega8 based Car Anti Theft and Security System
Prerequisite Skills –
Before trying this project, the developer must have the following prerequisite skills-
1) The Developer must have basic knowledge of AVR microcontroller.
2) The developer must be familiar with programming in AVR Studio 4.
3) The developer must know how to interface 16×2 LCD display with AVR.
4) The developer must know how to interface RTC with AVR.
Circuit Connections –  
This system involves two embedded devices – one, in-car installation device and second, remote monitoring device. The in-car installation device is equipped with sensors to detect any car break incident and keeps updating the real time alert messages to the remote monitoring device every 500 milliseconds via Bluetooth. The remote monitoring device has been designed as a digital clock which keeps reminding the in-car installation device to update status and if there is any alert, it flash the alert on its display screen.
Car Anti-Theft System on a breadboard
Fig. 4: Image of Car Anti-Theft System on a breadboard
The in-car installation device has been designed by making the following circuit connections –
1) AVR ATmega8 – Atmega8 is a 8-bit AVR microcontroller with 23 I/O pins. It is interfaced with GY-61 accelerometer sensor and HC-12 Bluetooth module in the circuit of this project.
2) GY-61 (ADXL335) Accelerometer module – GY-61 is a 3–axis accelerometer module. It is interfaced with controller to sense any vibrations to the car. The module comes with 5 terminals – VCC, GND, X-Axis, Y-Axis and Z-Axis. The VCC pin of GY-61 module is connected with the 5V power supply and GND pin is connected to the common ground. The X pin of GY-61 is connected with 23rd pin of ATmega8 which is ADC channel 0 of the microcontroller. The Y pin of GY-61 is connected with 24th pin of ATmega8 which is ADC channel 1 of the microcontroller and the Z pin of GY-61 is connected with 25th pin of ATmega8 which is ADC channel 2 of the microcontroller.
3) HC-12 Module – HC-12 is a wireless Bluetooth serial port communication module. It is used to transmit the data from in-car installation device to the remote monitoring device. The module has 5 terminals – VCC, GND, Rx, Tx and SET. The VCC pin of HC-12 is connected to the 5V DC and the GND pin of HC-12 is connected to the common ground. The TX pin of HC-12 is connected with 2nd pin of ATmega8, RX pin of HC-12 is connected with 3rd pin of ATmega8 and SET pin of HC-12 module is connected with 4th pin of ATmega8.
4) Optional Connections – Apart from these connections, the in-car installation device can be wired to utilize three more ADC channels of the ATMega8 microcontroller. Already three ADC channels are in use to read data from the GY-61 accelerometer sensor. One ADC channel can be used to record change in voltage due to self-start of the car. Two ADC channels can be optionally used to connect with the ignition key switch/relay and door lock system.
5) Power Supply – The in-car installation device can be powered by the car battery. The battery voltage will need to be regulated to 5V DC using a voltage regulator IC like 7805.
The Remote Monitoring Device has been designed by making the following circuit connections –
1) AVR ATmega8 – The same microcontroller AVR ATMega8 is used on the remote monitoring device. In the remote monitoring device, the controller is interfaced with 16×2 Character LCD, HC-12 Bluetooth  module and RTC DS1307 in the circuit of this project.
2) 16×2 LCD display – A character LCD is interfaced with the controller to display current Date-time and the status of the vehicle. The VSS/GND and LED pins of LCD module are connected to the ground and VCC and LED+ pins of LCD are connected to the 5V DC. The VEE pin of LCD is connected to a 5k trimpot. The EN pin of LCD is connected to the pin 16 of ATmega8 and RS pin is connected to the 15 pin of ATmega8. The RW pin of LCD is connected to the ground. The LCD is interfaced in 4-bit mode. So, the data pins D4, D5, D6 and D7 are connected to the pins 26, 25, 24 and 23 of ATmega8 respectively.
3) RTC DS1307 – RTC DS1307 is a Real Time Clock which is interfaced with the AVR ATmega8 to show the current time and date by default on the display. The 8th pin of DS1307 is connected to 5V DC and 4th pin is connected to the ground. The 1st and 2nd pins are connected to the external crystal oscillator. The 3rd pin of DS1307 is connected to the positive terminal of a 3V battery and 4th pin connected to the negative terminal of a 3V battery. The 7th pin of DS1307 is connected with negative terminal of an LED while the positive terminal of the same LED is connected to the 5V DC via a pull-up resistor. The 5th and 6th pin of DS1307 is connected to the 27th and 28th pin of ATmega8 microcontroller.
4) BC548 transistor – BC548 is an NPN transistor which is used to drive buzzer on signal from AVR microcontroller. The base terminal of the transistor is connected to the 14th pin of ATmega8. The collector terminal is connected to the buzzer and the emitter terminal is grounded.
5) HC-12 Module – The same Wireless Bluetooth Serial port communication module is used to on remote monitoring device for communication of alert messages with the in-car installation device. The VCC pin of HC-12 is connected to the 5V DC and the GND pin of HC-12 is connected to the ground. The TX pin of HC-12 is connected with 2nd pin of ATmega8, RX pin of HC-12 is connected with 3rd pin of ATmega8 and SET pin of HC-12 module is connected with 4th pin of the ATmega8 microcontroller.
How the circuit works – 
The operation of this system can be understood by what both wirelessly communicating embedded devices do. The role and functioning of both the devices has been described below –
In-Car Installation Device – When the controller on in-car device is powered on by a 5V DC supply, the Red and green LED start glowing for a while and stops. Finally, only Red LED glows for a while, which is an indication that the device is checking HC-12 module and reading analog voltages from the accelerometer module at ADC pins (ADC0 to ADC5). Once checked that Bluetooth module is operating fine and analog data from accelerometer sensor is properly received, the Red LED stops glowing. The Green LED blinks continuously, which indicates that the microcontroller is checking the status of all ADC channels every 500 milliseconds. If Red LED glows continuously, it indicates that there is some communication problem with HC-12 module. If Red LED starts blinking, then it indicates that one or more ADC channel is reading change in voltage either due to vibration or power-supply fluctuations. Once the request for status is received from the remote monitoring device, the Red LED stops. So, the Red LED is used as Error indicator and Green LED is used as blinker.
Remote Monitoring Device – The remote monitoring device by default act as real-time digital clock while it flash any alert message and starts buzzer when received appropriate message from the in-car device. When the controller on remote monitoring device is powered on by a 5V DC supply, initially all LEDs interfaced to it glow for a while and buzzer generates a small beep sound. After this, the LCD displays a Welcome massage and checks for communication from HC-12 module and connection with DS1307 RTC module. If there is an error in communication via HC-12 module or DS1307, it shows an error message on the display LCD. If all connections are Ok then it starts displaying current time and date on the LCD. The device keeps on sending “?” character to the in-car device as a request for status every 500 milliseconds and waits for the reply. If the Reply from in-car device contains any alert message, the buzzer is sent a PWM signal to make a  beep sound and LCD display flashes the alert message. To stop the beep sound, user needs to press S1 switch, which sets the microcontroller for next monitoring cycle. If the DS1307 RTC is not connected then it should be short via Jumper J1, which by-pass the RTC and display a formal message “HAVE A NICE DAY” on the LCD.
The time and date on remote monitoring device can be updated by using S2 and S3 buttons. When S2 button is pressed, the device enters into the edit mode. The S3 button can be used for changing the value of selected parameter after which S2 button can be used for selection of parameter which needs to be changed. Once the time and date are updated then user should leave the device for 5 seconds. After 5 seconds, the time and date are saved into the DS1307 RTC and current date/time are displayed on the LCD.
The in-car device can communicate the following alert messages to the remote monitoring device –
1) “NO SIGNAL. CHECK VEHICLE & BOARD” – This message means that either the vehicle is out of signal range (theft) or in-car device is not responding due to shortage of power-supply.  So, user needs to immediately check the vehicle and board power-supply from the battery.
2) “JERKS/VIBRATIONS/ENGINE/KEY USED” – This message means that the ADC inputs of the in-car device observed some changes in its signal voltages either from GY-61 or Engine start or Door Open etc. So, the user’s vehicle may be under threat and user should  immediately take a check.
3) “WEAK SIGNAL OR LONG DISTANCE” – This message means that the coded signal is received by the in-car device but it has incorrect values.  So, user needs to park the vehicle a bit nearer to get rid of poor signals and properly communicate status messages.
4)  “DATE and TIME” or display “HAVE A NICE DAY” – These messages means that no error is observed and the vehicle is in safe condition.
Date-Time displayed on Car Anti-Theft System
Fig. 5: Image of Date-Time displayed on Car Anti-Theft System
Fig. 6: Alert Message displayed on Car Anti-Theft System
Precautions –
The installation of in-car device essentially involves the following precautions –
1) The device fit on the vehicle must be installed at such place in it that it remains safe from over-heat of the engine,  spillage of water etc.For this, the in-car installation can be sealed in a plastic enclosure or casing.
2) The user should take help of an expert mechanic for connecting Signal Inputs 1 and 2, which are optional sensor connections for door open indicator and ignition key indicator. These connections can only be made by an expert mechanic.
Programming Guide –
Both circuits are based on AVR ATmega8. The AVR is programmed in embedded C using AVR Studio 4 or it can be programmed via other programming tools like Atmel Studio or Notepad++ which can also be used to write and compile the code. First of all, the user needs to add necessary library files attached below in a zip file then, copy and paste the code in AVR Studio 4 to generate hex file. On in-car device, the ATmega8 is used for sensing the vibration via GY-61 and the sensed data on ADC is sent to the remote monitoring device via HC-12 Bluetooth module. The remote monitoring device by default displays current date and time otherwise displays any alert message from the in-car installation on a character LCD.
The AVR code of the in-car device has the following breakdown –
Constants Used in the code:-
#define F_CPU 1000000UL :- Constant used to define clock frequency of MCU
#define FCPU_BY_100 F_CPU/100 :-Frequency Divided by 100 for baud rate calculation
#define ADCAVGDIFF 100 :- used to determine the ADC value change
#define ADCEXTREMEDIFF 50 :- used to determine the ADC value change
#define BLINKER_LED 0b00100000 :- blinker LED connected to the pin 5 of Port D
#define ERROR_LED 0b00100000 :- Error LED connected to the pin 5 of Port B
#define HC12_SET 0b00000100 :-SET pin of HC-12 is connected to the pin 2 of port D
#define ON  1 :- To turn on LED
#define OFF 0 :-To turn off LED
#define TOGGLE 2 :-To Blink LED
#define USART_MAX_RECV_BUF_SIZE 10 :- Maximum size of received data
Variable used in code:-
uint8_t isHC12ERROR=0 :- check error in HC-12 communication
uint8_t USART_RECD_DATA_POS=0 :- the position of buffer array
uint8_t isUSARTQUERY=0 :- if RX requested for Query
uint8_t USART_RXD = 0 :- To store Received Data
int ADCHIVALUE[6]={0 , 0 , 0 , 0 , 0 , 0} :- To set the ADC default value
int ADCLOVALUE[6]={1024,1024,1024,1024,1024,1024} :- To set the ADC default value
int ADCVALUE[6] :- To store ADC values
int ADCAVGVALUE[6] :- the average value of ADC
uint8_t ADC_ERROR_CODE=0 :-Used To send code to RX if change in ADC value
Header file and libraries used in the code:-
#include <avr/io.h> :- Standard AVR header for input/output
#include <util/delay.h> :-Standard AVR header to provide time delays
#include <avr/interrupt.h> :-Standard AVR header for interrupts
Function used in the code :-
initPorts :-initialize port as input and output
initAdc :-initialized ADC
readAdc :-Read the value from channels
USART_init :-initialize UART communication
HC12_sendChar :- send character to HC-12
HC12_sendString :-send string to HC-12
HC12_sendCommand :-send commands to HC-12
HC12_start :- verify the communication of HC-12
setBlinker :-control the blinker LED
setError :-control the error LED
sendStatus :-send status of ADC channels
readAdcValues :-Read ADC value from all channel
setAdcValues :-set the default ADC values
checkAdcValues :-check if there is change in ADC value
sei() :- enable interrupts
Algorithm :-
1) Initially, in the main program, the port is initialized for input and output, then the blinker LED and error LED turn on for a while and both get turned off. After this UART initialized to start communication.
_delay_ms  ( 100 );
initPorts ( );
_delay_ms  ( 10 );
setBlinker ( ON );
setError   ( ON );
_delay_ms  ( 500 );
setBlinker ( OFF );
setError   ( OFF );
USART_init ( );
_delay_ms  ( 100 );
2) The ADC is initialized and the error LED is turned on, then a function is used to set the default ADC values. After this Error LED turns off. The “sei()” function is used to enable the interrupts. After this the communication via HC-12 is verified and initiated.
initAdc ( );
_delay_ms  ( 100 );
setError   ( ON );
setAdcValues ( );
_delay_ms  ( 200 );
setError   ( OFF );
sei();
HC12_start();
3) The program enter into a while loop, where loop variable is used to blink the Error LED when there is an error in ADC values. For the first 10 cycles it checks the errors and make match for different conditions.
if (loop>10)
{
setBlinker ( TOGGLE );
if ( isHC12ERROR )
setError ( ON );
else if ( ADC_ERROR_CODE )
setError ( TOGGLE );
else
setError ( OFF );
loop=0;
}
4) The “readAdcValues” function is used to read ADC values from all channels and “checkAdcValues” function is used to check errors in values.
readAdcValues  ( );
checkAdcValues ( );
5) If the remote monitoring device sends a request for status then it sent via the following code snippet.
if ( isUSARTQUERY==1 )
{
sendStatus ( );
isUSARTQUERY = 0;
ADC_ERROR_CODE=0;
}
The AVR code of the remote monitoring device has the following breakdown –
Constants Used in the code :-
#define F_CPU 1000000UL :- Constant used to define clock frequency of MCU
#define FCPU_BY_100 F_CPU/100 :- Frequency Divided by 100 for baud rate calculation
#define ON  1 :- To turn on LED
#define OFF 0 :- To turn off LED
#define TOGGLE 2 :- To Blink LED
#define ERROR  1 :- used when there is an error
#define BUTTONS_PORT PIND :- button port defined as port D
#define BUTTON_UP 0b10000000 :- S3 is connected to the pin 7 of port D
#define BUTTON_NEXT 0b01000000 :- S2 is connected to the pin 6 of port D
#define BUTTON_MUTE 0b00100000 :- S1 is connected to the pin 5 of port D
#define BUTTON_SETTING 0b01000000 :- S2 is connected to the pin 6 of port D
#define RTC_BIT 0b00010000 :- jumper J1 connected to the 4th pin of Port D
#define HC12_SET 0b00000100 :-Set pin of HC-12 is connected to the pin 2 of PORT D
#define BLINKER_LED 0b00100000 :- Blinker LED connected to the pin 5 of PORT B
#define BUZZER_BIT 0b00000001 :-buzzer is connected to the 0 pin of port B
#define USART_MAX_RECV_BUF_SIZE 40 :- the maximum size of received buffer value
Variables used in code :-
char USART_RECV_BUF[USART_MAX_RECV_BUF_SIZE+1] :- used to store received buffer
char TEMP_STR[20] :- to store time value
uint8_t CURRENT_PROCESS = 0 :- Process clock
uint8_t HC12error=0 :- used for check Error in HC-12
uint8_t RTCerror=0 :-used for check error in RTC
uint8_t isUSART_DATA_READY=0 :-check data received from Tx
uint8_t USART_RECD_DATA_POS=0 :- the position of buffer array
uint8_t USART_RXD = 0 :- To store Received Data
uint8_t errorloop = 0 :-control buzzer indication
Header file and libraries used in the code :-
#include <avr/io.h> :- Standard AVR header for input/output
#include <util/delay.h> :-Standard AVR header to provide time delays
#include <avr/interrupt.h> :-Standard AVR header for interrupts
#include <string.h> :-used to perform character string operation
#include “FHN_LCD4_LIB.C” :- LCD library
#include “FHN_TWI_LIB.C” :-library for Two wire interface
#include “fhn_rtc_ds1307_lib.C” :-RTC library
Functions used in the code :-
initPorts :-initialize port as input and output
initAdc :-initialized ADC
readAdc :-Read the value from channels
USART_init :-initialize UART communication
HC12_sendChar :- send character to HC-12
HC12_sendString :-send string to HC-12
HC12_sendCommand :-send commands to HC-12
HC12_start :- verify the communication of HC-12
setBlinker :-control the blinker LED
setBuzzer :- control the buzzer
showDateTime :-show time on LCD
sendMessage :-send message via HC-12
editDateTime :-edit time for RTC
clearUsartRx :- Clear the received data at UART
sei() :- enable interrupts
Algorithm :-
1) Initially, the “errorloop” variable is used to turn off buzzer when there is an error. The port is initialized for input and output. After this, the blinker LED turns on for a while and turns off. After this, the buzzer makes a short beep sound.
uint8_t errorloop = 0;
_delay_ms ( 100 );
initPorts ();
_delay_ms ( 500 );
setBlinker (ON);
_delay_ms ( 500 );
setBlinker (OFF);
setBuzzer ( ON );
_delay_ms ( 200 );
setBuzzer ( OFF );
2) The LCD is initialized and then cleared , which clears any garbage values. In the beginning, the LCD shows message “Parked vehicle monitoring –fnn/..” .which indicates that the LCD is working properly. Then, Blinker LED is turned on for a while and turned off.
LCD_start ( );
_delay_ms ( 100 );
LCD_clrscr();
LCD_writeString(“PARKED VEHICLE”);
LCD_gotoRowCol (2, 1);
LCD_writeString(“MONITOR  -fhn/..”);
setBlinker (ON);
_delay_ms ( 500 );
setBlinker (OFF);
_delay_ms ( 100 );
3) The “sei()” function is used to enable interrupts. Then, the UART is initialized for Bluetooth communication. Again the blinker LED is turned on for a while and then turned off. The communication via HC-12 is started and checked if there is any alert message via HC-12 communication. Again, the blinker LED is turned on for a while and then turned off. The LCD is cleared.
sei();
USART_init ( );
setBlinker (ON);
_delay_ms ( 500 );
setBlinker (OFF);
_delay_ms ( 500 );
HC12error = HC12_start ( );
setBlinker (ON);
_delay_ms ( 500 );
setBlinker (OFF);
_delay_ms ( 500 );
//RTC_Start ( );
_delay_ms ( 100 );
LCD_clrscr();
4) The code checks if Jumper J1 is connected then it bypass the RTC. If J1 is not connected then it reads the RTC value. If there is some error in reading data from RTC then shows a message “NOT connected”. Next, the LCD is cleared.
if ((PIND & RTC_BIT) == 0)
{
LCD_writeString(“BY-PASS CHECKING”);
LCD_gotoRowCol (2, 1);
LCD_writeString(”      RTC:DS1307″);
RTCerror = 5;
}
else
{
LCD_writeString(“Check RTC:DS1307”);
LCD_gotoRowCol (2, 1);
RTCerror=RTC_getTime ( );
strcpy (TEMP_STR, TIMESTR );
if ( RTCerror ) //error
LCD_writeString( “ERROR” );
else if (strcmp ( TIMESTR, “HH:MM:SS”)==0)
{
LCD_writeString( “NOT CONNECTED” );
RTCerror = 2;
}
}
_delay_ms ( 1500 );
LCD_clrscr();
5) The programme enters in a while loop. First, it sets the LED to blink for every cycle. It clears the UART. If the S1 switch is pressed then it turns off the buzzer. If the S2 switch is pressed then it goes into time edit mode. It sends request for status to the in-car device via Bluetooth.
setBlinker ( TOGGLE );
clearUsartRx ( );
if ( (BUTTONS_PORT & BUTTON_MUTE) == 0)
{
errorloop=0;
}
if ( (BUTTONS_PORT & BUTTON_SETTING) == 0)
{
editDateTime();
}
sendMessage ( “?” );
6) If J1 jumper is connected then the message “HAVE A NICE DAY VEHICLE MONITOR” is displayed on the LCD. Else if J1 is not connected then current time and date from RTC are displayed.
if (errorloop==0)
{
if ( RTCerror )
{
LCD_gotoRowCol (1,1);
LCD_writeString (“HAVE A NICE DAY “);
LCD_gotoRowCol (2,1);
LCD_writeString (“VEHICLE MONITOR “);
_delay_ms(100);
}
else
{
RTC_getDate ( );
_delay_ms(100);
LCD_gotoRowCol (1,1);
LCD_writeString (“DATE: “);
LCD_writeString (DATESTR);
LCD_gotoRowCol (2,1);
LCD_writeString (“TIME: “);
RTC_getTime ( );
LCD_writeString (TIMESTR);
LCD_writeString (”  ” );
}
}
7) If received data from UART has some incorrect values then the message “WEAK SIGNAL OR LONG DISTANCE” is displayed on LCD. If received data has any alert message then the message “JEARK/VIBRATION/ENGINE/KEY USED” is displayed on the LCD. If there is no communication between both HC-12 modules then the message “NO SIGNAL CHECK VEHICLE & BOARD” is displayed on the LCD.
if ( isUSART_DATA_READY==1 )
{
if ( USART_RECV_BUF[0] != ‘<‘ || USART_RECV_BUF[3] != ‘>’ || (USART_RECV_BUF[1]!=USART_RECV_BUF[2]) )
{
errorloop++;
LCD_gotoRowCol (1,1);
LCD_writeString (“WEAK SIGNAL OR  “);
LCD_gotoRowCol (2,1);
LCD_writeString (”   LONG DISTANCE”);
}
else if ( USART_RECV_BUF[1] != 0x80 )
{
errorloop++;
if ( USART_RECV_BUF[1] & 0x07 )
{
LCD_gotoRowCol (1,1);
LCD_writeString (“JERKS/VIBRATION/”);
}
if ( USART_RECV_BUF[1] & 0x38 )
{
LCD_gotoRowCol (2,1);
LCD_writeString (“ENGINE/KEY USED “);
}
}
}
else // signal is out of coverage
{
errorloop++;
LCD_gotoRowCol (1,1);
LCD_writeString (“NO SIGNAL. CHECK”);
LCD_gotoRowCol (2,1);
LCD_writeString (“VEHICLE & BOARD.” );
}
8) If there is some vibration detected by in-car device then it turns on buzzer to make beep sounds.
if (errorloop>0)
{
_delay_ms(250);
setBuzzer ( ON );
errorloop=1;
}
Check out the complete code and quickly start building this exciting project. Please note that the system designed here is intended for cars and other four wheelers. However, it can be installed in bikes and scooters where only three ADC channels for sensing any vibrations and one ADC channel for sensing ignition or self-start can be used.
Do-It-Yourself Challenge –
How exciting would it have been, if instead of receiving the alert messages on a remote monitoring embedded device, user could have received the same messages on his/her smart phone. Try to develop the same project with a mobile application where the in-car installation device connects to a mobile app and mobile app shows and beeps the alert messages.
Shop For This Project Now –
Component Required Quantity
ATmega8 (A) Microcontrollers 2
16×2 LCD Display 1
HC-12 Modules 2
GY-61 Module 1
DS 1307 IC 1
7805 IC 2
BC548 Transistor 1
3V Battery (C2032) 1
Piezo Buzzer 1
5K Potentiometer 1
470uf 25V Capacitor 2
47uf 16V Capacitor 2
0.1uf Disc Capacitor 8
1K Resistor 2
3.3K Resistors 11
10K Resistor 7
33K Resistor 3
47K Resistor 1
1N4007 Diodes 4
3 mm LEDs 6
32.758 KHz Crystal 1
3V Battery Holder 1
28-Pin IC Base 2
8-Pin IC Base 1
2-Pin Tactile Push Button 5
Push to ON Switches 2
AVR Programmer 1
PCB/ Breadboard As Required
Connecting Wire As Required

 

You may also like:


  • The top IoT platforms of 2023

  • What are LoRa gateways and what types are available?

  • How does LoRa modulation enable long-range communication?

  • What are the different EV charging protocols?

  • What is the role of embedded software in electric vehicles?

  • What is the LoRaWAN network and how does it work?

Project Source Code

//Program to
​/*

filename : ParkedVehicleRx.C

author : fhn

date : 02-mar-2019

mcu : atmega8 (A)

usage : to receive data through HC-12 and set alarm accordingly. else display date and time only

*/


#define F_CPU 1000000UL

#define FCPU_BY_100 F_CPU/100


#define ON  1

#define OFF 0

#define TOGGLE 2

#define ERROR  1

#define OK


#define BUTTONS_PORT PIND

#define BUTTON_UP 0b10000000

#define BUTTON_NEXT 0b01000000

#define BUTTON_MUTE 0b00100000

#define BUTTON_SETTING 0b01000000

#define RTC_BIT 0b00010000 //portD

#define HC12_SET 0b00000100 //portD


#define BLINKER_LED 0b00100000 //portB

#define BUZZER_BIT 0b00000001 //portB



#define USART_MAX_RECV_BUF_SIZE 40

char USART_RECV_BUF[USART_MAX_RECV_BUF_SIZE+1];

char TEMP_STR[20];



#include 

#include 

#include 

#include 


uint8_t CURRENT_PROCESS = 0;

uint8_t HC12error=0, RTCerror=0;

uint8_t isUSART_DATA_READY=0;

uint8_t USART_RECD_DATA_POS=0;

uint8_t USART_RXD = 0;


#include "FHN_LCD4_LIB.C"

#include "FHN_TWI_LIB.C"

#include "fhn_rtc_ds1307_lib.C"

//============================================================

void initPorts ( ) 

{

DDRB=0;

DDRC=0;

DDRD=0;

LCD_DATA_REG |= ( LCD_DATA_BITS );

LCD_CTRL_REG |= ( LCD_ENABLE | LCD_RS );


DDRD |= 0b00000110;  

DDRB |= (BLINKER_LED | BUZZER_BIT);


cli();  //all interrupts disabled

}

//============================================================

int USART_init ( ) 

{


// INITIATES 9500-8-N-1 FORMAT


UBRRL = 12;

UBRRH = 0;


UCSRA |= (1<'9') ch = '0';

if ( ch>'3' && pos==0 )

ch='0';

if ( ch>'1' && (pos==3 || pos==7) )

ch='0';

if ( ch>'1' && DATESTR[0]=='3' && pos==1 )

ch='0';

if ( ch>'2' && DATESTR[3]=='1' && pos==4 )

ch='0';

DATESTR[pos%10] = ch;

LCD_gotoRowCol (1,1 );

LCD_writeString ( DATESTR );

}

else

{

ch = TIMESTR[pos%10];

ch++; if (ch>'9') ch = '0';

if ( ch>'5' && (pos==13 || pos==16) )

ch='0';

if ( ch>'2' && pos==10 )

ch='0';

if ( ch>'3' && TIMESTR[0]=='2' && pos==11 )

ch='0';

TIMESTR[pos%10] = ch;

LCD_gotoRowCol (2,1 );

LCD_writeString ( TIMESTR );

}

}

else if ( (BUTTONS_PORT & BUTTON_NEXT) == 0 ) // MOVES TO NEXT POSITION

{

//isEdited=1;

eloop=0;

pos++;

if (pos>=18)

pos=0;

if (pos==2 || pos==5 || pos==12 || pos==15 )

pos++;

if (pos==6) // for year 2000 series

pos++;

if (pos==7) // for year 2000 series

pos++;

}

else

{

eloop++;

}

}

// set for foolproof except Feb 29 days in leap year (alway 28 days max.)

if ( isEdited==1)

{

if ( DATESTR[0]=='3' && DATESTR[1]>'1')

{ DATESTR[1]='1'; }

if ( DATESTR[3]=='1' && DATESTR[4]>'2')

{ DATESTR[4]='2'; }

if ( DATESTR[0]=='3' && DATESTR[3]=='0' && DATESTR[4]=='2')

{ DATESTR[0]='2'; DATESTR[1]='8'; }

if ( DATESTR[0]=='3' && DATESTR[1]>'0' && DATESTR[3]=='0' &&(DATESTR[4]=='4' || DATESTR[4]=='6' || DATESTR[4]=='9' ))

{ DATESTR[1]='0'; }

if ( DATESTR[0]=='3' && DATESTR[1]>'0' && DATESTR[3]=='1' && DATESTR[4]=='1')

{ DATESTR[1]='0'; }

RTC_WriteDate ( DATESTR );

RTC_WriteTime ( TIMESTR );

LCD_gotoRowCol (2,11 );

LCD_writeString ("SAVED");

_delay_ms ( 2000 );

}

LCD_writeCommand ( 0x0C ); 



}

//============================================================

void clearUsartRx ( )

{

USART_RECD_DATA_POS=0;

isUSART_DATA_READY=0;

USART_RECV_BUF[0]=0;

USART_RECV_BUF[1]=0;

USART_RECV_BUF[2]=0;

USART_RECV_BUF[3]=0;

}

//============================================================

int main ( ) 

{


uint8_t errorloop = 0;


_delay_ms ( 100 );


initPorts ();

_delay_ms ( 500 );


setBlinker (ON);

_delay_ms ( 500 );

setBlinker (OFF);

setBuzzer ( ON );

_delay_ms ( 200 );

setBuzzer ( OFF );


LCD_start ( );

_delay_ms ( 100 );


LCD_clrscr();

LCD_writeString("PARKED VEHICLE");

LCD_gotoRowCol (2, 1);

LCD_writeString("MONITOR  -fhn/..");


setBlinker (ON);

_delay_ms ( 500 );

setBlinker (OFF);

_delay_ms ( 100 );




sei();


USART_init ( );


setBlinker (ON);

_delay_ms ( 500 );

setBlinker (OFF);

_delay_ms ( 500 );


HC12error = HC12_start ( );


setBlinker (ON);

_delay_ms ( 500 );

setBlinker (OFF);

_delay_ms ( 500 );



//RTC_Start ( );

_delay_ms ( 100 );

LCD_clrscr();

if ((PIND & RTC_BIT) == 0)

{

LCD_writeString("BY-PASS CHECKING");

LCD_gotoRowCol (2, 1);

LCD_writeString("      RTC:DS1307");

RTCerror = 5;

}

else

{

LCD_writeString("Check RTC:DS1307");

LCD_gotoRowCol (2, 1);

RTCerror=RTC_getTime ( );

strcpy (TEMP_STR, TIMESTR );

if ( RTCerror ) //error

LCD_writeString( "ERROR" ); 

else if (strcmp ( TIMESTR, "HH:MM:SS")==0)

{

LCD_writeString( "NOT CONNECTED" );

RTCerror = 2;

}

}


_delay_ms ( 1500 );


LCD_clrscr();

while ( 1 )

{

setBlinker ( TOGGLE );

clearUsartRx ( );

if ( (BUTTONS_PORT & BUTTON_MUTE) == 0) 

{

errorloop=0;

}

if ( (BUTTONS_PORT & BUTTON_SETTING) == 0) 

{

editDateTime();

}


sendMessage ( "?" );


if (errorloop==0)

{

if ( RTCerror )

{

LCD_gotoRowCol (1,1);

LCD_writeString ("HAVE A NICE DAY ");

LCD_gotoRowCol (2,1);

LCD_writeString ("VEHICLE MONITOR ");

_delay_ms(100);

}

else

{

RTC_getDate ( );

_delay_ms(100);

LCD_gotoRowCol (1,1);

LCD_writeString ("DATE: ");

LCD_writeString (DATESTR);

LCD_gotoRowCol (2,1);

LCD_writeString ("TIME: ");

RTC_getTime ( );

LCD_writeString (TIMESTR);

LCD_writeString ("  " );

}

}

_delay_ms(500);


if ( isUSART_DATA_READY==1 ) 

{


if ( USART_RECV_BUF[0] != '<' || USART_RECV_BUF[3] != '>' || (USART_RECV_BUF[1]!=USART_RECV_BUF[2]) )

{

errorloop++;

LCD_gotoRowCol (1,1);

LCD_writeString ("WEAK SIGNAL OR  ");

LCD_gotoRowCol (2,1);

LCD_writeString ("   LONG DISTANCE");

}

else if ( USART_RECV_BUF[1] != 0x80 )

{

errorloop++;

if ( USART_RECV_BUF[1] & 0x07 )

{

LCD_gotoRowCol (1,1);

LCD_writeString ("JERKS/VIBRATION/");

}

if ( USART_RECV_BUF[1] & 0x38 )

{

LCD_gotoRowCol (2,1);

LCD_writeString ("ENGINE/KEY USED ");

}

}

}

else // signal is out of coverage

{

errorloop++;

LCD_gotoRowCol (1,1);

LCD_writeString ("NO SIGNAL. CHECK");

LCD_gotoRowCol (2,1);

LCD_writeString ("VEHICLE & BOARD." );


}

setBuzzer(OFF);

if (errorloop>0)

{

_delay_ms(250);

setBuzzer ( ON );

errorloop=1;

}

}

}



//============================================================

ISR ( USART_RXC_vect )

{

USART_RXD = UDR; 



if ( USART_RECD_DATA_POS < USART_MAX_RECV_BUF_SIZE && USART_RXD>0)

USART_RECV_BUF[USART_RECD_DATA_POS++] = USART_RXD;


if ( USART_RECD_DATA_POS>=4 ) //( USART_RXD == '>' )

isUSART_DATA_READY=1;

}

//============================================================

Circuit Diagrams

RX
TX

Project Datasheet

https://www.engineersgarage.com/wp-content/uploads/2019/10/library_attechment.zip


Project Video


Filed Under: Electronic Projects

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Voltage mode pushpull is a nonsense SMPS?
  • Input impedance matching network
  • High Side current sensing
  • The comparison of different Tcl script checkers
  • Reducing "shoot-through" in offline Full Bridge SMPS?

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe