Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Ultrasonic sensor EZ0

Status
Not open for further replies.
give us more details. is this the thing you are working with?
 
Yes yes exactly this thing...
basically iam using this sensor for collision detection...
kindly help me cuz iam working on other part of the circuitary for my robot....
snd me the working robot if u hav....
any support will be appreciated....
plzzzz plzzzzz
 
its very simple to use, refer page #7 of the datasheet I am assuming you are using a micro controller. so , connect the device with the RXD pin of the MCU and then write a test code to read from it, after powering it up. or you can use a level converter like a MAX 232 and the PCs serial port for the interface.
 
i can give you some sample codes if you like.
for UART interface :
Code:
/*******************************
uart definitions
*******************************/
 
#define USART_BAUDRATE 4800
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

/*******************************
uart thingies
*******************************/
void usart_init()
{
	UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN);   	// Turn on the transmission reception ..
								// circuitry and receiver interrupt
	UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes
	UBRRL = BAUD_PRESCALE; 	// Load lower 8-bits of the baud rate value..
				// into the low byte of the UBRR register
	UBRRH = (BAUD_PRESCALE >> 8); 	// Load upper 8-bits of the baud rate value..
					// into the high byte of the UBRR register
}

ISR (USART_RXC_vect)
{
//	unsigned char value;
	serial = UDR; 		// Fetch the received byte value into the variable "value"
   // UDR = value;   		//Put the value to UDR
	
}
void usart_putch(unsigned char send)
{
	while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
							// for more data to be written to it
	UDR = send; // Send the byte 
}
void uart_string(unsigned char *str)	//take address vaue of the string in pionter *str
{
	int i=0;
	while(str[i]!='\0')				// loop will go on till the NULL charaters is soon in string 
	{
		usart_putch(str[i]);				// sending data on CD byte by byte
		i++;
	}
	return;
}

if you have an LCD
Code:
/*******************************
Class LCD 4 bit for 4 bit lcd
interface 
*******************************/
void lcd_init()	// fuction for intialize 
{
	dis_cmd(0x02);		// to initialize LCD in 4-bit mode.
	dis_cmd(0x28);		//to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
	dis_cmd(0x0C);
	dis_cmd(0x06);
	dis_cmd(0x80);
}

void dis_cmd(char cmd_value)
{
	char cmd_value1;
	cmd_value1 = cmd_value & 0xF0;		//mask lower nibble because PA4-PA7 pins are used. 
	lcdcmd(cmd_value1);			// send to LCD
 	cmd_value1 = ((cmd_value<<4) & 0xF0);	//shift 4-bit and mask
	lcdcmd(cmd_value1);			// send to LCD
}						
 
void to_line(char line,char pos)
{
if(line ==1)
{
 	dis_cmd(0x80 + pos);
}
else
{
 	dis_cmd(0xC0+pos);
}
}
void clear()
{
    to_line(1,0); 
    lcd_write_string("                ");
	to_line(2,0); 
    lcd_write_string("                ");
}

void dis_data(char data_value)
{
	char data_value1;
	data_value1=data_value&0xF0;
	lcddata(data_value1);
 	data_value1=((data_value<<4)&0xF0);
	lcddata(data_value1);
}
 
void lcdcmd(char cmdout)
{
	ctrl=cmdout;
	ctrl&=~(1<<rs);
	ctrl|=(1<<en);
	_delay_ms(1);
	ctrl&=~(1<<en);
}
 
void lcddata(char dataout)
{
	ctrl=dataout;
	ctrl|=(1<<rs);
	ctrl|=(1<<en);
	_delay_ms(1);
	ctrl&=~(1<<en);
}
 
void lcd_write_string(unsigned char *str)	//take address vaue of the string in pionter *str
{
	int i=0;
	while(str[i]!='\0')				// loop will go on till the NULL charaters is soon in string 
	{
		dis_data(str[i]);				// sending data on CD byte by byte
		i++;
	}
	return;
}
 
hey i got working on your requirement and here are the results. is this enough?
asdasd.jpg
View attachment ezo sensor electro tech.zip

Code:
/*****************************
 EZO sensors test code 
******************************
Program by   : Manu krishnan
version      : 1.0.0.0 (beta)
Assembled in : winavr
core         : mega 16 (16k)
fuse         : 11.0592Mhz interna
AVR Studio	 :	4.15.623  
GUI Version	 :	4, 15, 0, 623
AVR Simulator:  1, 0, 2, 1
ATMEGA16		247
date 		 : 25 March 2013 20.44
*******************************/

/*******************************
Preprovcessor Directive
*******************************/
#define F_CPU 11059200UL
#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>
/******************************/
/*******************************
LCD definitions
*******************************/
#define ctrl PORTC  //dataport
#define en PC3		//enable signal
#define rs PC2		//resister select signal
//MACROS
#define output_low(port,pin) port &= ~(1<<pin)
#define output_high(port,pin) port |= (1<<pin)
#define set_input(portdir,pin) portdir &= ~(1<<pin)
#define set_output(portdir,pin) portdir |= (1<<pin)
/*******************************
uart definitions
*******************************/
 
