Arduino – Ultrasonic Sensor

This week I attached the ultrasonic sensor to the board.

Ultrasonic sensor = measures the distance of the nearest object, sending the result to the serial port. It can work from 2 cm to 3 m. It measures the time spent by the signal to reach the object and return to the sensor. (definition given on https://create.arduino.cc/projecthub/Nicholas_N/distance-measurement-with-an-ultrasonic-sensor-hy-srf05-64554e)

Connecting the module :

Ultrasonic module   to     Arduino

Black Gnd   to                  Gnd

Yellow +5V  to                Vcc

Blue Trigger  to               D8

Red Echo  to                    D7

 

module connected

 

 

 

 

 

 

 

This was the first sketch I tried to run. It uploaded with no errors however it only produced ‘-1’meaning that the ultrasonic sensor was ‘out of range’. I tried moving it around however this made no change.

1st sketch

 

-1 s out of range

It was then suggested that the wire had a connection issue. So instead we all tried plugging the sensor directly into the board. We had to edit the sketch to do this, changing the pin mode to 8 and 11. This worked well and the sensor started to produce numbers meaning it no longer thought the module was ‘out of range’.

Sensor

final sketch and result

numbers produced and the edited sketch

full sketch

Edited sketch

Print Friendly, PDF & Email