Como ligar 2 sensores ultrasonicos ? - Laboratorio de Garagem (arduino, eletrônica, robotica, hacking)2024-03-29T12:28:14Zhttps://labdegaragem.com/forum/topics/como-ligar-2-sensores-ultrasonicos?feed=yes&xn_auth=nooi agr como faço para fazer d…tag:labdegaragem.com,2023-01-24:6223006:Comment:8896772023-01-24T20:12:01.658Zmarcus andre santos sousahttps://labdegaragem.com/profile/marcusandresantossousa
<p>oi agr como faço para fazer dois motores girarem igual de carro </p>
<p></p>
<p>oi agr como faço para fazer dois motores girarem igual de carro </p>
<p></p> Dois automóveis ?
Qual a dis…tag:labdegaragem.com,2016-06-22:6223006:Comment:5433932016-06-22T14:14:54.454ZJosé Gustavo Abreu Murtahttps://labdegaragem.com/profile/GustavoMurta
<p>Dois automóveis ? </p>
<p>Qual a distância entre os sensores e os automóveis ? </p>
<p>Qual a velocidade maxima desses automóveis ?</p>
<p>Lembre-se que esses sensores tem limitações de distância e tempo de medição. </p>
<p></p>
<p><a href="http://labdegaragem.com/forum/topics/sensor-hc-sr04-ultrasom-como-funciona" target="_blank">http://labdegaragem.com/forum/topics/sensor-hc-sr04-ultrasom-como-funciona</a></p>
<p>Dois automóveis ? </p>
<p>Qual a distância entre os sensores e os automóveis ? </p>
<p>Qual a velocidade maxima desses automóveis ?</p>
<p>Lembre-se que esses sensores tem limitações de distância e tempo de medição. </p>
<p></p>
<p><a href="http://labdegaragem.com/forum/topics/sensor-hc-sr04-ultrasom-como-funciona" target="_blank">http://labdegaragem.com/forum/topics/sensor-hc-sr04-ultrasom-como-funciona</a></p> É igual está na figura da res…tag:labdegaragem.com,2016-06-22:6223006:Comment:5433872016-06-22T13:37:45.059ZLuiz Carlos Almeidahttps://labdegaragem.com/profile/LuizCarlosAlmeida
<p>É igual está na figura da resposta acima, só ligar todos em paralelo em um único pino, quando vc usa o comando do trigger ele aciona todos os sensores aí é escolher qual vc quer ler.</p>
<p>É igual está na figura da resposta acima, só ligar todos em paralelo em um único pino, quando vc usa o comando do trigger ele aciona todos os sensores aí é escolher qual vc quer ler.</p> Bom dia, como faço para ligar…tag:labdegaragem.com,2016-06-22:6223006:Comment:5432932016-06-22T11:45:39.767ZPedro Luiz Battistini Souzahttps://labdegaragem.com/profile/PedroLuizBattistiniSouza
<p>Bom dia, como faço para ligar todos os pinos Trigger no mesmo pino do Arduino?</p>
<p>Bom dia, como faço para ligar todos os pinos Trigger no mesmo pino do Arduino?</p> então as distancias vc ta con…tag:labdegaragem.com,2014-07-02:6223006:Comment:3652122014-07-02T12:19:13.210ZLuiz Carlos Almeidahttps://labdegaragem.com/profile/LuizCarlosAlmeida
<p>então as distancias vc ta conseguindo ler corretamente!? e vc colocou que, <span>tempo2 = tempo /1000, mas onde vc mede a variavel tempo? não achei no codigo</span></p>
<p>então as distancias vc ta conseguindo ler corretamente!? e vc colocou que, <span>tempo2 = tempo /1000, mas onde vc mede a variavel tempo? não achei no codigo</span></p> boa tarde !
sua dica me ajudo…tag:labdegaragem.com,2014-07-01:6223006:Comment:3649192014-07-01T17:17:30.477Zgustavo ribeshttps://labdegaragem.com/profile/gustavoribes
<p>boa tarde !</p>
<p>sua dica me ajudou muito!</p>
<p>porem, eu estou tendo dificultadas em calcular as velocidades dos carros com os valores que eu leio dos sensores. a parte de apresentar os valores no lcd esta funcionando muito bem.</p>
<p>segue o codigo :</p>
<p><br></br>const int pingTrigger = 8;<br></br>const int Sensor_1 = 7;<br></br>const int Sensor_2 = 6;<br></br>#include <LiquidCrystal.h> //Carrega a biblioteca LCD<br></br>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<br></br>void setup() {…<br></br> <br></br></p>
<p>boa tarde !</p>
<p>sua dica me ajudou muito!</p>
<p>porem, eu estou tendo dificultadas em calcular as velocidades dos carros com os valores que eu leio dos sensores. a parte de apresentar os valores no lcd esta funcionando muito bem.</p>
<p>segue o codigo :</p>
<p><br/>const int pingTrigger = 8;<br/>const int Sensor_1 = 7;<br/>const int Sensor_2 = 6;<br/>#include <LiquidCrystal.h> //Carrega a biblioteca LCD<br/>LiquidCrystal lcd(12, 11, 5, 4, 3, 2);<br/>void setup() {<br/> <br/> pinMode(pingTrigger, OUTPUT);<br/> pinMode(Sensor_1, INPUT);<br/> pinMode(Sensor_2, INPUT);<br/> lcd.begin(16,2); //Inicializa LCD<br/> lcd.clear(); //Limpa o LCD <br/> // initialize serial communication:<br/> Serial.begin(9600);<br/>}</p>
<p>void loop()<br/>{<br/> long duration, cm;<br/> //distancia dos carros <br/> double x, velocidade, velocidade2, tempo2, tempoencontro,pontodeencontro, carro1,carro2, tempo; // define todas as variaveis como double<br/> // SENSOR 1 <br/> // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.<br/> // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:<br/> digitalWrite(pingTrigger, LOW);<br/> delayMicroseconds(2);<br/> digitalWrite(pingTrigger, HIGH);<br/> delayMicroseconds(5);<br/> digitalWrite(pingTrigger, LOW);</p>
<p>// The same pin is used to read the signal from the PING))): a HIGH<br/> // pulse whose duration is the time (in microseconds) from the sending<br/> // of the ping to the reception of its echo off of an object.<br/> duration = pulseIn(Sensor_1, HIGH);</p>
<p>// convert the time into a distance<br/> cm = microsecondsToCentimeters(duration);<br/> Serial.println("Sensor 1");<br/> Serial.print(carro1);<br/> Serial.print("cm");<br/> Serial.println();<br/> delay(100);</p>
<p>// apresenta a distancia dos carros na serial<br/> Serial.print("Carro 1:");<br/> Serial.print(cm);<br/> // apresenta no LCD a distancia dos carros <br/> lcd.setCursor(0,0);<br/> lcd.print("Distancia 1:");<br/> lcd.setCursor(10,0);<br/> lcd.print(cm);<br/> lcd.setCursor(14,0);<br/> lcd.print("CM");<br/> carro1 = cm;<br/> // SENSOR 2<br/> // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.<br/> // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:<br/> digitalWrite(pingTrigger, LOW);<br/> delayMicroseconds(2);<br/> digitalWrite(pingTrigger, HIGH);<br/> delayMicroseconds(5);<br/> digitalWrite(pingTrigger, LOW);</p>
<p>// The same pin is used to read the signal from the PING))): a HIGH<br/> // pulse whose duration is the time (in microseconds) from the sending<br/> // of the ping to the reception of its echo off of an object.<br/> duration = pulseIn(Sensor_2, HIGH);</p>
<p>// convert the time into a distance<br/> cm = microsecondsToCentimeters(duration);<br/> Serial.print("Carro 2 ");<br/> Serial.println(cm);<br/> // carro 2 <br/> lcd.setCursor(0,1);<br/> lcd.print("Distancia 2:");<br/> lcd.setCursor(10,1);<br/> lcd.print(cm);<br/> lcd.setCursor(14,1);<br/> lcd.print("CM");<br/> carro2 = cm; <br/> if(cm >= 91){<br/> <br/> <br/> //calcula e mostra na serial a velocidade dos carros<br/> tempo2 = tempo /1000; // transforma de millisegundos para segundos<br/> velocidade = carro1 / tempo2; // calcula a velocidade do carro 1 <br/> velocidade2 = carro2 / tempo2 ;// calcula a velocidade do carro 2<br/> Serial.println(tempo2); <br/> Serial.print(" velocidade carro 1: ");<br/> Serial.print(velocidade);<br/> Serial.print(" velocidade carro 2:");<br/> Serial.print(velocidade2);<br/> <br/> <br/> // CALCULA O PONTO DE ENCONTRO DOS CARROS E O APRESENTA NA LCD<br/> tempoencontro = 1 /(velocidade2 + velocidade);<br/> pontodeencontro = 0.04 + velocidade * tempoencontro; // calculo do local de encontro subustituindo os calores na primeira equação <br/> Serial.print("encontro ocorreu");<br/> Serial.print(pontodeencontro);<br/> lcd.setCursor(0,0);<br/> lcd.print("encontro foi em :");<br/> lcd.setCursor(0,1);<br/> lcd.print(pontodeencontro);<br/> lcd.setCursor(5,1);<br/> lcd.print("CM");<br/> delay (1000000);<br/> <br/> }<br/>}</p>
<p>long microsecondsToInches(long microseconds)<br/>{<br/> // According to Parallax's datasheet for the PING))), there are<br/> // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per<br/> // second). This gives the distance travelled by the ping, outbound<br/> // and return, so we divide by 2 to get the distance of the obstacle.<br/> // See: <a href="http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf" target="_blank">http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf</a><br/> return microseconds / 74 / 2;<br/>}</p>
<p>long microsecondsToCentimeters(long microseconds)<br/>{<br/> // The speed of sound is 340 m/s or 29 microseconds per centimeter.<br/> // The ping travels out and back, so to find the distance of the<br/> // object we take half of the distance travelled.<br/> return microseconds / 29 / 2;<br/>}</p>
<p></p>
<p>Até mais,</p>
<p>abraço!</p> Olá Gustavo.
Basta você l…tag:labdegaragem.com,2014-07-01:6223006:Comment:3649032014-07-01T14:11:28.284ZDaniel (OráculoX)https://labdegaragem.com/profile/DanielCezar
<p></p>
<p></p>
<p> Olá Gustavo.</p>
<p> Basta você ligar os pinos de Trigger dos sensores no mesmo pino do Arduino, e os pinos de Echo em pinos diferentes.</p>
<p> No código você manda o comando de ping, seleciona o pino correspondente ao sensor, e efetua a leitura das medidas.</p>
<p></p>
<p>Segue exemplo abaixo.:</p>
<p><a href="http://storage.ning.com/topology/rest/1.0/file/get/1939632691?profile=original" target="_self"><img class="align-full" src="http://storage.ning.com/topology/rest/1.0/file/get/1939632691?profile=RESIZE_1024x1024" width="721"></img></a></p>
<p><strong>/* Ping)))…</strong></p>
<p></p>
<p></p>
<p> Olá Gustavo.</p>
<p> Basta você ligar os pinos de Trigger dos sensores no mesmo pino do Arduino, e os pinos de Echo em pinos diferentes.</p>
<p> No código você manda o comando de ping, seleciona o pino correspondente ao sensor, e efetua a leitura das medidas.</p>
<p></p>
<p>Segue exemplo abaixo.:</p>
<p><a target="_self" href="http://storage.ning.com/topology/rest/1.0/file/get/1939632691?profile=original"><img width="721" class="align-full" src="http://storage.ning.com/topology/rest/1.0/file/get/1939632691?profile=RESIZE_1024x1024" width="721"/></a></p>
<p><strong>/* Ping))) Sensor</strong><br/><strong> </strong> <br/><strong> This sketch reads a PING))) ultrasonic rangefinder and returns the</strong><br/><strong> distance to the closest object in range. To do this, it sends a pulse</strong><br/><strong> to the sensor to initiate a reading, then listens for a pulse</strong> <br/><strong> to return. The length of the returning pulse is proportional to</strong> <br/><strong> the distance of the object from the sensor.</strong><br/><strong> </strong><br/><strong> The circuit:</strong><br/><strong> * +V connection of the PING))) attached to +5V</strong><br/><strong> * GND connection of the PING))) attached to ground</strong><br/><strong> * SIG connection of the PING))) attached to digital pin 7</strong><br/><br/><strong> <a href="http://www.arduino.cc/en/Tutorial/Ping" target="_blank">http://www.arduino.cc/en/Tutorial/Ping</a></strong><br/><strong> </strong><br/><strong> created 3 Nov 2008</strong><br/><strong> by David A. Mellis</strong><br/><strong> modified 30 Aug 2011</strong><br/><strong> by Tom Igoe</strong><br/><strong> </strong><br/><strong> This example code is in the public domain.</strong><br/><br/><strong> */</strong><br/><br/><strong>// this constant won't change. It's the pin number</strong><br/><strong>// of the sensor's output:</strong><br/><strong>const int pingTrigger = 8;</strong><br/><strong>const int Sensor_1 = 7;</strong><br/><strong>const int Sensor_2 = 6;</strong><br/><strong>const int Sensor_3 = 5;</strong><br/><br/><strong>void setup() {</strong><br/><strong> </strong> <br/><strong> pinMode(pingTrigger, OUTPUT);</strong><br/><strong> pinMode(Sensor_1, INPUT);</strong><br/><strong> pinMode(Sensor_2, INPUT);</strong><br/><strong> pinMode(Sensor_3, INPUT);</strong><br/><strong> </strong><br/><strong> // initialize serial communication:</strong><br/><strong> Serial.begin(9600);</strong><br/><strong>}</strong><br/><br/><strong>void loop()</strong><br/><strong>{</strong><br/><strong> // establish variables for duration of the ping,</strong> <br/><strong> // and the distance result in inches and centimeters:</strong><br/><strong> long duration, inches, cm;</strong><br/><br/><strong> // SENSOR 1</strong> <br/><strong> // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.</strong><br/><strong> // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:</strong><br/><strong> digitalWrite(pingTrigger, LOW);</strong><br/><strong> delayMicroseconds(2);</strong><br/><strong> digitalWrite(pingTrigger, HIGH);</strong><br/><strong> delayMicroseconds(5);</strong><br/><strong> digitalWrite(pingTrigger, LOW);</strong><br/><br/><strong> // The same pin is used to read the signal from the PING))): a HIGH</strong><br/><strong> // pulse whose duration is the time (in microseconds) from the sending</strong><br/><strong> // of the ping to the reception of its echo off of an object.</strong><br/><strong> duration = pulseIn(Sensor_1, HIGH);</strong><br/><br/><strong> // convert the time into a distance</strong><br/><strong> inches = microsecondsToInches(duration);</strong><br/><strong> cm = microsecondsToCentimeters(duration);</strong><br/><strong> Serial.println("Sensor 1");</strong><br/><strong> Serial.print(inches);</strong><br/><strong> Serial.print("in, ");</strong><br/><strong> Serial.print(cm);</strong><br/><strong> Serial.print("cm");</strong><br/><strong> Serial.println();</strong><br/><br/><strong> delay(100);</strong><br/><br/><strong> // SENSOR 2</strong><br/><strong> // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.</strong><br/><strong> // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:</strong><br/><strong> digitalWrite(pingTrigger, LOW);</strong><br/><strong> delayMicroseconds(2);</strong><br/><strong> digitalWrite(pingTrigger, HIGH);</strong><br/><strong> delayMicroseconds(5);</strong><br/><strong> digitalWrite(pingTrigger, LOW);</strong><br/><br/><strong> // The same pin is used to read the signal from the PING))): a HIGH</strong><br/><strong> // pulse whose duration is the time (in microseconds) from the sending</strong><br/><strong> // of the ping to the reception of its echo off of an object.</strong><br/><strong> duration = pulseIn(Sensor_2, HIGH);</strong><br/><br/><strong> // convert the time into a distance</strong><br/><strong> inches = microsecondsToInches(duration);</strong><br/><strong> cm = microsecondsToCentimeters(duration);</strong><br/><strong> Serial.println("Sensor 2");</strong><br/><strong> Serial.print(inches);</strong><br/><strong> Serial.print("in, ");</strong><br/><strong> Serial.print(cm);</strong><br/><strong> Serial.print("cm");</strong><br/><strong> Serial.println();</strong> <br/><br/><strong> delay(100);</strong><br/><strong> </strong> <br/><strong> // SENSOR 3</strong><br/><strong> // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.</strong><br/><strong> // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:</strong><br/><strong> digitalWrite(pingTrigger, LOW);</strong><br/><strong> delayMicroseconds(2);</strong><br/><strong> digitalWrite(pingTrigger, HIGH);</strong><br/><strong> delayMicroseconds(5);</strong><br/><strong> digitalWrite(pingTrigger, LOW);</strong><br/><br/><strong> // The same pin is used to read the signal from the PING))): a HIGH</strong><br/><strong> // pulse whose duration is the time (in microseconds) from the sending</strong><br/><strong> // of the ping to the reception of its echo off of an object.</strong><br/><strong> duration = pulseIn(Sensor_3, HIGH);</strong><br/><br/><strong> // convert the time into a distance</strong><br/><strong> inches = microsecondsToInches(duration);</strong><br/><strong> cm = microsecondsToCentimeters(duration);</strong><br/><strong> Serial.println("Sensor 3");</strong><br/><strong> Serial.print(inches);</strong><br/><strong> Serial.print("in, ");</strong><br/><strong> Serial.print(cm);</strong><br/><strong> Serial.print("cm");</strong><br/><strong> Serial.println();</strong><br/><strong> </strong><br/><strong> delay(1000);</strong><br/><strong>}</strong><br/><br/><strong>long microsecondsToInches(long microseconds)</strong><br/><strong>{</strong><br/><strong> // According to Parallax's datasheet for the PING))), there are</strong><br/><strong> // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per</strong><br/><strong> // second). This gives the distance travelled by the ping, outbound</strong><br/><strong> // and return, so we divide by 2 to get the distance of the obstacle.</strong><br/><strong> // See: <a href="http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf" target="_blank">http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf</a></strong><br/><strong> return microseconds / 74 / 2;</strong><br/><strong>}</strong><br/><br/><strong>long microsecondsToCentimeters(long microseconds)</strong><br/><strong>{</strong><br/><strong> // The speed of sound is 340 m/s or 29 microseconds per centimeter.</strong><br/><strong> // The ping travels out and back, so to find the distance of the</strong><br/><strong> // object we take half of the distance travelled.</strong><br/><strong> return microseconds / 29 / 2;</strong><br/><strong>}</strong><br/><br/></p>
<p>Espero ter ajudado.</p>
<p></p>
<p>T++. ^^</p>
<p></p>
<p></p>
<p></p>
<p></p> posta o codigotag:labdegaragem.com,2014-07-01:6223006:Comment:3645942014-07-01T12:49:08.902ZLuiz Carlos Almeidahttps://labdegaragem.com/profile/LuizCarlosAlmeida
<p>posta o codigo</p>
<p>posta o codigo</p>