#define USART_BAUDRATE 4800
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
/*******************************
Function definitions
*******************************/
void convert(unsigned int value,unsigned int numb);
void dis_data(char data_value);
void dis_cmd(char cmd_value);
/////////////////////////////////
void lcdcmd(char cmdout);
void lcddata(char dataout);
void lcd_write_string(unsigned char *str);
void lcd_init();
void to_line(char line,char pos);
void clear();	
void convert(unsigned int value,unsigned int numb);
////////////////////////////////
void setup();
////////////////////////////////
void usart_init();
void usart_putch(unsigned char send);
unsigned int usart_getch();
void uart_string(unsigned char *str);
////////////////////////////////////
char txt[];
char a;
volatile unsigned char serial,i;
volatile unsigned char data[3];
/*******************************
Main Function Start
*******************************/
int main()
{

 setup();
 to_line(1,0);
 lcd_write_string("Distance:-");
 while(1)//infinite loop
 {
  to_line(2,0);
  for(a=0;a<=2;a++)
  {
   data[a]= usart_getch();
  }

  for(a=0;a<=2;a++)
  {
  dis_data(data[a]);
  }
 lcd_write_string("c.m.");
  
 }
}
/*******************************
End main
*******************************/
void setup()
{

   DDRA=0x00;
	DDRC=0xff;
//	PORTD=0xff;
	lcd_init();
	usart_init();
	uart_string("test");
//	t2_fastpwm_init();
 
}
/*******************************
Class LCD 4 bit for 4 bit lcd
interface 
*******************************/
void lcd_init()	// fuction for intialize 
{
	dis_cmd(0x02);		// to initialize LCD in 4-bit mode.
	dis_cmd(0x28);		//to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
	dis_cmd(0x0C);
	dis_cmd(0x06);
	dis_cmd(0x80);
}

void dis_cmd(char cmd_value)
{
	char cmd_value1;
	cmd_value1 = cmd_value & 0xF0;		//mask lower nibble because PA4-PA7 pins are used. 
	lcdcmd(cmd_value1);			// send to LCD
 	cmd_value1 = ((cmd_value<<4) & 0xF0);	//shift 4-bit and mask
	lcdcmd(cmd_value1);			// send to LCD
}						
 
void to_line(char line,char pos)
{
if(line ==1)
{
 	dis_cmd(0x80 + pos);
}
else
{
 	dis_cmd(0xC0+pos);
}
}
void clear()
{
    to_line(1,0); 
    lcd_write_string("                ");
	to_line(2,0); 
    lcd_write_string("                ");
}

void dis_data(char data_value)
{
	char data_value1;
	data_value1=data_value&0xF0;
	lcddata(data_value1);
 	data_value1=((data_value<<4)&0xF0);
	lcddata(data_value1);
}
 
void lcdcmd(char cmdout)
{
	ctrl=cmdout;
	ctrl&=~(1<<rs);
	ctrl|=(1<<en);
	_delay_ms(1);
	ctrl&=~(1<<en);
}
 
void lcddata(char dataout)
{
	ctrl=dataout;
	ctrl|=(1<<rs);
	ctrl|=(1<<en);
	_delay_ms(1);
	ctrl&=~(1<<en);
}
 
void lcd_write_string(unsigned char *str)	//take address vaue of the string in pionter *str
{
	int i=0;
	while(str[i]!='\0')				// loop will go on till the NULL charaters is soon in string 
	{
		dis_data(str[i]);				// sending data on CD byte by byte
		i++;
	}
	return;
}
/*******************************
uart thingies
*******************************/
void usart_init()
{
	UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN);   	// Turn on the transmission reception ..
								// circuitry and receiver interrupt
	UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes
	UBRRL = BAUD_PRESCALE; 	// Load lower 8-bits of the baud rate value..
				// into the low byte of the UBRR register
	UBRRH = (BAUD_PRESCALE >> 8); 	// Load upper 8-bits of the baud rate value..
					// into the high byte of the UBRR register
}
unsigned int usart_getch()
{
	while ((UCSRA & (1 << RXC)) == 0);
				// Do nothing until data have been received and is ready to be read from UDR
	return(UDR); // return the byte
	
}
void usart_putch(unsigned char send)
{
	while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
							// for more data to be written to it
	UDR = send; // Send the byte 
}
void uart_string(unsigned char *str)	//take address vaue of the string in pionter *str
{
	int i=0;
	while(str[i]!='\0')				// loop will go on till the NULL charaters is soon in string 
	{
		usart_putch(str[i]);				// sending data on CD byte by byte
		i++;
	}
	return;
}
 
for two sensors you can either connect then in some way that one would'nt communicate with the controller at a time. or use a small signal diode for communicating. or you can make a software serial and then interface, its upto you.
 
Hey magvitron...
the code u snt me is showing error which displaying data on lcd....
tell me what circuitary or programmind i changed to get correct circuitary.....:(
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top