Get Servo Motor Positions From SD Card

by RonFrtek in Circuits > Arduino

252 Views, 1 Favorites, 0 Comments

Get Servo Motor Positions From SD Card

Get Servo Motor Positions from SD Card

In this tutorial we are going to read servo motor positions from the SD card where we saved a text file with positions.

Watch the Video!

What You Will Need

STORAGE 1-500x500.jpg
micro-servo-sg90-3-600x600.png
sd-icon.png
VisuinoAdvrtisementPLCXPertTinyLab (1).jpg
breadboard.png
  • Arduino UNO (Or any other Arduino)
  • SD card module
  • SD card to store a file
  • Servo motor
  • Jumper wires
  • Breadboard
  • Visuino program: Download Visuino



Brought by PCBWay

2022-08-26_13-41-18.jpg

Thank you PCBWay for supporting this tutorial and helping users learn more about electronics.

What I like about the PCBWay is that you can get 10 boards for approximately $5 which is really cost effective for professional made boards, not to mention how much time you save!

Go check them out here. They also offer a lot of other stuff in case you might need it like assembly3D printingCNC machining and a lot more.

The Circuit

2022-09-23_13-48-07.jpg
  • Connect SD card Module pin GND to Arduino pin GND
  • Connect SD card Module pin VCC to Arduino pin 5V
  • Connect SD card Module pin SCK to Arduino digital pin 13
  • Connect SD card Module pin MISO to Arduino digital pin 12
  • Connect SD card Module pin MOSI to Arduino digital pin 11
  • Connect SD card Module pin CS to Arduino digital pin 10
  • Connect Servo motor "Orange" (signal) pin to Arduino Digital pin[2]
  • Connect Servo motor "Red" pin to Arduino positive pin[5V]
  • Connect Servo motor "Brown" pin to Arduino negative pin[GND]


Prepare the SD Card

2022-09-28_14-48-25.jpg

In a Notepad type angle positions from 0 to 180 and save it to the SD Card in file "SERVO.TXT"

Start Visuino, and Select the Arduino UNO Board Type

Visuino-Select-Board-UNO.jpg
F5ZAEMUK36U3RS2.LARGE.jpg

The Visuino: https://www.visuino.eu needs to be installed. Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2

In Visuino Add Components

2022-09-28_14-52-55.jpg
2022-09-28_15-06-24.jpg
2022-09-28_14-54-15.jpg
2022-09-28_14-54-39.jpg
2022-09-28_14-55-06.jpg
2022-09-28_14-55-29.jpg
  • Add "Pulse Generator" component
  • Add "Counter" component
  • Add "Micro SD Card Module" component
  • Add "Text To Analog" component
  • Add "Divide Analog By Value" component
  • Add "Servo" component



In Visuino Set Components

2022-09-28_14-53-44.jpg
2022-09-28_14-55-47.jpg
2022-09-28_14-56-06.jpg
2022-09-28_14-56-37.jpg
2022-09-28_14-57-01.jpg
2022-09-28_14-57-39.jpg
  • If you want to set Servo motor positions faster or slower then adjust the Frequency of the "PulseGenerator1"
  • Select "DivideByValue1" and in the properties window set "Value" to 180


  • Double click on the "SDCard1" and in the "Elements" window drag "File" to the left side and in the properties window set "Path Name" to SERVO.TXT
  • Select "Elements" and click on the 3 dots button and in the new "Elements" window:
  • Drag "Read Seek" to the left side and in the properties window select "Position" and click on the pin icon and select "Cardinal SinkPin"
  • Drag "Read Text Line" to the left
  • Close both "Elements" windows

In Visuino Connect Components

2022-09-28_14-58-42.jpg
2022-09-28_14-58-19.jpg
  • Connect "PulseGenerator1" pin [Out] to "SDCard1" > "Read Text Line1" pin [Clock]
  • Connect "PulseGenerator1" pin [Out] to "Counter1" pin [In]
  • Connect "Counter1" pin [Out] to "SDCard1" > "Read Seek1" pin [Position]
  • Connect "SDCard1" > "Read Text Line1" pin [Out] to "TextToAnalog1" pin [In]
  • Connect "TextToAnalog1" pin [Out] to "DivideByValue1" pin [In]
  • Connect "DivideByValue1" pin [Out] to "Servo1" pin [In]
  • Connect "Servo1" pin [Chip Select] to "Arduino" Digital pin [2]
  • Connect "SDCard1" pin [SPI] to "Arduino" pin [SPI]
  • Connect "SDCard1" pin [Chip Select] to "Arduino" Digital pin [10]


Generate, Compile, and Upload the Arduino Code

2020-10-30_13-20-50.jpg

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Play

If you power the Arduino module, The positions for the Servo motor will be loaded every 1s from the SD card.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this tutorial, you can download it and open it in Visuino: https://www.visuino.eu