In this post, we will see how to install the Arduino software and use the integrated development environment (IDE). For this series, I’m going to be using parts from the Arduino Starter Kit.
Windows Installation
First, go to Arduino software download page here. For windows users, click on the installer option. Mac users will only have one option.
Arduino Software Download Page
Download and run the executable file. Agree to the license agreement. On the next screen, make sure the “Install USB driver” box is checked and finish going through the installation.
Arduino Software Installation Wizard
Mac Installation
For the Mac installation, clicking on the link from the download page will download a zip file. Inside the zip file is the application file. You can run Arduino by clicking on this link directly from your downloads folder, or you can move it to your applications folder.
Arduino Software Download for Mac
Using the IDE
Open up the Arduino software. This will be the environment where all of the code will be written. If the interface is too small to read, you can change the scale by going to File>Preferences. You’ll have to close and reopen the software for to it to take effect.
Arduino Software Preferences
Arduino Preferences Menu
The icon with the check mark is the “Verify” icon. This icon will check the syntax of the code for any errors. The icon next to it is the “Upload” icon. This checks the syntax and then uploads the code to the board. The three icons to the left are “New,” “Open,” and “Save.” The last icon on the far right will open up the serial monitor, which will be discussed in later posts.
Arduino IDE Icons
Communicating with the Arduino Uno
Next we’re going to verify that your computer can communicate with your Arduino. Connect the USB cable to the Arduino and the computer. You should see an LED light up.
Arduino USB Cable
In the Arduino IDE, we’re going to open up an example to upload to the board. Go to File>Examples>Basics>Blink.
Arduino Blink Example
Then make sure you have the correct board selected by going to Tools>Board>Arduino Uno.
Arduino IDE Board Selection
A COM port needs to be selected in order to send and receive data. Select the port by going to Tools>Port. For the Arduino Uno, the COM port is usually labeled. For Windows, the ports are numbered. For a Mac, the port will have “usbmodem” in the name.
Arduino COM Port Selection for Windows
Arduino COM Port Selection for Mac
If you choose the wrong port, the IDE just won’t do anything. To get out of this, choose the correct port and upload again. You’ll initially get an error. Then just click upload one more time.
Arduino IDE Error Message
On Windows, you can check which port is associated with your Arduino by going to the device manager. Scroll down to ports, unplug your Arduino, and then reconnect it. You should be able to see a new COM port pop up. This is the one that is connected to your Arduino.
Windows Device Manager
The particular example that was uploaded turns Pin 13 on and off, over and over again. The “L” LED is connected to this pin and will blink if everything was done properly.
Arduino Uno Pin 13 LED
Now that you’re able to upload to your board, you’re all set to start building circuits and writing code.
https://mechanicaldesign101.com/wp-content/uploads/2024/12/3f.-Arduino-USB-Cabel.jpg563999Prof. McCarthyhttps://mechanicaldesign101.com/wp-content/uploads/2016/07/mechanical-design-101LOGOf.pngProf. McCarthy2024-12-07 16:38:032024-12-07 16:41:23Getting to Know the Arduino IDE
A typical brushed, direct current (DC) motor has two leads. When a voltage is applied across these two leads, the motor shaft spins. Reversing the polarity of this voltage will reverse the direction of rotation of the motor shaft. DC motors are usually wired to a motor driver, which receive and interpret control signals to ultimately drive the motor’s speed and direction. Brushed motors like this are considered to be open loop, meaning they aren’t capable of sending back information about its shaft position or speed.
Brushed DC Motor
This type of motor becomes closed loop when a rotary motor is attached. In this case, the motor is driven in the same way as any other brushed motor. The only difference is that there is now the ability to measure the motor shaft position. Usually this type of motor will have 5 or 6 wires.
Brushed DC Gear Motor with Rotary Encoder
Two of the wires are used for the motor power and the other wires are used for the encoder. Essentially the encoder works by turning a signal on and off as the motor shaft rotates. These pulses are directly related to the motor shaft position. I like to use the analogy of a playing card flapping in the spokes of a bicycle wheel. The faster the wheel moves, the more times you hear the playing card making a noise. In the case of a rotary encoder, a high number of pulses over a given time period indicates a faster motors speed.
For this example I will be using a Pololu DC brushed motor with a 50:1 gear ratio and a rotary encoder with two outputs. It has red and green wires to power the motor shaft movement. It has a green wire for a ground for the encoder, a blue wire (Vcc) to receive a positive voltage between 3.5V and 20V, and a yellow and white wire to output separate encoder signals.
Rotary Encoder Wiring
Below is what the output signals would look like as the motor rotates. Notice how they are out of phase. The signals alternate between values of the supplied Vcc and 0V throughout the motor rotation. For this encoder, if you count the rising and falling edges of a single output, you will count 32 counts per revolution. If you count rising and falling edges for both outputs, you will count 64 counts per revolution. Since this is a 50:1 geared motor, a single rotation of the output shaft will result in a total of 3200 counts (50 x 64 counts).
Rotary Encoder Output — Forward direction
The order in which the rising edge of a particular signal is read is an indication of direction. For instance, let’s say that when the motor is rotating clockwise, the rising edge of Output B is counted before the rising edge of Output A. If that was reversed, the rising edge of Output A is counted first, indicating that the motor is rotating counterclockwise.
Rotary Encoder Output — Reversed Direction
An Arduino Nano is being used to power the motor encoder and read the output values of the encoder. It is also sending signals to a dual motor driver to control the speed of the motor.
I’m also using an RC transmitter and receiver to send signals to the Arduino. Essentially, moving a stick on the controller transmits a signal to the RC receiver. The receiver sends a signal to the Arduino which interprets it and sends it to the motor driver. The motor driver receives the signal from the Arduino, interprets it and outputs power to the motor. All of these signals are pulse width modulated signals, which I will discuss in another post. Lastly, as the motor rotates, the Arduino reads the encoder values.
Hardware for Remote Control of a Motor
Wiring
To start this example, I place an Arduino Nano in a breadboard. I use wire jumpers to make connections to the components. The red and black wires on the motor are wired to one of the black sets of screw terminal blocks on the motor controller. The green wire is connected the Arduino ground and the Blue wire is connected to the Arduino 5V output. The yellow and white wires are attached to pins 2 and 3 on the Arduino.
Electronic Assembly of Nano and Motor-Encoder
For the motor driver, the tan screw terminal blocks receive power from an external power source between 6.5V and 27V. I’m using a AA battery holder and a set of 8 AA batteries for this example. The user manual for this board recommends putting a 10A fuse in between one of the leads of the motors and the motor driver and a 15A fuse between the positive end of the power source and the motor driver.
The motor driver also has a set of male header pins. These pins are what control the behaviors of the attached motors. If you look at these two pins, there are two columns. The left column is for one motor and the right column is for the other. The top pins are connected to 5V from the Arduino and the bottom pins are connected to a ground, also on the Arduino. The pins labeled ENA receive a PWM signal from the Arduino and are directly related to the motor speed. These can be connected to any Arduino pin capable of a PWM output. The pins labeled IN1, IN2, IN3, and IN4 control the direction of the motor. If IN1 has a value of 1 and IN2 has a value of 0, one of the motors will spin forward. If you reverse this configuration, the motor changes direction. This applies to the other motor output with IN3 and IN4. These pins can be connected to any digital pin on the Arduino
Dual Motor Driver Board
Lastly, I used and RC transmitter and receiver to indirectly control the motor speed. I chose to use Channel 3, which is the up and down movement on the left stick. I chose this channel because it is not spring loaded and will not return to the center position. The top pin connects to any digital pin on the Arduino, the middle pin is connected to 5V and the bottom pin is connected to ground.
Radio Control Receiver
Below is the diagram of the breadboard view.
Motor and Receiver System Wiring Diagram
Arduino Code
Setup: In this example I use 6 different digital pins. I set the pin leading from RC receiver to be an Input. The pins leading to the ENA, IN1, and IN2 pins on the motor driver are set to be digital outputs, and the pins connected to the rotary encoder outputs are set to “INPUT_PULLUP.”
I also use the “attachInterrupt” command to interrupt the loop and increment counting functions every time encoder outputs a “CHANGE.” Essentially I am counting the rising and falling edges of each of the encoder outputs. This can only be used with pins 2 and 3 on the Arduino Uno and Nano. If a second motor is needed, one encoder output on each motor will not be used. One encoder output per motor is often enough for most projects.
Loop: I start the loop be reading the RC PWM value using the “pulseIn” command. I write IN1 to “HIGH” and IN2 to “LOW” to establish a motor direction. I then use “if” statements to store the minimum and maximum values that are read from the RC receiver. I use this range to map the current RC PWM value to values between 0 and 255, since this is the range that “analogWrite” uses. This value is then sent to the ENA Pin to ultimately spin the motor.
Lastly, I print the counters.
Functions: I use two functions that simply increment two different variables. These functions are called every time the interrupts are initiated.
You should now be able to control the speed of the motor with the channel 3 joystick on the remote control.
MD101 is pleased to present this post by Brandon Tsuge previously published in the Bored Robot
https://mechanicaldesign101.com/wp-content/uploads/2024/12/2f.-Control-Hardware-for-DC-Motor-and-Encoder.jpg5621000Prof. McCarthyhttps://mechanicaldesign101.com/wp-content/uploads/2016/07/mechanical-design-101LOGOf.pngProf. McCarthy2024-12-07 13:16:452024-12-07 15:39:09Remote Control of a Brushed DC Motor
If you’ve ever wanted to get started with DIY robotics, you’ve probably heard the name Arduino thrown around. Arduino is an Italian made, open-source, electronics platform with incredibly user friendly hardware and software. The modular nature of the hardware and the simplicity of the programming environment makes it ideal for beginners while still having the capabilities for more complex projects.
Most of the time when somebody says they are “using an Arduino,” they most likely mean they are using the Arduino Uno or Arduino Nano.
In simple terms, the Arduino is a mini computer that can perceive the environment through sensors that measure things like light, sound, temperature, distance, etc. It can then use this information to impart change to the physical environment by sending signals to actuators or other hardware. Actuators consist of things like motors, lights, speakers, LCD screens, and much more. The Arduino performs these actions through instructions received in a program, or sketch. These sketches are sent via a USB cable and created using the Arduino integrated development environment (IDE), which is based on the C programming language.
Arduino Communication Diagram
In a nutshell, here are some of the main features of the Arduino:
· Read an analog signal
· Write an analog signal*
· Read a digital signal
· Write a digital signal
· Provide a 5V or 3.3V source
· Provide a ground (0V)
· Easily communicate with your PC via USB
*Arduino can’t truly create an analog signal. It “fakes” it by using pulse width modulation (PWM). I’ll elaborate on this in a future post.
If you are a complete beginner to programming and electrical circuits, I recommend getting the Arduino starter kit (https://amzn.to/2YWt01o). This set comes with over 100 components and an easy to understand project book that teaches fundamental concepts via sample projects. In the upcoming posts, I will be providing tutorials on each of these examples from this book.
MD101 is pleased to present these posts by Brandon Tsuge originally published as The Bored Robot.
https://mechanicaldesign101.com/wp-content/uploads/2024/12/1.Arduino-Nano-Uno.jpg5621000Prof. McCarthyhttps://mechanicaldesign101.com/wp-content/uploads/2016/07/mechanical-design-101LOGOf.pngProf. McCarthy2024-12-07 12:18:452024-12-07 12:35:15How To Get Started With Robotics At Home