Ultrasound sensor in Snap4Arduino

592 views
Skip to first unread message

Bernat Romagosa

unread,
Mar 31, 2015, 7:17:31 AM3/31/15
to s4a-co...@googlegroups.com
We've managed to hook it up! :)

Here's the blog post with a video and all files you'll need to control an ultrasound sensor from Snap4Arduino:


Just specify the pin where you've connected it and you're done!

The formula to convert from the value the sensor gives and centimeters is to just divide it by 58.

Enjoy!

--
Bernat Romagosa

Equip de recerca Edutec

http://edutec.citilab.eu

+34 93 551 06 60


FUNDACIÓ PEL FOMENT DE LA 

SOCIETAT DEL CONEIXEMENT

CORNELLÀ


Citilab Cornellà | http://citilab.eu | Pl. Can Suris s/n | 08940 Cornellà de Llobregat | Barcelona


En compliment de la Llei Orgànica de Protecció de Dades de Caràcter Personal (LOPD), l'informem que les seves dades de contacte han estat incorporades en un fitxer titularitat de FUNDACIÓ PEL FOMENT DE LA SOCIETAT DEL CONEIXEMENT (CITILAB). La finalitat d'aquest fitxer és la de mantenir la relació amb els usuaris dels diferents oferts, inscripció als cursos i a les activitats organitzades, facilitar la tramitació d'informació i notificacions comercials i administratives, i en el cas de que vostè ho hagi sol·licitat, l'enviament de publicitat relativa als serveis oferts. FUNDACIÓ PEL FOMENT DE LA SOCIETAT DEL CONEIXEMENT (CITILAB) assegura la confidencialitat de les dades aportades i garanteix que, en cap cas, seran cedides per cap altre ús sense que hi hagi un consentiment previ i exprés per part seva.

 

Per exercir els drets d'accés, rectificació, cancel·lació i oposició previstos en la llei, pot adreçar-se mitjançant correu postal a FUNDACIÓ PEL FOMENT DE LA SOCIETAT DEL CONEIXEMENT (CITILAB), Ref. Protecció de Dades, Pl. Can Suris S/N, 08940, Cornellà de Llobregat, Barcelona, o bé exercir els drets assenyalats mitjançant l'enviament de la seva petició al correu electrònic avis...@citilab.eu, indicant en l'assumpte del correu “Ref. Protecció de Dades” (acreditant degudament la seva identitat).

蔡其蓁

unread,
Apr 16, 2015, 3:50:53 AM4/16/15
to s4a-co...@googlegroups.com
Thank you so much for the wonderful work.

Tom....@madatech.org.il

unread,
May 30, 2015, 11:25:52 AM5/30/15
to s4a-co...@googlegroups.com
I have modified the code to work with HC-SR04 popular ultrasonic sensor with TRIG/ECHO (4 pins)
I cannot upload so this is the snippet that needs changing
this assumes ECHO pin is connected at the pin next to TRIG (ex. 2, 3)

---------

unsigned long pollUltrasound(int pin) {
pinMode(pin, OUTPUT);
pinMode(pin+1, INPUT);
digitalWrite(pin, LOW);
delayMicroseconds(2);
digitalWrite(pin, HIGH);
delayMicroseconds(5);
digitalWrite(pin, LOW);

return pulseIn(pin+1, HIGH);// add this for conversion to cm: / 29 / 2;
}

Bernat Romagosa

unread,
Jun 1, 2015, 3:59:28 AM6/1/15
to Tom....@madatech.org.il, s4a-co...@googlegroups.com
Hi Tom!

Thanks for the modification, we'll feature it in our official site soon.

Cheers!
Bernat.

}

--
You received this message because you are subscribed to the Google Groups "S4A Community Mail List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to s4a-communit...@googlegroups.com.
To post to this group, send email to s4a-co...@googlegroups.com.
Visit this group at http://groups.google.com/group/s4a-community.
To view this discussion on the web visit https://groups.google.com/d/msgid/s4a-community/10a4037d-58ba-492d-a56a-0770684ce8a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

mza...@gmail.com

unread,
Mar 25, 2017, 12:37:00 AM3/25/17
to S4A Community Mail List, brom...@e-citilab.eu
Hi,

