What I have made here is a distance measurement tool. I have put together some parts I had laying around, like an LCD and the DYP-ME007 ultrasonic distance sensor. The idea of this project is really just to familiarize myself with interfacing LCDs using the AVR LCD library from Peter Fleury, which turned out to be very easy, so I can absolutely recommend this library!
I wanted a bar-graph and plain text to visualize the distance to a object that I will point to. I also made a “tare” functionality so you can set a predefined distance to add or subtract other distances based on the tare distance. If the word “tare” is right for this application I don’t know. It is what’s printed on a button on my kitchen weight that does the same thing. Below I will post some pictures and source code for you to look at, but this time I also wanted to videotape the process of making this. So here it goes
Parts list:
AtTiny2313
DYP-ME007 Ultrasonic Distance Module
HD44780 16×2 LCD
2 tactile switches
Some generic components and a stripboard
The code (AVR GCC Compiler)
#include
#include
#include
#include
#include "lcd.h"
volatile int count = 0;
volatile int valueint;
volatile int tareint=0;
char tarestring[7];
char valuestring[10];
ISR(INT0_vect)
{
tareint=valueint;
}
ISR(TIMER1_CAPT_vect)
{
valueint=(ICR1-100)/5;
itoa(valueint-tareint, valuestring, 10);
TCNT1 = 0;
//is triggered each time echo pin goes low.
//Read out tcnt value
}
ISR(TIMER1_COMPA_vect)
{
//is triggered every 6th ms
PORTD ^= (1< _delay_us(20);
PORTD ^= (1< //TCNT1=0;
count++;
}
void updatebar(void)
{
int i;
cli();
lcd_home();
lcd_puts(" ");
lcd_home();
for(i=0 ; i<(valueint/10) ; i++)
{
lcd_putc(255);
}
sei();
}
void updatenumber(void)
{
cli();
lcd_gotoxy(0,1);
lcd_puts(" ");
lcd_gotoxy(0,1);
lcd_puts(valuestring);
lcd_gotoxy(4,1);
lcd_puts("cm");
lcd_gotoxy(8,1);
lcd_puts("Tare=");
lcd_gotoxy(13,1);
itoa(tareint,tarestring, 10);
lcd_puts(tarestring);
sei();
count=0;
}
int main(void)
{
DDRD=0b00110000;
PORTD |= (1<
//INT0 init
MCUCR |= (1< GIMSK |= (1<
//TIMER1 INIT
TCCR1B |= (1< TIMSK |= (1< OCR1A = 8000;
//LCD INIT
lcd_init(LCD_DISP_ON); /* initialize display, cursor off */
lcd_puts("my shiny new lcd");
lcd_gotoxy(3,1);
lcd_puts("is WORKING!");
sei();
while (1) /* loop forever */
{
//PORTD |= (1< if(count>=10)
{
updatebar();
updatenumber();
}
}
}
could you post a quick schematic please
Sorry, never made a schematic for this. It should be self-explanatory if you can read the AVR code though.
Hey Henrik – how do I make a wireless rangefinder as broadcasting every hour with a distance and to work with batteries (Low power)
I thought maybe I could use HC-SR04, ATTiny2313 and NRF24L01 + but I can not assembly code – only Visual Studio. NET (C #, VB, C + +) but can make the receiver portion with Arduino and NRF24L01 + or FEZ Panda II – but need help to the transmitter part HC-SR04, ATTiny2313, NRF24L01 + and low power … Sincerely Paw
If you can make the receiver portion with an Arduino you should be able to make the transmitter portion with an arduino also. You can pull the atmega out of the arduino board after programming and make your own minimalistic PCB, so it will use less power (using low voltage dropout regulators or running directly off of a battery and remove LEDs etc.). Also remember to use low power modes like sleep function.