Save money on your purchases by earning redeemable points with Progressive Rewards!
The world of electronics can be fun and exciting, but often it can seem quite daunting when you are looking at a wiring diagram and have no idea where to start. Moreover, understanding the code that goes on to a microcontroller can be confusing if you are new to this. Thankfully, we are here to give you the information you need to start your learning journey!
In this article, we will dive into what a microcontroller is by looking at its benefits and features. Then, we will give you a simple project on how to run a linear actuator from a microcontroller, starting with making it extend/retract. Whether you are new to microcontrollers or are an experienced hobbyist who just needs some brushing up, this is the article for you. This article is one of many to come, where we will take a closer look at microcontroller shields, sensor modules, and motor drivers. But let’s start with the basics!
Look to your left and then look to your right. You probably will have seen a handful of things around your house or office that has an integrated circuit (IC) inside – these small silicon-based chips are the brains of your electronic devices. Microcontroller boards will have one or more of these ICs on board along with a bunch of peripherals.
Microcontrollers are small, versatile, inexpensive devices that can be successfully implemented and programmed not only by experienced electrical engineers, but also by hobbyists, students, and professionals from other disciplines.
A microcontroller will generally have the following elements:
A microcontroller is very cost-effective since it can be produced at lower costs than its electromechanical predecessors. Furthermore, development boards, such as the Arduino, allow for quick programming and is ideal for system prototypes. Because the majority of the circuitry is made from integrated circuits, the energy cost of using a microcontroller is much less than if using individual components of a relay-type logic circuit. Lastly, since the typical microcontroller is programmable, it means you can reuse it on another project if needed.
It’s time to put a Progressive Automations linear actuator with a microcontroller to the test and extend/retract! We will walk you through the wiring as well as how the code operates so that you can modify the control of the linear actuator as you please.
Here is what you will need to get started with pairing a microcontroller with a linear actuator. All components can be purchased on the Progressive Automations website:
Thankfully, there is not much wiring that needs to be done because of the shields. This simple wiring makes this project the best beginner's project to learn how to use a microcontroller. Once you have the required components, follow the wiring connections below step-by-step. Use the Arduino pinout image as a reference.
View the full code for this project here.
The code that is understood by the Arduino microcontroller board is C. Multiple libraries have been written, which contain code to simplify the addition of various peripherals, in this case, the LCD (#include <LiquidCrystal.h>).
The first part of the code is the setup of the pins. These pin numbers correlate to the relay connections on the Arduino pins numbers. If you decide to use a different Arduino microcontroller board, ensure these numbers are changed to match which pin you connect the relays to.
The setup loop assigns the relay pins as OUTPUTS and sets the pins to LOW. Additionally, the LCD is sent a few commands to display text and set up the cursor arrows. Within the main loop, the code is constantly checking if any of the buttons on the LCD board have been pressed. In this case, the buttons are connected to the Arduino’s A0 pin. When a button is pressed, the value read by the Arduino will either be close to 100 or close to 255, depending on which buttons were pressed. These values are not always exact, especially if you have additional circuitry connected to the Arduino that could interfere with the signal. Therefore, a threshold value has been included and can be adjusted if the buttons are too sensitive to interference.
If you have the Arduino connected to your computer via USB, you can use the serial monitor on the Arduino IDE to view the output signal from the A0 pin. Simply add the below line of code to the main loop:
Some logic takes place with the read signal to determine if the up or down button was pressed. If the up button was pressed, one relay will be set to high and the other to low. If the down button was pressed, the logic is flipped. The activation and deactivation of relays will cause the actuator to extend/retract.
Now that you know how the code works, you can play around with it by adding additional logic, such as turning on an LED when the actuator extends and turning it off when the actuator retracts. This is fairly simple to do and will require you to set up the pin number, assign the pin as an OUTPUT, and then set that pin to HIGH (digitalWrite command) within the if or else if statement.
Working with an Arduino microcontroller for an actuator, among others, can be quite fun and rewarding. Learning to code on a simple microcontroller for an actuator, especially in the C language, is a great way to build your knowledge and potentially turn your coding skills into a career. Start with the basics and work your way up to more complex projects.
In the coming articles, we will explore various shields that can be used with the Arduino and show you slightly more complex pieces of code. Moreover, we will investigate the use of sensors to control segments of your code to control a linear actuator. If you have any further queries around microcontrollers or connecting a linear actuator to a microcontroller, please don’t hesitate in contacting us!
We have detected your location to be from outside of the US, would you like to go to our Canadian Store?