Arduino Nano: Measure Distance With Ultrasonic Ranger and Log It to MicroSD Card With Visuino

by BoianM in Circuits > Arduino

8251 Views, 19 Favorites, 0 Comments

Arduino Nano: Measure Distance With Ultrasonic Ranger and Log It to MicroSD Card With Visuino

Arduino Nano: Measure distance with Ultrasonic Ranger and Log it to MicroSD Card With Visuino

MicroSD Cards are cheap and easy data storage medium, and they are very convenient for storing Arduino sensor data. There are also a number of cheap readily available MicroSD Card Modules for Arduino.

In this Instructable, I will show you how easy it is to connect MicroSD Card Module to Arduino, and program it with Visuino to record Sensor data.

Components

572e7b5a67400cfaa4000959.jpeg
  1. One Arduino compatible board (I use Arduino Nano, because I have one, but any other will be just fine)
  2. One MicroSD Card Module
  3. One MicroSD Card
  4. One Ultrasonic Ranger Sensor Module - I used HC-SR04, but US-015, or very much any other will also work
  5. One small Breadboard (Any breadboard can be used, or any other way to connect 3 wires together)
  6. 8 Female-Female jumper wires
  7. 3 Female-Male (Red) jumper wires

Connect the MicroSD Module to Arduino

572e7df9937ddb44360002d3.jpeg
572fce3815be4d71dd000536.jpeg
572fce0145bcebab46001703.jpeg
572fce96937ddbb52e000f41.jpeg
572fce2150e1b6a19e000594.jpeg
  1. Connect Female-Female CS(Gray Wire), SCK(Orange wire), MOSI(Blue wire), MISO(Purple wire), and Ground(Black wire) to the MicroSD Module
  2. Connect the Female end of a Female-Male Power(Red wire) to the VCC/Power pin of the MicroSD Module (Picture 1) , and leave the Male end unconnected
  3. Connect the other end of the Ground wire(Black wire) to Ground pin of the Arduino board(Picture 2)
  4. Connect another Female-Male Power wire(Red wire) to the 5V Power pin of the Arduino board(Picture 2), and leave the Male end unconnected
  5. Connect the other end of the SCK(Orange wire) to Digital pin 13 of the Arduino board(Picture 3)
  6. Connect the other end of the MISO(Purple wire) to Digital pin 12 of the Arduino board(Picture 4)
  7. Connect the other end of the MOSI(Blue wire) to Digital pin 11 of the Arduino board(Picture 4)
  8. Connect the other end of the CS(Gray wire) to Digital pin 10 of the Arduino board(Picture 4)
  9. Picture 5 shows in Red where are the Ground, 5V Power, Digital 10, Digital 11, Digital 12, and Digital 13 pins of the Arduino Nano

Connect the Ultrasonic Ranger to Arduino

567c537a4936d4196e00057f.jpeg
572fcea3937ddbb52e000f42.jpeg
572fce2d50e1b6aefb000141.jpeg
  1. Connect Female-Female Ground(Black wire), Trigger(Green wire), and Echo(Yellow wire) to the Ultrasonic Ranger Sensor Module (Picture 1)
  2. Connect the Female end of a Female-Male Power(Red wire) to the VCC/Power pin of the Ultrasonic Ranger Sensor Module (Picture 1) , and leave the Male end unconnected
  3. Connect the other end of the Ground wire(Black wire) to Ground pin of the Arduino board(Picture 2)
  4. Connect the other end of the Trigger wire(Green wire) to Digital pin 2 of the Arduino board(Picture 2)
  5. Connect the other end of the Echo wire(Yellow wire) to Digital pin 3 of the Arduino board(Picture 2)
  6. Picture 3 shows in Red where are the Ground, Digital 2, and Digital 3 pins of the Arduino Nano (In Blue are shown the connections made in the previous step)

Connect the Power Wires Together, and Plug the MicroSD Card in the Module

5695929050e1b652510007ee.jpeg
572fce022e7fb624e2000fb7.jpeg
  1. Connect the Male ends of the 3 Power wires(Red wires) - from the Ultrasonic Ranger, the MicroSD Card Module, and the Arduino together as example with the help of a Breadboard (Picture 1) - In my case I used a small Breadboard
  2. Insert the MicroSD Card into the MicroSD Card Module (Picture 2)

