Nuovamente salve a tutti:
Ho scritto alla ITEAD e dopo uno scambio di e-mail mi hanno inviato questo codice. Che ho provato e FUNZIONA!! Innanzi tutto voglio ringraziare il servizio tecnico di ITEAD che si e' dimostrato molto efficiente e diponibile, poi posto sul forum il tutto nel caso che altri si trovino ad avere a che fare con lo stesso rettangolino di EX-INFELICITA'
![]()
I wrote to ITEAD and after some e-mail exchange they sent me this code. Which I tested and WORKS!!
Firstly I'd like to thank the guys from the ITEAD technical service which have been extremely efficient and helpful. Then i post everything on this forum in case somebody else meets the same problems with this sensor.
int pin = 8; // connected to the Trig on the module, this serves as both Trigger and Echo
unsigned long time;
unsigned long sizeofpulse;
float cm;
void setup()
{
Serial.begin(9600);
pinMode(pin, OUTPUT);
digitalWrite(pin, HIGH); // Trig pin is normally HIGH
}
void loop()
{
pinMode(pin, OUTPUT); //return digital pin to OUTPUT mode after reading
digitalWrite(pin, LOW);
delayMicroseconds(25);
digitalWrite(pin, HIGH); //Trig pin pulsed LOW for 25usec
time = micros(); //record timer
pinMode(pin, INPUT); //change pin to INPUT to read the echo pulse
sizeofpulse = pulseIn(pin, LOW, 18000); //should be approx 150usec, timeout at 18msec
time = micros() - time - sizeofpulse; // amount of time elapsed since we sent the trigger pulse and detect the echo pulse, then subtract the size of the echo pulse
cm=(time*340.29/2/10000)-3; // convert to distance in centimeters
Serial.println("sc;");
ย Serial.println("sd0,0;");
ย Serial.println("ssSDM-IO:;");
// Serial.println("sd1,0;");
Serial.print("ss");
Serial.print(cm);
Serial.println(";");
ย Serial.println("ssCM;");
ย delay(1000);
}
Questo e' il risultato ottenuto: (c'e' un po' di pulizia da fare nel codice, l'ho provato cosi' come me lo hanno inviato)
sc;
sd0,0;
ssSDM-IO:;
ss26.03;
ssCM;
sc;
sd0,0;
ssSDM-IO:;
ss25.98;
ssCM;
sc;
sd0,0;
ssSDM-IO:;
ss25.67;
ssCM;
sc;