![codevision avr examples hc-sr04 codevision avr examples hc-sr04](https://hackster.imgix.net/uploads/attachments/992300/uploads2ftmp2fa5c18e68-1097-4360-8555-ff13f4e5d3702fscreenshot281729_CJWGV9H2kl.png)
![codevision avr examples hc-sr04 codevision avr examples hc-sr04](https://microcontrollerslab.com/wp-content/uploads/2020/10/TM4C123-Tiva-Launchpad-with-HC-SR04-ultrasonic-sensor-interfacing-example.jpg)
We are going to do further calculations in the memory to get the distance in cmĦ. This count is updated to memory for getting the distance, as we have the width of echo in count now.ĥ. So for a pulse high to low at echo pin, we have started a counter and stopped it. Once echo goes low again an interrupt is generated, this time we are going to stop the counter (disabling the counter).Ĥ. Once echo goes high we get an external interrupt and we are going to start a counter (enabling a counter) in the ISR (Interrupt Service Routine) which is executed right after an interrupt triggered.ģ. Triggering the sensor by pulling up the trigger pin for atleast 12uS.Ģ. Now for getting the distance we have to program the controller for the following:ġ. So to get the width of the signal output, the echo pin of sensor is connected to INT0 (interrupt 0) or PD2. The echo pin here is connected to controller as an external interrupt source. Echo is output pin where we get the distance in the form of width of pulse. Trigger pin is where we give trigger to tell the sensor to measure the distance. The ultrasonic sensor is a four pin device, PIN1- VCC or +5V PIN2-TRIGGER PIN3- ECHO PIN4- GROUND. So as shown in the above table we are connecting 10 pins of LCD to controller in which 8 pins are data pins and 2 pins for control. In the circuit you can see we have used 8bit communication (D0-D7) however this is not a compulsory and we can use 4bit communication (D4-D7) but with 4 bit communication program becomes a bit complex. PIN5 or RW (Read/Write) to ground (puts LCD in read mode eases the communication for user) PIN4 or RS (Register Selection) to PD6 of uC
![codevision avr examples hc-sr04 codevision avr examples hc-sr04](https://electrosome.com/wp-content/uploads/2014/10/HC-SR04-Ultrasonic-Sensor.jpg)
PIN3 or VEE to ground (gives maximum contrast best for a beginner) The connections which are done for LCD are given below: See also Networked Biometric Authentication Using Atmega32 We just need to control ENABLE and RS pins to send characters and data accordingly. This puts LCD in highest contrast and read mode. The contrast bit and READ/WRITE are not often used so they can be shorted to ground. In the circuit, you observe I have only took two control pins, this give the flexibility of better understanding. Anyone who does not want to work with FUSE BITS of ATMEGA32A can not use PORTC, as PORTC contains a special type of communication which can only disabled by changing FUSEBITS. Here we are using PORTB to connect to LCD data port (D0-D7). Software: Atmel studio 6.1, progisp or flash magic. Hardware: ATMEGA32, Power supply (5v), AVR-ISP PROGRAMMER, JHD_162ALCD (16x2LCD), 1000uF capacitor, 10KΩ resistor (2 pieces), HC-SR04 sensor. Here the width of the signal must be taken in multiple of uS(micro second or 10^-6). This distance is calculate as, distance (in cm) = width of pulse output (in uS) / 58. As shown in figure, at first we need to initiate the sensor for measuring distance, that is a HIGH logic signal at trigger pin of sensor for more than 10uS, after that a sound vibration is sent by sensor, after a echo, the sensor provides a signal at the output pin whose width is proportional to distance between source and obstacle.