Start Visuino, and Select the Arduino Board Type

Select Board Arrow.png
Select BoardNano.png

To start programming the Arduino, you will need to have the Arduino IDE installed from here: http://www.arduino.cc/.

Please be aware that there are some critical bugs in Arduino IDE 1.6.6.

Make sure that you install 1.6.7 or higher, otherwise this Instructable will not work!

The Visuino: https://www.visuino.com also needs to be installed.

  1. Start Visuino as shown in the first picture
  2. Click on the "Tools" button on the Arduino component (Picture 1) in Visuino
  3. When the dialog appears, select "Arduino Nano" as shown in Picture 2

In Visuino: Add and Connect Micro SD Card Module Component

ComponentMicroSD.png
ComponentMicroSDConnect.png
ComponentMicroSDConnect2.png

First we need to add and connect MicroSD Component in Visuino to control the MicroSD Module:

  1. Type "sd" in the Filter box of the Component Toolbox then select the "Micro SD Card Module" component (Picture 1), and drop it in the design area
  2. Connect the "Out" pin of the SDCard1 component to the to the "In" pin of the "SPI" channel of the Arduino component (Picture 2)
  3. Connect the "ChipSelect" output pin of the SDCard1 component to the "Digital" input pin of the "Digital[ 10 ]" channel of the Arduino component (Picture 3)

In Visuino: Add and Configure File Element to the MicroSD Card Component

ComponentMicroSDTools.png
AddFile.png
FileName.png

To record the data we need to add File element to the MicroSD component and specify its file name:

  1. Click on the "Tools" button of the SDCard1 component (Picture 1)
  2. In the "Elements" editor select the “File” element in the right window, and then click on the "+" button on the left (Picture 2) to add File element
  3. In the Object Inspector set the value of the "Path Name" property of the File1 Element to "Log.txt" (Picture 3)

In Visuino: Add and Connect Ultrasonic Ranger Component

ComponentSonicRanger.png
ComponentSonicRangerConnect1.png
ComponentSonicRangerConnect2.png
ComponentSonicRangerConnect3.png
ComponentSonicRangerConnect4.png
ComponentSonicRangerConnect5.png

Finally we need to add and connect a sensor to collect data, and send it to the File element of the MicroSD Module:

  1. Type "sonic" in the Filter box of the Component Toolbox then select the "Ultrasonic Ranger(Ping)" component (Picture 1), and drop it in the design area
  2. Connect the "Out" output pin of the UltrasonicRanger1 component to the "In" input pin of the "Elements.File1" of the SDCard1 component (Picture 2)
  3. Connect the "Ping(Trigger)" pin of the UltrasonicRanger1 component (Picture 3) to the "Digital" input pin of the Digital[ 2 ] channel of the Arduino component (Picture 4)
  4. Connect the "Out" pin of the Digital[ 3 ] channel of the Arduino component (Picture 5) to the "Echo" input pin of the UltrasonicRanger1 component (Picture 6)

In Visuino: Specify the Delay Between the Ultrasonic Ranger Measurements

ComponentSonicRangerProperty.png

In the Object Inspector set the value of the "Pause Time (mS)" property to "1000" so the Ultrasonic Ranger will pause for 1 second between the measurements (Picture 1)

Generate, Compile, and Upload the Arduino Code

GenerateCtopped.png
ArduinoIDE.png
  1. In Visuino, Press F9 or click on the button shown on Picture 1 to generate the Arduino code, and open the Arduino IDE
  2. In the Arduino IDE, click on the Upload button, to compile and upload the code (Picture 2)

And Play...

572e7539937ddb44360002ca.jpeg
Log.png
VisuinoDiagramCrop.png
Arduino Nano: Measure distance with Ultrasonic Ranger and Log it to MicroSD Card With Visuino

Congratulations! You have completed the project.

Picture 1 and the Video show the connected and powered up project. The LED on Digital Pin 13 of the Arduino will start flashing once a second when new data from the Ultrasonic Ranger is recorded to the MicroSD Card.

On Picture 2 you can see example of the data recorded on the MicroSD Card.

On Picture 3 you can see the complete Visuino diagram.
Also attached is the Visuino project, that I created for this Instructable. You can download and open it in Visuino: https://www.visuino.com