My daughter tried to follow the instructions on the most recent version (1.6) and there is no File->Import option... Only Import Project.
Also, once sketch is uploaded, S4A doesn't seem to connect to Uno (it's connecting with the regular sketch).

Should the library still work on the recent version?

thanks,
Michael

Bernat Romagosa

unread,
Mar 25, 2017, 6:33:56 AM3/25/17
to S4A Community Mail List
Hi Michael!

I think you may be downloading the wrong software (S4A vs Snap4Arduino). The latter can be found at http://snap4arduino.org.

Cheers,
Bernat.

--
You received this message because you are subscribed to the Google Groups "S4A Community Mail List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to s4a-community+unsubscribe@googlegroups.com.

To post to this group, send email to s4a-co...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Bernat Romagosa

이기호

unread,
May 24, 2017, 12:42:36 AM5/24/17
to S4A Community Mail List
Hi~ Thank you for your valuable information

I have a question related with HC-SR04.

I uses TRIG pin to digital 9 and ECHO pin to analog 5.

In this case How to modify javascript code.

Can you help me? or anybody else?

2015년 5월 31일 일요일 오전 12시 25분 52초 UTC+9, Tom....@madatech.org.il 님의 말:

이기호

unread,
May 24, 2017, 1:39:23 AM5/24/17
to S4A Community Mail List
I solve the problem...

s4a gives me hint

unsigned long pollUltrasound(int pin) {
 
  long duration, distance1, distance0;

  if(distance1 > 1)
    distance0=distance1;
  
  pinMode(pin, OUTPUT);    // ponemos el pin 3 como salida
  pinMode(A5, INPUT);    // cambiamos el pin como entrada
  
  digitalWrite(pin, LOW);
  delayMicroseconds(2);                 // give a short LOW pulse beforehand to ensure a clean HIGH pulse
  digitalWrite(pin, HIGH);    // lo activamos
  delayMicroseconds(5);    // esperamos 10 microsegundos
  digitalWrite(pin, LOW);     // lo desactivamos

   duration = pulseIn(A5, HIGH, 50000);  // lee el tiempo que tardo el pulso en regresar echo
  distance1 = duration / 29 / 2;  // calculo de la distancia en cm

  if (distance1==0)
    distance1=distance0;

  return distance1;// add this for conversion to cm: / 29 / 2;
}

return cm 

don't need to calculate return values.



2017년 5월 24일 수요일 오후 1시 42분 36초 UTC+9, 이기호 님의 말:

Armaan

unread,
May 30, 2021, 7:10:21 AM5/30/21
to S4A Community Mail List
sir pls help me! i havee to do this project  soon!!! likee sooooo soon and i found you but the thing is am using hc-sr04 and the frimataa is not loading can u pls hlp me by sending the link for tht waiting for your reply ........... yours Armaan

Armaan

unread,
May 31, 2021, 11:18:46 AM5/31/21
to S4A Community Mail List
sir tq i appreciate ur work but the thing is i have thee latest version of ultrasonic sensor which is HC-SR04 but i guess the ultrasonic senor u hav used is different so..... it would be a great hlp if u hlp me with tht pls am just a 13 year old boy i wanna learn and explore and the possible way is u pls hlp me pls......... Armaan



--
You received this message because you are subscribed to a topic in the Google Groups "S4A Community Mail List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/s4a-community/3r2Q8n6AR1U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to s4a-communit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/s4a-community/1e51cc32-9d95-4bf8-a38f-40e4eeb8f45bn%40googlegroups.com.

Joan Guillén i Pelegay

unread,
May 31, 2021, 12:22:13 PM5/31/21
to Armaan, S4A Community Mail List
Hi Armaan,

What is "the latest version" of the ultrasonic sensor?

More or less, all those HC-SR04 sensors are the same. I guess you can use our firmware and blocks without any problem.

Notes:
- That sensor works at 5V. If you are using 3.3V, the sensor doesn't run ok. It is not about the firmware, is about the sensor itself.
- Usually you have two pins (echo and trigger) but some sensors have only one pin (three pins in total). But this is not a problem. In that case (3 pins) echo and trigger are the same pin.

Joan

You received this message because you are subscribed to the Google Groups "S4A Community Mail List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to s4a-communit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/s4a-community/CAOcv6AnMyZaBwxXV33zgYOAo8DrNVcyCYMba9bgfkcSJpEh%3DGg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages