URM37 Ultrasonic Sensor with Cosm.com (Arduino uno w/ethernet shield)

So I'm very new to the arduino system as well as cosm. I purchased an ultrasonic sensor and want to connect it to cosm to monitor the feed. In the past I was able to do this with a different type of sensor but I cannot seem to figure it out with this sensor. Here is some info about the sensor:

http://bit.ly/UzswCX

Power: +5V
Current: <20mA
Working temperature: -10??+70?
Detecting range: 4cm-5m
Resolution: 1cm
Interface: RS232 (TTL), PWM
Servo control: One servo control output
Operating Mode: Serial; (PWM) passive control mode; Autonomous Mode; On/OFF Mode
Temperature sensor: 12 bits reading from serial port

The basic code for this sensor. There is also some other example code included, I have attached those as a zip file.

// #
// # Editor : Lauren from DFRobot
// # Date : 08.05.2012

// # Product name: URM V3.2 ultrasonic sensor TTL connection with Arduino
// # Product SKU : SEN0001
// # Version : 1.0
// # Update the library to make it compatible with the Arduino IDE 1.0 or the latest version

// # Description:
// # The sketch for using the URM37 from DFRobot to read values (0-300) from an ultrasound sensor (3m sensor)
// # and writes the values to the serialport

// # Connection:
// # Pin12 (Arduino) -> Pin 1 VCC (URM V3.2)
// # GND (Arduino) -> Pin 2 GND (URM V3.2)
// # Pin 0 (Arduino) -> Pin 9 TXD (URM V3.2)
// # Pin 1 (Arduino) -> Pin 8 RXD (URM V3.2)
// #

int URPower = 12; // Ultrasound power pin
int val = 0;
int USValue = 0;
int timecount = 0; // Echo counter
boolean flag=true;
uint8_t DMcmd[4] = {
0x22, 0x00, 0x00, 0x22}; //distance measure command

void setup() {
Serial.begin(9600); // Sets the baud rate to 9600
Serial.println("Init the sensor");
pinMode(URPower, OUTPUT);
digitalWrite(URPower, HIGH); // Set to High
delay(200); //Give sensor some time to start up --Added By crystal from Singapo, Thanks Crystal.
}

void loop()
{
flag = true;
//Sending distance measure command : 0x22, 0x00, 0x00, 0x22 ;

for(int i=0;i<4;i++)
{
Serial.write(DMcmd[i]);
}

delay(40); //delay for 75 ms
unsigned long timer = millis();
while(millis() - timer < 30)
{
if(Serial.available()>0)
{
int header=Serial.read(); //0x22
int highbyte=Serial.read();
int lowbyte=Serial.read();
int sum=Serial.read();//sum

if(header == 0x22){
if(highbyte==255)
{
USValue=65525; //if highbyte =255 , the reading is invalid.
}
else
{
USValue = highbyte*255+lowbyte;
}

Serial.print("Distance=");
Serial.println(USValue);

flag=false;
}
else{
while(Serial.available()) byte bufferClear = Serial.read();
break;
}
}
}
delay(20);
}

URM37.zip (19.4 KB)

If you plan on using the ethernet shield, do not use digital pins 10-13 for other devices. You are using digital pin 12, and that is one of the SPI data lines used by the w5100.

Thank you SurferTim, thats exactly one of the reasons I throw my questions out there. I don't know this stuff!

What, exactly, is flag doing?

Why is your code so poorly formatted? Indenting makes for much easier reading.

Why do you want someone else to pay to host your data? Why do you want to host that data, anyway?

The code was written by the manufacturer of the sensor. The formatting is probably off because I copy and pasted it.

I don't want people to pay for my feed, I just want to use cosm because it allows me to be notified of events, I can view it on my iPhone and I can track the data.

Honestly I'm not on here to be criticized why I'm doing what I'm doing, but because I want to know how to do it.

Hopefully someone is willing to help.

Thank you.

Honestly I'm not on here to be criticized why I'm doing what I'm doing, but because I want to know how to do it.

Don't worry, some people use the forum to showcase their lives. :slight_smile: