Changing the range of SRF 10 ultrasonic distance sensor
hallo
i use arduino uno connected ethernet shield (there micro sd in ethernet shield board saving datalog in txt). then, connect ethernet shield srf 10 devantech ultrasonic distance sensor. used coding
#include <wire.h>
#include <spi.h>
#include <sd.h>
string cm = " cm";
const int chipselect = 4;
void setup() {
wire.begin(); // join i2c bus (address optional master)
serial.begin(9600); // start serial communication @ 9600bps
serial.print("initializing sd card...");
// see if card present , can initialized:
if (!sd.begin(chipselect)) {
serial.println("card failed, or not present");
// don't more:
// return;
}
serial.println("card initialized.");
}
int reading = 0;
void loop() {
string datastring = "";
// step 1: instruct sensor read echoes
wire.begintransmission(112); // transmit device #112 (0x70)
// address specified in datasheet 224 (0xe0)
// i2c adressing uses high 7 bits it's 112
wire.write(byte(0x00)); // sets register pointer command register (0x00)
wire.write(byte(0x51)); // command sensor measure in "inches" (0x50)
// use 0x51 centimeters
// use 0x52 ping microseconds
wire.endtransmission(); // stop transmitting
// step 2: wait readings happen
delay(65); // datasheet suggests @ least 65 milliseconds
// step 3: instruct sensor return particular echo reading
wire.begintransmission(112); // transmit device #112
wire.write(byte(0x02)); // sets register pointer echo #1 register (0x02)
wire.endtransmission(); // stop transmitting
// step 4: request reading sensor
wire.requestfrom(112, 2); // request 2 bytes slave device #112
// step 5: receive reading sensor
if (2 <= wire.available()) { // if 2 bytes received
reading = wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte high 8 bits
reading |= wire.read(); // receive low byte lower 8 bits
// serial.println(reading); // print reading
}
datastring = string(reading);
datastring += cm;
file datafile = sd.open("datalog.txt", file_write);
// if file available, write it:
if (datafile) {
datafile.println(datastring);
datafile.close();
// print serial port too:
serial.println(datastring);
}
// if file isn't open, pop error:
else {
serial.println("error opening datalog.txt");
}
delay(1000); // wait bit since people have read output
}
/*
// following code changes address of devantech ultrasonic range finder (srf10 or srf08)
// usage: changeaddress(0x70, 0xe6);
void changeaddress(byte oldaddress, byte newaddress)
{
wire.begintransmission(oldaddress);
wire.write(byte(0x00));
wire.write(byte(0xa0));
wire.endtransmission();
wire.begintransmission(oldaddress);
wire.write(byte(0x00));
wire.write(byte(0xaa));
wire.endtransmission();
wire.begintransmission(oldaddress);
wire.write(byte(0x00));
wire.write(byte(0xa5));
wire.endtransmission();
wire.begintransmission(oldaddress);
wire.write(byte(0x00));
wire.write(newaddress);
wire.endtransmission();
}
*/
this sensor can reach 6 meters. but, when used coding above, maximum range 50 cm. based on srf 10 website, can change range modify in register range. website: http://www.robot-electronics.co.uk/htm/srf10tech.htm. but, still don't understand, place of coding, can change.
can me please modify coding? optimal range (up 6 meters).
thank you
i use arduino uno connected ethernet shield (there micro sd in ethernet shield board saving datalog in txt). then, connect ethernet shield srf 10 devantech ultrasonic distance sensor. used coding
#include <wire.h>
#include <spi.h>
#include <sd.h>
string cm = " cm";
const int chipselect = 4;
void setup() {
wire.begin(); // join i2c bus (address optional master)
serial.begin(9600); // start serial communication @ 9600bps
serial.print("initializing sd card...");
// see if card present , can initialized:
if (!sd.begin(chipselect)) {
serial.println("card failed, or not present");
// don't more:
// return;
}
serial.println("card initialized.");
}
int reading = 0;
void loop() {
string datastring = "";
// step 1: instruct sensor read echoes
wire.begintransmission(112); // transmit device #112 (0x70)
// address specified in datasheet 224 (0xe0)
// i2c adressing uses high 7 bits it's 112
wire.write(byte(0x00)); // sets register pointer command register (0x00)
wire.write(byte(0x51)); // command sensor measure in "inches" (0x50)
// use 0x51 centimeters
// use 0x52 ping microseconds
wire.endtransmission(); // stop transmitting
// step 2: wait readings happen
delay(65); // datasheet suggests @ least 65 milliseconds
// step 3: instruct sensor return particular echo reading
wire.begintransmission(112); // transmit device #112
wire.write(byte(0x02)); // sets register pointer echo #1 register (0x02)
wire.endtransmission(); // stop transmitting
// step 4: request reading sensor
wire.requestfrom(112, 2); // request 2 bytes slave device #112
// step 5: receive reading sensor
if (2 <= wire.available()) { // if 2 bytes received
reading = wire.read(); // receive high byte (overwrites previous reading)
reading = reading << 8; // shift high byte high 8 bits
reading |= wire.read(); // receive low byte lower 8 bits
// serial.println(reading); // print reading
}
datastring = string(reading);
datastring += cm;
file datafile = sd.open("datalog.txt", file_write);
// if file available, write it:
if (datafile) {
datafile.println(datastring);
datafile.close();
// print serial port too:
serial.println(datastring);
}
// if file isn't open, pop error:
else {
serial.println("error opening datalog.txt");
}
delay(1000); // wait bit since people have read output
}
/*
// following code changes address of devantech ultrasonic range finder (srf10 or srf08)
// usage: changeaddress(0x70, 0xe6);
void changeaddress(byte oldaddress, byte newaddress)
{
wire.begintransmission(oldaddress);
wire.write(byte(0x00));
wire.write(byte(0xa0));
wire.endtransmission();
wire.begintransmission(oldaddress);
wire.write(byte(0x00));
wire.write(byte(0xaa));
wire.endtransmission();
wire.begintransmission(oldaddress);
wire.write(byte(0x00));
wire.write(byte(0xa5));
wire.endtransmission();
wire.begintransmission(oldaddress);
wire.write(byte(0x00));
wire.write(newaddress);
wire.endtransmission();
}
*/
this sensor can reach 6 meters. but, when used coding above, maximum range 50 cm. based on srf 10 website, can change range modify in register range. website: http://www.robot-electronics.co.uk/htm/srf10tech.htm. but, still don't understand, place of coding, can change.
can me please modify coding? optimal range (up 6 meters).
thank you
quote
by default, ranging lasts 65ms, can changed writing range register @ location 2.just use formula calculate value range register, , write location 2.
...
the maximum range of srf10 set internal timer. default, 65ms or equivalent of 11 metres of range.
...
the range ((range register x 43mm) + 43mm)
but please, use code tags.
Arduino Forum > Using Arduino > Sensors > Changing the range of SRF 10 ultrasonic distance sensor
arduino
Comments
Post a Comment