help with ultrasonic code


  using following ultrasonic sensor.
http://www.sunrom.com/index.php?main_page=product_info&cpath=55&products_id=...
i tried program using arduino atmega8. first did 5v pin in ultrasonic sensor powered using digitalpin. read serial port , converted buffer ascii. problem values remaining constant though obstacles placed @ different positions.here code ive used:
int ser=0;
char s;
char st[10];
int pin=2;
int a;
int i=0;
int range;
void setup()
{
pinmode(pin,output);
serial.begin(9600);
}
void loop()
{
digitalwrite(pin,high);
delay(1000);
digitalwrite(pin,low);
delay(1000);
/* for(i=0;i<10;i++)
{
  s=serial.read();
  range=(s[0]-0x30)*100;//  also tried these lines given in datasheet.
  range=range+(s[1]-0x30)*10;
  range=range+(s[2]-0x30)*1;
  serial.println(s);
}
}*/
 
if(serial.available())
{
  s=serial.read();
  if(i<10&&s!='c'&&s!='m')
{
    st=s;
    i++;
}
   i=0;
    int val=atoi(st);
  serial.println(val);
}
}

your link broken.

could modify post, highlight code in , hit "#" button on editor toolbar, please?

if you're powering device second, how data return in time?
the serial buffer 128 bytes long, may overflowing.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > help with ultrasonic code


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums