Smart Security System using Facial Recognition with Raspberry Pi 4

Greeting, and welcome to the next tutorial of our raspberry programming tutorial. In the previous tutorial, we learned how to build a smart attendance system using an RFID card reader, which we used to sign in students in attendance in a class. When it comes to building a face-recognition program on a Raspberry Pi, this tutorial will show you how. Two Python programs will be used in the lesson, one of which is a Training program that analyzes a collection of photographs of a certain individual and generates a dataset. (YML File). The Recognizer application uses the YML script to detect a face and afterward utters the person's name when the face is detected.

Where To Buy?
No.ComponentsDistributorLink To Buy
1BreadboardAmazonBuy Now
2DC MotorAmazonBuy Now
3Jumper WiresAmazonBuy Now
4Raspberry Pi 4AmazonBuy Now

Components

  • Raspberry Pi
  • Breadboard
  • L293 or SN755410 motor driver chip
  • Jumper wires
  • DC motor
  • 5v power supply

A growing number of us already use face recognition software without realizing it. Facial recognition is used in several applications, from basic Fb Tag suggestions to advanced security screening surveillance. Chinese schools employ facial recognition to track students' adherence and behaviour for the first time. Retail stores use face recognition to classify their clients and identify those who have a history of crime. There's no denying that this tech will be all over soon, especially with so many other developments in the works.

How does facial recognition work?

When it comes to facial recognition, biometric authentication goes well beyond simply being able to identify human faces in images or videos. An additional step is taken to identify the person's identity. A facial recognition software compares an image of a person's face to a database to see if the features match another person's. Since facial expressions and hair do not affect the technology's ability to identify matches, it has been built to do so.

How can face recognition be used when it comes to smart security systems?

The first thing you should do if you want to make your home "smart" is to focus on security. Your most prized possessions are housed at this location, and protecting them is a must. You can monitor your home security status from your computer or smartphone thanks to a smart security system when you're outdoors.

Installing a system that is not wireless in your house and signing you up for professional monitoring was traditionally done by a security company. The plot has been rewritten. When setting up a smart home system, you can even do it yourself. In addition, your smart smartphone acts as a professional monitor, providing you with real-time information and notifications.

Face recognition is the ability of a smart camera in your house to identify a person based on their face. Consequently, you will have to inform the algorithm what face goes with what name for face recognition to operate. Facial detection in security systems necessitates the creation of user accounts for family members, acquaintances, and others you want to be identified by the system. Your doors or the inside of your house will be alerted when they arrive.

Face-recognition technology allows you to create specific warning conditions. For example, you can configure a camera to inform you when an intruder enters your home with a face the camera doesn't recognize.

Astonishing advancements in smart tech have been made in recent years. Companies are increasingly offering automatic locks with face recognition. You may open your doors just by smiling at a face recognition system door lock. You could, however, use a passcode or a real key to open and close the smart door. You may also configure your smart house lock to email you an emergency warning if someone on the blacklist tries to unlock your smart security door.

How to install OpenCV for Raspberry Pi 4.

OpenCV, as previously stated, will be used to identify and recognize faces. So, before continuing, let's set up the OpenCV library. Your Pi 4 needs a 2A power adapter and an HDMI cable because we won't be able to access the Pi's screen through SSH. The OpenCV documentation is a good place to learn how image processing works, but I'm not going to go into it here.

Installing OpenCV using pip

pip is well-known for making it simple to add new libraries to the python language. In addition, there is a technique to install OpenCV on a Raspberry Pi via PIP, but it didn't work for me. We can't obtain complete control of the OpenCV library when using pip to install OpenCV; however, this might be worth a go if time is of the essence.

Ensure pip is set up on your Raspberry Pi. Then, one by one, execute the lines of code listed below into your terminal.

sudo apt-get install libhdf5-dev libhdf5-serial-dev

sudo apt-get install libqtwebkit4 libqt4-test

sudo pip install opencv-contrib-python?

How OpenCV Recognizes Face

Facial recognition and face detection are not the same things, and this must be clarified before we proceed. When simply a user's face is detected using Face detection, the program has no clue who that person is. Only the face will be detected in facial recognition software, but the program will also recognize it. At this point, it's pretty evident that facial detection comes before facial recognition. To explain how OpenCV recognizes a person or other objects, I will have to go into detail.

Essentially, a webcam feed is like a long series continuously updating still photos. And every image is nothing more than a jumble of pixels with varying values arranged in a specific order. So, how does a computer software identify a face among all of these random pixels? Trying to describe the underlying techniques is outside the scope of this post, but since we're utilizing the OpenCV library, facial recognition is a straightforward process that doesn't necessitate a deeper understanding of the underlying principles.

Using Cascade Classifiers for Face Detection

We can only recognize a person if we can see it. Detection of an item, including a face, Classifiers are a feature of OpenCV. They are pre-trained datasets that may be utilized to recognize a certain item, such as a face. Classifiers may also detect additional objects, such as the mouth, the eyebrows, the number plate of a vehicle, and smiles.

Alternatively, OpenCV allows you to design your custom Classifier for detecting any objects in images by retraining the cascade classifier. For the sake of this tutorial, we'll be using the classifier named "haarcascade_frontalface_default.xml" to identify faces from the camera. We'll learn more about image classifiers and how to apply them in code in the following sections.

Setup the raspberry pi camera

For the face training and detection, we only need the pi camera, and to install this, insert the raspberry pi camera in the pi camera slot as shown below. Then go to your terminal, open the configuration window using "sudo raspi-config", and press enter. Navigate to the interface options and activate the pi camera module. Accept the changes and finish the setup. Then reboot your RPi.

How to Setup the Necessary Software

First, ensure pip is set up, and then install the following packages using it.

Install dlib: Dlib is a set of libraries for building ML and data analysis programs in the real world. To get dlib up and running, type the following command into your terminal window.

Pip install dlib

If everything goes according to plan, you should see something similar after running this command.

Install pillow: The Python Image Library, generally known as PIL, is a tool for opening, manipulating, and saving images in various formats. The following command will set up PIL for you.

pip install pillow

You should receive the message below once this app has been installed.

Install face_recognition: The face recognition package is often the most straightforward tool for detecting and manipulating human faces. Face recognition will be made easier with the help of this library. Installing this library is as simple as running the provided code.

Pip install face_recognition –no –cache-dir

If all goes well, you should see something similar to the one shown below after the installed software. Due to its size, I used the "—no –cache-dir" command-line option to configure the package without keeping any of its cache files.

Face Recognition Folders

A script named "haarcascade_frontalface_default.xml" is for detecting faces using a Classifier. It will also build a "face-trainner.yml" file using the training script based on the photos found in the face images directory.

Start the face images folder with a collection of face images.

The face images folder indicated above should contain subdirectories with the names of each person to be identified and several sample photographs of them. Esther and x have been identified for this tutorial. As a result, I've just generated the two sub-directories shown below, each containing a single image.

You must rename the directory and replace the photographs with the names of the people you are identifying. It appears that a minimum of five images for each individual is optimal. However, the more participants, the slower the software will run.

Face trainer program

Face Trainer.py is a Python software that may be used to train a new face. The purpose of the software is to access the face photographs folder and scan for faces. As soon as it detects a face, it crops it, turns it to grayscale, and saves it in a file named face-trainner.yml using the face recognition package we had previously loaded. The information in this script can be used to identify the faces later. In addition to the whole Trainer program provided at the conclusion, we'll go over some more critical lines.

The first step is to import the necessary modules. The cv2 package is utilized to process photos. The NumPy library can be used for image conversion, the operating system package is used for directory navigation, and PIL will be used to process photos.

import cv2

import numpy as np

import os

from PIL import Image

Ensure that the XML file in question is located in the project directory to avoid encountering an issue. The LBPH Facial recognizer is then constructed using the recognizer parameter.

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

recognizer = cv2.createLBPHFaceRecognizer()

Face_Images = os.path.join(os.getcwd(), "Face_Images")

In order to open all of the files ending in.jpg,.jpg, or .png within every subfolder in the face images folder, we must traverse the tree with for loops. In a variable named path, we record the path to every image, and in a variable named person name, we store the file location name (the name of the user who uploaded the images).

For root, dirs, files in os.walk(Face_Images):

for file in files: #check every directory in it

if file.endswith("jpeg") or file.endswith("jpg") or file.endswith("png"):

path = os.path.join(root, file)

person_name = os.path.basename(root)

As a result, in case the name of the person changes, we increase a variable named Face_ID that will allow us to have a unique Face_ID for each individual.

if pev_person_name!=person_name:

Face_ID=Face_ID+1 #If yes increment the ID count

pev_person_name = person_name

Because the BGR values may be ignored, grayscale photos are simpler for OpenCV to deal with than colourful ones. We transform the data to grayscale and afterwards lower the image size by 50% so that all the pictures are the same size. To avoid having your face cut out, place it in the centre of the photo. To get a numerical number for these photos, transform them into NumPy arrays. Afterwards, a classifier identifies a face in a photo and saves the results in variable named faces.

Gery_Image = Image.open(path).convert("L")

Crop_Image = Gery_Image.resize( (550,550) , Image.ANTIALIAS)

Final_Image = np.array(Crop_Image, "uint8")

faces = face_cascade.detectMultiScale(Final_Image, scaleFactor=1.5, minNeighbors=5)

Our Area of Attention will be the portion of the image where the face may be found after being cropped. It will be utilized to train the face-recognition system in the ROI area. Every area of attention face must be appended to a variable named x train. We then feed the recognizer with our training data using the area of attention values and Face ID data. The information gathered will be archived.

for (x,y,w,h) in faces:

roi = Final_Image[y:y+h, x:x+w]

x_train.append(roi)

y_ID.append(Face_ID)

 

recognizer.train(x_train, np.array(y_ID))

recognizer.save("face-trainner.yml")

You'll notice that the face-trainner.yml script is modified whenever you run this program. If you make any modifications to the photographs in the Face Images folder, ensure to recompile this code. Debugging purposes include printing out the Face ID, name of the path, name of a person, and NumPy arrays.

Face recognition program

We can begin using our trained data to identify people now that it has been prepared. We'll use a USB webcam or pi camera to feed video into the Face recognizer application, turning it into an image. Once we've found the faces in those images, we'll find similarities to all of our previously developed Face IDs. Finally, we output the identified person’s name in boxes around their face. Afterwards, the whole program is presented, and the explanation is below.

Import the required module from the training program and use the classifier because we need to do more facial detection in this program.

import cv2

import numpy as np

import os

from time import sleep

from PIL import Image

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

recognizer = cv2.createLBPHFaceRecognizer()

The people listed in the folder should be entered in the variable named labels. Insist on performing each step in the same order. It is "Esther" and "Unknown" in my situation.

labels = ["Esther", "Unknown"]

We need the trainer file to detect faces, so we import it into our software.

recognizer.load("face-trainner.yml")

The camera provides the video stream. It's possible to access any second pi camera by replacing 0 with 1.

cap = cv2.VideoCapture(0)

In the next step, we separate the footage into images and transform it into grayscale, and afterwards, we search for a face in the photo. To save the area of attention grey image, we must first detect the face and then crop the image to remove them.

ret, img = cap.read()

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)

for (x, y, w, h) in faces:

roi_gray = gray[y:y+h, x:x+w]

id_, conf = recognizer.predict(roi_gray)

It informs us how sure the program is in its ability to identify the person. We write the code below to get the person's name based on their Identification number. A square should be drawn around the user's head, written outside their name.

if conf>=80:

font = cv2.FONT_HERSHEY_SIMPLEX

name = labels[id_]

cv2.putText(img, name, (x,y), font, 1, (0,0,255), 2)

cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)

We must playback and afterwards break the video stream we just evaluated, which is done by pressing a wait key.

cv2.imshow('Preview',img)

if cv2.waitKey(20) & 0xFF == ord('q'):

break

While running this application, ensure the Raspberry is linked to a display via HDMI. A display with your video stream and the name will appear when you open the application. There will be a box around the face identified in the video feed, and if your software recognizes the face, it displays that person’s name. As evidenced by the image below, we've trained our software to identify my face, which shows the recognition process in action.

The face recognition code

import cv2

import numpy as np

import os

from PIL import Image

labels = ["Esther", "Unknown"]

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

recognizer = cv2.createLBPHFaceRecognizer()

recognizer.load("face-trainner.yml")

cap = cv2.VideoCapture(0)

while(True):

ret, img = cap.read()

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5) #Recog. faces

for (x, y, w, h) in faces:

roi_gray = gray[y:y+h, x:x+w]

id_, conf = recognizer.predict(roi_gray)

if conf>=80:

font = cv2.FONT_HERSHEY_SIMPLEX

name = labels[id_]

cv2.putText(img, name, (x,y), font, 1, (0,0,255), 2)

cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)

cv2.imshow('Preview',img)

if cv2.waitKey(20) & 0xFF == ord('q'):

break

cap.release()

cv2.destroyAllWindows()

Face detection code

import cv2

import numpy as np

import os

from PIL import Image

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

recognizer = cv2.createLBPHFaceRecognizer()

 

Face_ID = -1

pev_person_name = ""

y_ID = []

x_train = []

Face_Images = os.path.join(os.getcwd(), "Face_Images")

print (Face_Images)

for root, dirs, files in os.walk(Face_Images):

for file in files:

if file.endswith("jpeg") or file.endswith("jpg") or file.endswith("png"):

path = os.path.join(root, file)

person_name = os.path.basename(root)

print(path, person_name)

if pev_person_name!=person_name:

Face_ID=Face_ID+1

pev_person_name = person_name

Gery_Image = Image.open(path).convert("L")

Crop_Image = Gery_Image.resize( (550,550) , Image.ANTIALIAS)

Final_Image = np.array(Crop_Image, "uint8")

faces = face_cascade.detectMultiScale(Final_Image, scaleFactor=1.5, minNeighbors=5)

print (Face_ID,faces)

for (x,y,w,h) in faces:

roi = Final_Image[y:y+h, x:x+w]

x_train.append(roi)

y_ID.append(Face_ID)

recognizer.train(x_train, np.array(y_ID))

recognizer.save("face-trainner.yml")

DC motor circuit

Since the "How to operate DC motor in Rpi 4" guide has covered the basics of controlling a DC motor, I won't provide much detail here. Please read this topic if you haven't already. Check all the wiring before using the batteries in your circuit, as outlined in the image above. Everything must be in place before connecting your breadboard's power lines to the battery wires.

Testing

To activate the motors, open the terminal because you'll use the Python code-writing program called Nano in this location. For those of you who aren't familiar with the command-line text editor known as Nano, I'll show you how to use some of its commands as we go.

This code will activate the motor for two seconds, so try it out.

import RPi.GPIO as GPIO

from time import sleep

GPIO.setmode(GPIO.BOARD)

Motor1A = 16

Motor1B = 18

Motor1E = 22

GPIO.setup(Motor1A,GPIO.OUT)

GPIO.setup(Motor1B,GPIO.OUT)

GPIO.setup(Motor1E,GPIO.OUT)

print "Turning motor on"

GPIO.output(Motor1A,GPIO.HIGH)

GPIO.output(Motor1B,GPIO.LOW)

GPIO.output(Motor1E,GPIO.HIGH)

sleep(2)

print "Stopping motor"

GPIO.output(Motor1E,GPIO.LOW)

GPIO.cleanup()

The very first two lines of code tell Python whatever the program needs.

The RPi.GPIO package is what the first line is looking for. The RPi GPIO pins are controlled by this module, which takes care of all the grunt work.

It is necessary to delay the script for a few seconds to provide the package time to operate, therefore leaving a motor to run for a while.

The method set mode is used to leverage the RPi's board numbers. We'll tell Python that the pins 16 through 22 correspond to the motors.

Pin A is used to steer the L293D in one way, and pin B is used to direct it in the opposite direction. You can turn on the motor using an Enable pin, referred to as E, inside the test file.

Finally, use GPIO.OUT to inform the RPi that all these are outputs.

The RPi is ready to turn the motor after the software is set up. After a 2-second pause, some pins will be turned on and subsequently turned off, as seen in the code.

Save and quit by hitting CTRL-X, and a confirmation notice appears at the bottom. To acknowledge, tap Y and Return. You can now run the program in the terminal and watch as the motor begins to spin up.

sudo python motor.py

If the motor doesn't move, check the cabling or power supply. The debug process might be a pain, but it's an important phase in learning new things!

Now turn in the other direction.

I'll teach you how to reverse a motor's rotation to spin in the opposite direction.

There's no need to touch the wiring at this point; it's all Python. Create a new script called motorback.py to accomplish this. Using Nano, type the command:

./script

Please type in the given program:

import RPi.GPIO as GPIO

from time import sleep

GPIO.setmode(GPIO.BOARD)

Motor1A = 16

Motor1B = 18

Motor1E = 22

GPIO.setup(Motor1A,GPIO.OUT)

GPIO.setup(Motor1B,GPIO.OUT)

GPIO.setup(Motor1E,GPIO.OUT)

print "Going forwards"

GPIO.output(Motor1A,GPIO.HIGH)

GPIO.output(Motor1B,GPIO.LOW)

GPIO.output(Motor1E,GPIO.HIGH)

sleep(2)

print "Going backwards"

GPIO.output(Motor1A,GPIO.LOW)

GPIO.output(Motor1B,GPIO.HIGH)

GPIO.output(Motor1E,GPIO.HIGH)

sleep(2)

print "Now stop"

GPIO.output(Motor1E,GPIO.LOW)

GPIO.cleanup()

Save by pressing CTRL, then X, then Y, and finally Enter key.

For reverse compatibility, we've set Motor1A low in the script.

Programmers use the terms "high" and "low" to denote the state of being on or off, respectively.

Motor1E will be turned off to halt the motor.

Irrespective of what A is doing; the motor can be turned on or off using the Enable switch.

Take a peek at the Truth Table to understand better what's going on.

When Enabled, only two states allow the motor to move; A or B is high, and not both high at the same time.

Putting it all together

At this point, we have designed our face detection system and the dc motor control circuit; now, we will put the two systems to work together. When the user is verified, the dc motor should run to open the cd rom drive and close after a few seconds.

In our verify code, we will copy the code below to spin the motor in one direction “open the door” when the user is verified. We will also increase the time to 5 seconds to simulate the door's time to open for the user to get through. This also allows the motor to spin long enough to open and close the cd room completely. I would also recommend putting a stopper on the cd room door so that it doesn't close all the war and get stuck.

if conf>=80:

font = cv2.FONT_HERSHEY_SIMPLEX

name = labels[id_] #Get the name from the List using ID number

cv2.putText(img, name, (x,y), font, 1, (0,0,255), 2)

#place our motor code here

GPIO.setmode(GPIO.BOARD)

Motor1A = 16

Motor1B = 18

Motor1E = 22

 

GPIO.setup(Motor1A,GPIO.OUT)

GPIO.setup(Motor1B,GPIO.OUT)

GPIO.setup(Motor1E,GPIO.OUT)

Print("Openning")

GPIO.output(Motor1A,GPIO.HIGH)

GPIO.output(Motor1B,GPIO.LOW)

GPIO.output(Motor1E,GPIO.HIGH)

sleep(5)

print("Closing")

GPIO.output(Motor1A,GPIO.LOW)

GPIO.output(Motor1B,GPIO.HIGH)

GPIO.output(Motor1E,GPIO.HIGH)

sleep(5)

print("stop")

GPIO.output(Motor1E,GPIO.LOW)

GPIO.cleanup()

cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)

Output

The advantages of face recognition over alternative biometric verification methods for home security

An individual's biometric identity can be verified by looking at various physical and behavioural characteristics, such as a person's fingerprint, keystrokes, facial characteristics, and voice. Face recognition seems to be the winner because of the precision, simplicity, and lack of contact detection.

Face-recognition technology will continue and will get better over time. The tale has evolved, and your alternatives have grown due to smart tech.

What are the advantages of employing Facial Recognition when it comes to smart home security?

Using an RPi as a surveillance system means you can take it with you and use it wherever you need it.

  1. High accuracy rate

For the most part, the face-recognition software employed in security systems can reliably assess whether or not the individual attempting entry matches your record of those authorized to enter. On the other hand, certain computer programs are more precise when it comes to identifying faces from diverse angles or different countries.

Concerned users may be relieved to learn that some programs have the option of setting custom confidence criteria, which can significantly minimize the likelihood of the system giving false positives. Alternatively, 2-factor authentication can be used to secure your account.

  1. Automation

When your smart security system discovers a match between a user and the list of persons you've given access to, it will instantly let them in. Answering the doorbell or allowing entry isn't necessary.

  1. Smart integration

Face recognition solutions can be readily integrated into existing systems using an API.

Cons of Facial Recognition

  1. Privacy of individuals and society as a whole is more at risk

A major drawback of face recognition technology is that it puts people's privacy at risk. Having one's face collected and stored in an unidentified database does not sit well with the average person.

Confidentiality is so important that several towns have prohibited law enforcement from using real-time face recognition monitoring. Rather than using live face recognition software, authorities can use records from privately-held security cameras in certain situations.

  1. can infringe on one's liberties

Having your face captured and stored by face recognition software might make you feel monitored and assessed for your actions. It is a form of criminal profiling since the police can use face recognition to put everybody in their databases via a virtual crime lineup.

  1. It's possible to deceive modern technology.

Face recognition technology can be affected by various other elements, including camera angle, illumination, and other aspects of a picture or video. Facial recognition software can be fooled by those who do disguises or alter their appearance.

Conclusion

This article walked us through creating a complete Smart Security System using a facial recognition program from the ground up. Our model can now recognize faces with the help of OpenCV image manipulation techniques. There are several ways to further your knowledge of supervised machine learning programming with raspberry pi 4, including adding an alarm to ring whenever an individual's face is not recognized or creating a database of known faces to act like a CCTV surveillance system. We'll design a security system with a motion detector and an alarm in the next session.

Voice Control Project using Raspberry Pi 4

Welcome to the next tutorial of our Raspberry Pi programming course. Our previous tutorial taught us to make a button-controlled "music box" that plays different sounds depending on which buttons are pressed. In this lesson, we will configure our raspberry pi for voice control.

Where To Buy?
No.ComponentsDistributorLink To Buy
1BreadboardAmazonBuy Now
2DC MotorAmazonBuy Now
3Jumper WiresAmazonBuy Now
4Raspberry Pi 4AmazonBuy Now

What will you learn?

Like the Amazon Echo, voice-activated gadgets are becoming increasingly popular, but you can also construct your own with a Raspberry, a cheap USB mic, and some appropriate software. Simply speaking to your Raspberry Pi will allow you to search YouTube, view websites, activate applications, and even answer inquiries.

What will you need?

Because the Raspberry Pi lacks a soundcard or audio port, this project requires a USB microphone or a camera with a built-in microphone. If your mic only has an audio jack, look for an affordable USB soundcard that connects to a USB port on one side and has a headphone and mic output on the other.

Getting started

For the Raspberry Pi, there are various speech recognition programs. We're utilizing Steve Hickson's Pi AUI Toolkit for this project since it is powerful and straightforward to set up and operate. You may install a variety of programs using the Pi AUI Suite. The first question is whether or not the dependencies should be installed. These are the files that the Raspberry Pi requires to work with voice commands, so pick Yes, then press Enter to agree.

Following that, you'll be asked if you wish to download the PlayVideo software, which allows you to open and play video content using voice commands. If you select Y, you'll be prompted to enter the location of your media files, such as /home/pi/Videos. It's worth noting the upper-case letters are crucial in this scenario. The application will tell you if the route is incorrect.

Next, you'll be asked if you wish to download the Downloader application, which explores the internet for files and downloads them for you automatically. If you select Yes, you will be prompted to enter an address, port, password, and username. If you're not sure, press Return to choose the default settings in each scenario for now.

Install the Google Texts to Speech Service if you require your raspberry pi to read the contents of the text files. Since it communicates to Google servers to translate text into speech, the Raspberry Pi must be hooked up to the internet to utilize this service.

You'll require a google user account to install this. The installation requests your username—press Return after completing this step. The Google password is then requested. Return to the previous page and type this.

You may also use the installer to download Google Voice Commands. This makes use of Google's speech-to-text technology. To proceed, you must enter your Google login and password once again.

Regardless of whether you choose Google-specific software or not, the program will ask if you wish to download the YouTube scripts. These technologies allow you to say something like "play pi tutorial," An appropriate video clip will be played—press Return after typing a new welcome. You can also enable the silent flag to prevent the Raspberry Pi from responding verbally.

Lastly, the software installs the Voice command, which includes some of the more helpful scripts, such as the ability to deploy your internet browser by simply saying "internet."

Basic voice commands used

Youtube: When you say "YouTube" followed by a title tag, a youtube clip of the first related YouTube clip appears. "I'm feeling lucky" is comparable to "I'm feeling lucky" on google. Say "YouTube" followed by the title of the video you want to watch, for example, "YouTube fluffy kittens."

Internet: Your internet browser is launched when you use the word "internet." Midori is the internet browser for Rpi by default, but you may alter that.

Download: When you say "download," followed by a search query, the Pirate Bay webpage searches for the files in demand. For instance, you can say "Download Into the badlands" to get the most current edition of the movie.

Play: This phrase utilizes the in-built media player to open an audio or video file. For instance, "Play football.mp4" would play the file "football.mp4" from the media directory you chose during setup, like /home/pi/movies.

Show me: When you say "show me," a directory of your choice appears. The command defaults to not going to a valid root directory, so you'll need to modify your configuration so that it points to one. For instance, show me==/Documents.

You'll be asked if you want the Voice command to set things up automatically. If an issue occurs at this point, run the following command to download and install the required software.

Configuring the Raspberry Pi master voice

After installing the Voice command application, you may want to perform a few basic adjustments to the setup to fine-tune it. Execute the following command from your Raspberry Pi's Terminal or via SSH.

Following that, you'll be asked several yes/no questions. The first question is whether you wish to enable the continuous flag permanently. The Voice command application, in clear English, asks if you would want to listen to your voice commands constantly every time you launch it.

For the time being, choose Yes. After that, you'll be asked if you wish the Voice command application to set the verify flag permanently. If you select Y, the application will expect you to pronounce your keyword (the default setting is "Pi") before responding to requests.

If you like the RPi to monitor continually but not act on all words you say, this is a good option.

The next step asks if you wish to enable the ignore flag permanently. If Voice command receives a command that isn't expressly listed in the config file, it will try to find and launch a program from your installed apps. For example, if you say "leafpad," a notepad tool, the Voice command looks for it and starts it even if you don't tell it to.

This is a functionality that we would not recommend anyone to enable. Because you're using Voice command at the SuperUser level, there's a significant danger that you'll accidentally issue a command to the Raspberry Pi that will harm your files. If you wish to set up other programs to function with the Voice command, you can update the configuration file for each scenario.

The voice command afterward asks if you want to permanently enable the silence flag so that it doesn't respond verbally whenever you talk. As you see fit, select yes or no. After that, you'll be prompted to adjust the default voice recognition timeframe. If Pi is having problems hearing your commands, you should modify this.

If you select Yes, you'll be prompted to enter a number; this is the number of seconds that the Raspberry Pi will listen for a voice command; the default for RPI is 3. The application then allows you to customize your text-to-speech choices. Before you do this, make sure your volume is turned up. The application attempts to speak something and then asks if you heard it.

When the system receives your keyword, it responds with "Yes, sir?" as the default response. To modify this, select Yes in the following prompt, then enter your chosen response, for example, "Yes, ma'am?" Once you're finished, hit the enter key. The program will replay the assigned response to check that you are satisfied with the outcome.

Whenever the program receives an unidentified command, the method is the same as the default response. "Received the wrong command" is set as the default response, but you could still alter it to something more friendly by typing yes, then your desired response, like, "The command is not known."

You now have the option of configuring the voice recognition parameters. This will check to see if you have a suitable mic. The Pi will then ask you if you want it to test your sound threshold using the Voice command.

Check for background sound, then press Yes, then press enter key. It then requests you to say a command to ensure that it is using the correct audio device. Type Yes to have the application automatically select the appropriate audio threshold for your Rpi.

Lastly, the Raspberry Pi will ask if you wish to modify the default voice command term ("Pi"). After that, type Y and your new keyword, then press enter when you're finished.

After that, you'll be requested to say your keyword to acclimate the RPi to your voice. If everything looks good, press Y to finish the setup. Start with the fundamental commands outlined above when using the Voice command software.

Once you've mastered these commands, use the following line of code to exit the application and, if desired, change your config file.

Vexing sounds and how to get rid of them

The Raspberry Pi's technology is still a work-in-progress, so not everything you speak may be recognized by the program.

Stay near the mic and talk slowly and clearly to maximize your chances of being heard by the program if you still have difficulties understanding. Launch the terminal or log in through SSH to your Raspberry Pi and type the following command to access your audio settings to change your audio preferences.

Hit the F4 button on the keyboard to select audio input, then the F6 key to exit. Select your input device, the mic with the arrow up or down keys, then press Enter key. To change the mic's volume, push it up using the up-arrow key to maximum (100).

If your device isn't identified at all, it may require more current than a universal serial bus port on a Raspberry Pi can supply. A powered universal serial bus hub is the ideal solution for this.

 

If you have difficulty connecting after installing the Download application, please ensure that connection to The Pirate Bay site is not limited.

To download the files, you'll also require a BitTorrent application for your RPi, such as transmission. To install this, launch your terminal or access your RPi through SSH and type the following command:

The Transmission homepage has instructions about getting started and utilizing the application. You should always download files that have permission from the copyright holder.

Please remember that whatever you speak and any text documents you provide are transferred to Google servers for translation if you use Google text or speech Commands.

Google maintains that none of this information is kept on its servers. Even if this is the case, any data communicated through the worldwide web can be decrypted by any skilled third party or a hacker. Google, however, encrypts your connection to minimize the risk of this happening.

If you like this voice command tool, you might want the program to launch automatically every time the Rpi is powered on. If this is the case, launch the terminal from your RPi or access it via SSH and execute the command below:

The above command opens the script that controls which programs run whenever your Raspberry Pi is booted. By default, this script is doing nothing. Type the following line of code directly above the one reading exit 0:

To save any changes, use Ctrl+X, enter yes, and press enter key. At this point, you can restart the Raspberry Pi to ensure that it is working.

Launch your Rpi terminal, type the command below, and press enter to see a list of active processes.

How can we reduce vexing noise?

Noise from air conditioners and heaters can damage your audio and make it impossible for the program to understand what you're saying. The only other alternative is to turn these systems off during recording unless the entire system is redesigned to be more acoustically friendly. However, upon listening to the audio, it becomes clear and annoying.

Computer hardware cooling fans are also sources of mechanical noise. These can be disabled manually and for a limited period. Besides that, try isolating the disturbance in another space or utilizing an isolation box as an alternative.

Conclusion

We learned how to configure our raspberry pi for voice control. We also looked at a few basic commands used to control the raspberry pi and the software used. However, In the following tutorial, we will learn how to tweet on Raspberry pi.

Smart Coffee Vending Machine using Arduino

Hello geeks, Welcome to our new project. As most readers have already seen the coffee vending machine or maybe you are drinking coffee while reading this article and if you are a tinker or a geek, it must have come to your mind how to make a coffee vending machine on your own. In today's tutorial, we are going to learn how to make a Smart Coffee Vending Machine using Arduino with Proteus Simulation for the same.

We can use this project for an engineering project’s showcase for electronics, electrical engineering students, and can be used in offices as well.

Coffee is the second most popular drink in the world and it is one of the oldest beverages of the world. According to Wikipedia, more than 2 billion cups of coffee are consumed every day in the whole world. As engineers or working professionals, we all know how coffee is very important for us. Having a good coffee makes our day better and refreshes the mood. Research shows coffee drinkers tend to live longer but when keeping it in moderate consumption. And making a good coffee is one of the most skillful jobs and time-consuming processes as we want our coffee in minutes. Now here our project comes to the picture, this smart coffee vending machine can make a good coffee in a couple of minutes. There are various flavors of coffee and our smart coffee vending machine can provide us with 4 different flavors which are the most commonly loved such as Latte, Cappuccino, Espresso, and Cafe Mocha. Here's the video demonstration of this project:

Where To Buy?
No.ComponentsDistributorLink To Buy
1DC MotorAmazonBuy Now
2LCD 20x4AmazonBuy Now
3Arduino UnoAmazonBuy Now

Software to Install:

As we are going to design this project using Proteus Simulation, instead of using real components. As in the simulation, we can figure out the issue which may occur while working on real components and that can damage our components.

Proteus is the software for simulation and designing electronics circuits. As Proteus software has a big database of electronics components but still it does not have few modules in it like Arduino boards or LCD modules etc.

So we have to install the libraries, which we are going to use in this project:

  • Arduino Library for Proteus: We have to add the Arduino boards to the Proteus components list.
  • LCD Library for Proteus: We have to add the LCD module to Proteus Suite.
You can download this whole project for example Proteus Simulation and Arduino Code, by tapping the below button

Smart Coffee Vending Machine using Arduino

These are required components for Smart Coffee Vending Machine, as follows:

  • 20X4 LCD display: It is used to display user-related messages like the state of the vending machine.
  • Arduino UNO: It is used as the brain of our project. All operations and decision-making will be done using this microcontroller.
  • DC motor: It is used for dispensing the ingredients of coffee and the mixer.
  • Buttons: It is used as a user interaction option.

As a suggestion, whenever we make a project, it should be like a product, as it should be user friendly and interactive, so considering that we have used an LCD module to display the messages related to available coffee flavors and their individual prices so that users can easily select them using buttons and DC motors to pour the ingredients related to coffee like water, sugar, coffee powder, and milk, and a mixer for blending the coffee.

We have connected the LCD using an I2C GPIO expander as we have limited GPIO pins to connect other peripherals with Arduino UNO. I2C Gpio expander requires only two pins as we know that I2C uses SCL(Serial Clock) and SDA(Serial Data) pins for communication.

Components Needed:

  1. Arduino UNO
  2. LCD display
  3. 4 Buttons
  4. 8 Motors
  5. PCF8574

Components Details

Arduino UNO:

We can use any Arduino development board but here in this project, we have used an Arduino UNO board.

  • Arduino UNO is one of the programmable, open-source microcontroller boards of the Arduino family.
  • It contains an Atmel’s Microchip ATMega328 or ATMega328P microcontroller which has Harvard architecture 8-bit RISC processor core and 32 KB flash memory.
  • Arduino UNO comprises 14 digital I/O pins out of which 6 are PWM pins as well and 6 Analog I/O pins with 10 bits resolution(0-1024).
  • Arduino UNO has only 1 hardware UART pin(but we can use other pins also for UART communication using SoftwareSerial library in Arduino), 1 I2C, and 1 SPI.

PCF8574:

We have used this IC as a GPIO expander for our project as we have restrictions on the availability of GPIO pins in Arduino UNO.

  • It is an 8-bit I/O, silicon-based CMOS GPIO expander.
  • It can be used to write data on the pins and also can read data on those pins.
  • It uses the I2C protocol for communication with the master device.
  • As we know that I2C protocol uses the slave address to send or receive data from slaves, so for that it has 3 pins A0, A1, A2 for setting the slave address.
  • Slave address for PCF8574 starts from 0x20 to 0x27. That means we can add only 8 PCF8574 IC directly to a master controller.
  • The following image explains the logic of the slave address of PCF8574.
  • It is used for connection for the LCD module with Arduino UNO in our project.
  • If you want to learn more about IC PCF8574, you can refer to the datasheet using the following URL: PCF8574 Datasheet

LCD display

The LCD display is used to show the user-related messages in this project.

  • LCD is a short form of Liquid Crystal Display which is basically built using Liquid Crystal technology.
  • There are different sizes of LCDs available, in this project we have used 20X4 size.
  • Here 20X4 signifies that it can display 80 ASCII characters at a time.
  • There are 16 pins in the LCD. We will not use every pin of LCD in this project.
  • It has 8 data pins, 1 Read/ Write select pin, 1 Register mode pin, 1 Enable pin, 2 pins for backlight, and 2 pins for power supply, 1 contrast control pin.
  • There are mainly two types of register in the LCD: Command Register and Data Register.
  • When we set the RS(Register Select) pin to logic High then it will select the data register mode and in logic Low, it will select the command register.
  • To display the data on LCD we will set the RS pin to logic High.

Proteus Simulation of Smart Coffee Vending Machine :

Now, it's time to start designing the Proteus Simulation of our Smart Coffee Vending Machine.
  • Most importantly, ensure that Proteus is installed on your PC and download all the required libraries for Proteus ahead.
  • For this project, we are going to need libraries of Arduino and LCD modules.
  • Make sure that you have read about how to use libraries in Proteus software.
Let’s create a new project, open the new project in Proteus and import all the required components which we are going to use, and place them within the working area.
  • We need the following components, so select all of them from the Proteus component library.

Circuit Diagram and Working:

  • Now let’s design our circuit, first place all the selected components in the Proteus Workplace, as shown in the image below:
  • We will start connecting the LCD module and PCF8574, as we are using only 4-data pin-mode of LCD.
  • After that, we will start the GPIO expander PCF8574 I2C connections, connect the SDA, SCL pins of PCF8574 to Arduino UNO’s SDA, SCL pins which are A4, A5 pins of the development board.
  • As we know, we have to set the slave address of PCF8574 using A0, A1, A2 pins. And in this project we are going to use the slave address 0x20, therefore for that, we have to connect all pins to the ground. (As we have already seen in the above PCF8574 addressing image)
  • In the next step, we are going to connect the buttons to Arduino digital pins D2, D3, D4, D5 as "Latte", "Cappuccino", "Espresso", "Cafe Mocha" flavors respectively and another terminal of the buttons is connected to ground. As we are going to use the buttons inactive low condition which means, when we press the button it will give us a logical LOW state.
  • There may be a doubt in your mind why we have not used any PULL-UP resistors with buttons because we will handle that in our code. Arduino UNO comes with an internal PULL-UP resistor of 20-50 KOhms.
  • Now connect the dc motors for each container, Water, Coffee, and Sugar container’s motors are connected with Arduino’s digital pins D10, D12, D11 respectively. Connect the coffee outlet motors for each type of Latte, Cappuccino, Espresso, Cafe Mocha with digital pins D6, D7, D8, D9 respectively. And at last, connect the mixer with the D13 pin.
  • As we have mostly completed the wiring part, the first thing which we must make sure of before going to start our simulation is that all components should have adequate power supply and ground. And ground must be common in the whole circuit.

Now we hope you have understood the connections and you have already done it, so it is time to move to the coding part of our project.

Arduino Code for Smart Coffee Vending Machine

If you already know about the syntax and structure of Arduino sketch, it's a good thing, but if you have not been familiarized yet, no need to worry, we will explain it to you step-by-step.

Arduino coding language mostly follow the syntax and structure of C++ programming language, so if you are familiar with C++, then it would be like a cup of cake for you to understand the code but still if you don’t have any background knowledge, you don’t have to worry again, we have your back.

Arduino Coding follows a strict structure, it has mainly two sections. we have to write our code in those two functions.

  • void setup()
  • void loop()

As we are going to explain the Arduino code, it would be easy to understand if you have opened the code in the Arduino IDE already.

Declaration code:

  • When we start our code, we will first include all the required libraries which we are going to use in this project.
  • So our first step would be to download the required libraries if they are already not pre-installed in the Arduino IDE.
  • Mainly we will use only two libraries, one for LCD display and the other for I2C communication.
  • And I2C related functions come in the Wire library which will be pre-installed in Arduino ID, we don't have to install it explicitly.
  • For the LCD module, we will use the Liquid Crystal_I2C library that we have to install.
  • We can install libraries related to Arduino from the Arduino IDE by going to ‘Sketch > Include Library > Manage Library’. Now in the library manager, we can search for our required libraries. We can install the libraries using zip files also.
  • >> Now, as we have installed all the required libraries. Let’s include them in our sketch.
  • After that, we will define the pins which we are going to use in our project.
  • We have to define them globally so that we can use them in all functions.
  • You must be having a doubt why we have not defined pins for I2C.
  • Because those pins are pre-defined in the Wire library, we can not assign any other pins for I2C communication.
  • Now we will define and declare all the variables which are required in our project.
  • There is an array for the price of a coffee with the size of 4, as we will only provide only 4 types of coffees and a string type variable for storing the name of flavors of coffee.

Arduino Setup() Function:

In this Arduino Setup() function, we will write a section of code that will only run once.
  • So mostly we will write the declarations, define the type of pins and initialize the peripherals such as the LCD module.
  • We want to take user input from the buttons therefore we will declare them as INPUT type.
  • We have not connected PULL UP resistors in buttons as you have read above, we will handle that in the code therefore we have declared it as INPUT_PULLUP mode.
  •  We have declared motor pins as OUTPUT mode because we want to control the motors.
  • After that we will initialize the LCD module then we will turn on the backlight of LCD, set the cursor to 0,0 index and using ‘lcd.print()’, we will print the welcome message on the LCD module.
  • In the setCursor function, the first argument is used for X-Axis and the second argument is for Y-Axis.
  • It will display the welcome message for 1 sec as we have given a delay for 1000 milliseconds after we clear the display.

Arduino Loop() Function:

Arduino Loop function runs after the the ‘void setup()’ function.
  • In this section, we will write the code which is required to run in a continuous loop. So we will write our main application code here.
  • So when the code reaches the void loop section, first we will display the flavor and the price of the coffee on LCD display as we want to show the user what type of coffee our vending machine makes and the price of those individually.
>> Now we will write the section for reading the user input from the buttons. As we have set that the condition will be true when the button will be logic LOW state. >> Now when the user will press the button, the state of the button’s pin state will be changed to logic LOW state and then our ‘if condition’ will be true and code and our operation will enter in the ‘if condition’ section. >> Here we will display to the user the current process stage of the coffee making. So we will clear the LCD display and then set the cursor to 0,0 index. After that we will display the message for collecting the ingredients.
  • As we have not cleared the display, it will display the same message.
  • After 1 second delay, we will start the water container motor for pouring the water for 2 seconds.
  • Thereafter we will set the water’s container pin to LOW and Sugar’s container motor pin to HIGH for 2 seconds, similarly for the coffee’s container pin.
  • Now we will start the motor for the selected flavor of coffee for 2 seconds and then stop it.
  • As now our selected coffee is getting ready so we will display the message for the same.
  • To display any new message, we have to clear our display with pre-occupied text.
  • Now we will start the mixer motor for 10 seconds to mix all the poured ingredients.
>> Now our selected coffee is ready. So we will clear the LCD display and set the cursor, and will print the message regarding the prepared coffee with the price of it.

Results/Working:

  • Below is the Flow diagram of coffee vending machine:
  • Let’s understand the code with an example, we will go with the starting step.
  • Power ON the device, the machine will display the welcome message that you can change from that code as per your choice.
  • That message will be shown for 1 second thereafter it will clear the display.
  • Now it will display the type of coffee as "Latte", "Cappuccino", "Espresso", "Cafe Mocha" and their respective prices.
  • Let’s suppose, the user wants to have a Latte today, so he/she will press the button for the same, thereafter our coffee-making process will start.
  • The first LCD display will show the message “Wait a Moment Collecting Ingredients” and it waits for 1 second.
  • Thereafter it will start pouring the water for 2 seconds, then it will stop that motor.
  • After that, it will start to pour sugar for 2 seconds, then stop that motor.
  • At last, it will start to pour the coffee for 2 seconds, then stop that motor.
  • It will start the motor of the selected type of coffee to dispense the coffee to the container and then it will wait for 1 second.
  • Now LCD will display the message for coffee getting ready as "Wait a Moment Your’s Rich Latte is getting ready…” as the user has selected Latte that’s why it shows “Latte is getting ready… “.
  • Now we will start the mixer to mix all the ingredients for 10 seconds.
  • Again we will clear the LCD display to show the message for prepared coffee as “ Your's Rich Latte is ready. Please Collect it Your's Amount - 5/-”.
  • Then it waits for 5 seconds and clears the display and again shows the price and the available types of coffee.
  • As Proteus requires the hex file of the code to run the simulation.
  • So for that, open the Arduino IDE and please verify your code before making a hex file by clicking on the ‘Verify’ button to remedy any errors.
  • To get the hex file from the Arduino IDE click on “Sketch > Export Compiled Binary”.
  • Your hex file will be generated successfully now put that hex file to the Arduino UNO board in the Proteus software.
  • Everything is now in place, it's time to run the simulation and get a nice virtual coffee.

I hope you have understood the whole working of our smart vending machine project and enjoyed it as well. I think we have explained pretty much everything but still if you have any doubts or improvements please let us know in the comment section.

Thanks for giving your valuable time for reading it.

L298 Motor Driver Library for Proteus

Hello everyone, I hope you all are doing great. Today, I am going to share a new L298 Motor Driver Library for Proteus. It has never been designed before and we are proudly presenting it for the first time. I hope you guys are gonna like it. You should also have a look at DC Motor Speed Control using L298 in which I have used the same module in hardware design. But today we are gonna see it in action in Proteus Simulation and its quite exciting for me as well. :) If you don't know much about L298 then you should also have a look at Introduction to L298, in which I have discussed the basics of L298 module, it will be quite informative for you. If you got into any trouble regarding this L298 Motor Driver Library for Proteus, then you can ask in comments and I will try my best to resolve your issues. So, let's get started with L298 Motor Driver Library for Proteus:

L298 Motor Driver Library for Proteus

  • First of all, download the L298 Motor Driver Library for Proteus by clicking the below button:
L298 Motor Driver Library for Proteus
  • Once you downloaded the rar file, open it and extract the files.
  • You will get two files in it, named as:
    • L298MotorDriverTEP.LIB
    • L298MotorDriverTEP.IDX
  • Place these two files in the Library folder of your Proteus Software.
Note:
  • If you are using Proteus 7 Professional, then the library folder link will be something like this: C:Program Files (x86)Labcenter ElectronicsProteus 7 ProfessionalLIBRARY
  • If you are using Proteus 8 Professional, then the library folder link will be something like this: C:ProgramDataLabcenter ElectronicsProteus 8 ProfessionalDataLIBRARY
  • Now restart your Proteus software and search for L298 Motor Driver in the search box as shown in below figure:
  • Place this L298 Motor Driver in your Proteus work space.
  • If everything goes fine then you will get something as shown in below figure:
  • You can see its looking quite awesome in above figure.
  • Using this L298 Motor Driver, you can easily control two DC Motors and it works exactly the same as our hardware L298 module.
  • It has two output pins on left and 2 on the right side, while the input pins are shown at the right bottom corner.
  • Now, let's design a small circuit and check out its controlling operation.

L298 Motor Driver Simulation in Proteus

  • Now, I am gonna design a small circuit which will simulate this L298 Motor Driver and we will driver two DC motors with it.
  • You can download this L298 Motor Driver Simulation in Proteus by clicking the below button:
Download Proteus Simulation for L298
  • So, first of all design a simple circuit as shown in below figure:
  • I have attached one DC Motor at OUT1 and OUT2 while second DC Motor at OUT3 and OUT4.
  • I have attached Logic States at all of four inputs and you can also provide input using any microcontroller like Arduino or PIC Microcontroller.
  • Now run your simulation and if everything goes fine then you will get results as shown in below figure:
  • You can also have a look at the working of this L298 Motor Driver in below video:
That's all about L298 Motor Driver in Proteus and I hope you won't get any problem in simulating it in Proteus. If you still got any problem then as k in comments and I will help you out and do give your suggestions as well. I will also run Stepper Motor using this L298 Motor Driver.

DC Motor Speed Control using Arduino

Hello friends! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge about how can you make a simple program for DC Motor Speed Control using Arduino UNO. In my previous tutorial, DC Motor Direction Control using Arduino, I have just controlled the DC motor in both directions at constant speed using Arduino. I have also performed the DC Motor Direction Control in Matlab by sending different commands through serial port from Matlab and LabVIEW to the Arduino and then controlled the direction of rotation of DC motor. But in this tutorial I will rotate the same DC motor at variable speed in both clockwise and anti clockwise directions. In my previous tutorial, we have seen that input pins In1 In2 of motor control driver L298 (H-Bridge) are useful to control the direction of rotation of the DC motor. In this tutorial, I have controlled its speed as well by providing different voltage levels at the enable pin of the DC motor control driver L298. It will be helpful to vary the speed of the DC motor in either clockwise or in anti clockwise direction. So, let's get started with DC Motor Speed Control using Arduino UNO:

DC Motor Speed Control using Arduino UNO

In this tutorial we will learn that how to make an algorithm for DC Motor Speed Control using Arduino UNO. Speed control of any motor is always done y Pulse Width Modulation, abbreviated as PWM. PWM pulse can be generated using Arduino and L298 Enable Pin is used to get that PWM pulse and then it controls the motor speed accordingly. Before going into the further details I would like to tell you about the concept of PWM for controlling DC motor. Moreover, you can download the complete Arduino code for DC Motor Speed Control using Arduino by clicking the below button: Download Arduino Source Code
Pulse Width Modulation (PWM)
PWM stands for Pulse Width Modulation. It basically describes the type of the digital signal. PWM technique is an excellent technique to control the analog circuits with microcontroller's digital PWM output. In this technique we can get analog results with the digital means. Digital control is used to create square wave. This pattern can vary voltages between full on i.e. 5V and full off i.e. 0V. The duration of on time i.e. when the the signal is present is known as pulse width. PWM waves for the different duty cycles are shown in the figure below. Duty cycle is basically the proportion of the time during which a system is operated. It can be expressed as a percentage. For example motor rotates for 1 second out of 100 seconds, it duty cycle can be represented as 1/100 or as 1%. For Arduino software coding the command analogWrite(255) shows the maximum i.e. 100% duty cycle. To achieve 50% duty cycle we have to update this command to analogWrite(127). Arduino UNO's pin no 3, 5, 6,10 and 11 are used as PWM pins. In this project we can control the speed of the DC motor by providing high and low voltages to the enable pin of the motor control driver L298. For example, if a motor rotates with the maximum speed and 100% duty cycle at 12V and we provide it with the 6V then it will rotate with the half of the initial speed having 50% duty cycle.
Motor Controller L298
The pins EnA and EnB of the motor controller L298 are used as the PWM pins. We can rotate the DC motor at different speed providing different high and low voltage levels to these pins of the motor control driver. If we start to reduce the maximum voltage at which the motor rotates at maximum speed, the speed of the motor also starts to reduce. In this way these enable pins are helpful to control the speed of the DC motor.
Algorithm design and descrition
In this section of the tutorial DC Motor Speed Control using Arduino UNO, I am going to explain you about designing as well as a detailed description of the designed algorithm. I will tell you about the entire algorithm in step by step procedure. Note:Since you are working on the DC motor so you must also have a look at my previous tutorials, they will be helpful for you to simulate this project as well. Open your Arduino software, copy and paste the source code given below in your software.
#include <LiquidCrystal.h>
//Keyboard Controls:
//
// C - Clockwise
// S - Stop
// A - Anti-clockwise

// Declare L298N Controller pins
// Motor 1
int count=255;
int dir1PinA = 2;
int dir2PinA = 5;
int speedPinA = 6; // PWM control
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

void setup() { 
 
Serial.begin(9600); // baud rate

lcd.begin(20, 4);
lcd.setCursor(5,0);
lcd.print("DC Motor");
lcd.setCursor(5,1);
lcd.print("Direction");
lcd.setCursor(5,2);
lcd.print("Control");
lcd.setCursor(2,3);
lcd.print("via Arduino UNO");

delay(3000);

lcd.clear ();

lcd.setCursor(0,2);
lcd.print("www.TheEngineering");
lcd.setCursor(4,3);
lcd.print("Projects.com");
//Define L298N Dual H-Bridge Motor Controller Pins

pinMode(dir1PinA,OUTPUT);
pinMode(dir2PinA,OUTPUT);
pinMode(speedPinA,OUTPUT);

analogWrite(speedPinA, 255);//Sets speed variable via PWM 

}

void loop() {

// Initialize the Serial interface:

if (Serial.available() > 0) {
int inByte = Serial.read();
int speed; // Local variable

switch (inByte) {

case 'C': // Clockwise rotation
//analogWrite(speedPinA, 255);//Sets speed variable via PWM 
digitalWrite(dir1PinA, LOW);
digitalWrite(dir2PinA, HIGH);
Serial.println("Clockwise rotation"); // Prints out “Motor 1 Forward” on the serial monitor
Serial.println("   "); // Creates a blank line printed on the serial monitor
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("Clockwise rotation");
break;

case 'S': // No rotation
//analogWrite(speedPinA, 0); // 0 PWM (Speed)
digitalWrite(dir1PinA, LOW);
digitalWrite(dir2PinA, LOW);
Serial.println("No rotation");
Serial.println("   ");
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("No rotation");
break;

case 'H': //Accelrating motor
count=count+20;
  if (count>255)
  {
  count =255;
  }
  analogWrite(speedPinA,count);
  delay(50);

//digitalWrite(dir1PinA, LOW);
//digitalWrite(dir2PinA, HIGH);
Serial.println("Motor is accelrating slowly");
Serial.println("   ");
Serial.println(count);
lcd.setCursor(0,0);
lcd.print("Motor is accelrating");
break;

case 'L': //Deaccelrating motor
count=count-20;
  if (count<20)
  {
  count=20;
  }
  analogWrite(speedPinA,count);
  delay(50);

//digitalWrite(dir1PinA, LOW);
//digitalWrite(dir2PinA, HIGH);
Serial.println("Motor is deaccelrating slowly");
Serial.println("   ");
Serial.println(count);
lcd.setCursor(0,0);
lcd.print("Motor Deaccelrates");
break;

case 'A': // Anti-clockwise rotation
//analogWrite(speedPinA, 255); // Maximum PWM (speed)
digitalWrite(dir1PinA, HIGH);
digitalWrite(dir2PinA, LOW);
Serial.println("Anti-clockwise rotation");
Serial.println("   ");
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("Anti-clockwise");
break;

default:
// Turn off the motor if any other key is being pressed
for (int thisPin = 2; thisPin < 11; thisPin++) {
digitalWrite(thisPin, LOW);
}
Serial.println("Wrong key is pressed");
//lcd.clear();
lcd.setCursor(0,0);
lcd.print("Wrong key is pressed");
  }
    }
      }
  • In the previous tutorials, DC Motor Direction Control using Arduino and DC Motor Direction Control using Matlab we have learnt that how to control the direction of the DC motor.
  • We used the commands C, A and S for the clockwise rotation, anti clockwise rotation and stopping the motor respectively.
  • In this tutorial, we have added two further commands and for accelerating and de-accelerating the DC motor.
  • If we send the command H different times consecutively the speed of the motor will increase continuously.
  • If we send the command different times consecutively, the speed of the motor will start to decrease.
  • Now, upload the source code to your Arduino UNO's board.
  • Open the serial monitor at the top right of the Arduino Software.
  • And enter the commands in serial monitor periodically as explained above.
Actual Hardware Setup
  • When we enter the command in the serial monitor of the Arduino software. Motor will start rotating in the clockwise direction and a statement Clockwise rotation will be printed on serial port.
  • The same statement will be printed on the LCD as well as shown in the figure below.
  • When we enter the command in the serial monitor of the Arduino software. Motor will start rotating in the anti clockwise direction and a statement Anti clockwise rotation will be printed on serial port.
  • The same statement will be printed on the LCD as well as shown in the figure below.
  • When we enter the command in the serial monitor of the Arduino software. Motor will start accelerating and a statement Motor is accelerating will be printed on serial port.
  • The same statement will be printed on the LCD as well as shown in the figure below.
  • When we enter the command in the serial monitor of the Arduino software. Motor will start to deaccelerate and a statement Motor Deaccelerates will be printed on serial port.
  • The same statement will be printed on the LCD as well as shown in the figure below.
Thats all from the tutorial DC Motor Speed Control using Arduino UNO. I hope you have enjoyed this tutorial. If you face any sort of problem, you can ask me anytime without feeling any kind of hesitation. I will further explore my knowledge about Arduino projects in my later tutorials. Till then, Take care :)

DC Motor Direction Control using Arduino

Hello friends! I hope you all will be absolutely fine and having fun. Today, I am going to share my knowledge with all of you about how to make a simple program for DC Motor Direction Control using Arduino. The word DC is basically an abbreviation of Direct current. So, a direct current motor is commonly used motor having two input terminals, one is positive and the other one is negative. If we connect these terminals with the voltage supply the motor will rotate. If you change the polarity then motor will rotate in opposite direction. You should also have a look at Difference between DC & AC Motors to get a better idea about these motors. DC motor has a lot of applications. You can use it in automation projects, for controlling static as well as mobile robots, in transport system, in pumps,fans,bowers and for industrial use as well. In this tutorial, I will do the DC Motor Direction Control using Arduino and L298 motor controller. Moreover, I have also used LCD which will give us the status of our DC Motor i.e. whether its moving in clockwise direction or anticlockwise. In my later tutorial I will control the same DC motor using NI LabVIEW 2015 and MATLAB. I have added the next tutorial on this project in which I have done the DC Motor Direction Control in MATLAB so in that project, I have used the same hardware but instead of controlling it from Arduino I have controled it using MATLAB so you must have a look at that tutorial.

DC Motor Direction Control using Arduino

In this tutorial, I will make a simple program to do the DC Motor Direction Control using Arduino. Arduino is basically an amazing micro controller and is very easy to use because it is an open source device. So, it is a student friendly device. You can also write Arduino programs for different purpose. Arduino is also a cost efficient device in comparison to the other micro-controllers e.g. raspberyy pi, NI-myRIO, galileo, single board RIO etc. First of all I prepared my complete hardware setup. Then I made a program and interfaced it with the hardware. We will discuss all the steps in detail below. The logic is pretty simple i.e. Arduino has to send commands to L298 motor controller and then L298 decides the DC Motor Direction Control by manipulating the Arduino commands. Before going into the detail, I want to show you the list of components required. You can download complete Arduino source file here:

Download Arduino Source Code Note: If you are working on DC Motor then you should also have a look at these Proteus Simulations:

Components List & Description

Here's the complete list of the components required for designing DC Motor Direction Control using Arduino: So, now let's discuss the main components for this project individually so that you get better idea of why these components are used in this DC Motor Direction Control using Arduino:
Arduino UNO
Arduino UNO is basically the back bone of this DC Motor Direction Control Project. It controls and leads the whole project. In this project, Arduino reads the commends from serial port and sends to L298 motor controller IC in order to control the direction of rotation of the DC motor. So, the Arduino has overall major control over the whole project.
Motor Controller L298
Motor Controller is used to control the direction of DC motor. It consists of an L298 motor driver IC which is capable of rotating the motor in both clockwise and anti clockwise directions by switching its pins from HIGH to LOW and vise versa. Moreover, it needs +12V, GND and +5V in order to power it up. So, we will design a voltage regulator which will step down 12V to 5V. So, let's have a look at this voltage driver in next part:  
Voltage Regulator
Voltage regulator is also the part of this design. In our daily life, we need to step up or to step down the voltages according to the requirements. Requirements vary with the different purpose. Small electronics components like micro-controller, LED, LCD etc. So the main purpose of voltage regulator is to step down the voltage from 12V to just 5V in order to fulfill the requirements of the electronic components. Step down transformer can also be used instead of voltage regulator. Due to the huge structure and cost we prefer to use voltage regulator. You should read How to Design a 5V Power Supply in Proteus to get better idea about this voltage regulator. The circuit diagram of the designed voltage regulator is shown in the figure below.
DC Motor
DC motor is the essential part of the different projects and our daily life. for example if we want to automate our house doors i.e if we want to open and close the doors automatically by detecting the person, motor plays a vital role here. Similarly in robotics, vacuum, blowers and air conditioners, DC motor has a wide range of applications. LED is used here to show whether the designed circuit is working properly or not. Like in mobile phones and laptops as we connect the charger it shows the charging indication. So, we must need some indication that everything is going fine and the circuit is working properly.
Jumper Wires
Jumper wires are used to make the connections between all of the components. Use small pieces of the jumper wires in order to give a better look to the designed circuit. If you are using longer wires for the connections, it will create complexity and causes many problems while operating the circuits.
Power Supply
12V power supply is used as the main power supply. As we know, to operate any of the electronic components or electronic appliances we must need the main power supply. Power supply can vary according to the power consumption of the electronic equipment. Here I am using a 12V DC power supply because it is a small and simple project with minimum power requirements.
LCD 20x4
LCD is used to visualize the commands sent to the serial port. It basially display us that which function is being performed at a particular time. A 20×4 LCD is used and is shown in the figure below. If you haven't worked on LCD before, then you should have a look at Circuit Designing of LCD with Arduino in Proteus ISIS.
Assembling of the Components
Here are the few steps followed while designing this DC Motor Direction Control using arduino:
  • Connect the terminals of the DC motor with the output pins (OUT1 and OUT2) of L298 motor controller.
  • Connect L298 motor controller's pin IN1 and IN2 with the Arduino UNO's pin 2 and 5 respectively.
  • Now, connect ENA pin of L298 motor controller to the Arduino's pin 9.
  • Connect the power supply to turn on the circuit.
  • Make sure that you have supplied 12V, 5V and GND properly to the L298 motor controller.  
Circuit Diagram
Completely Assembled Diagram

Arduino Code Designing

After making all the connections properly, open your Arduino source code. If you are using Arduino for the first time then you should have a look at Installation of Arduino Driver in Windows.
  • Attach the Arduino board with your PC and go to Search->Device Manager as shown in the figure below.
  • Select the device manger and you can see different options here like Batteries, bluetooth radios, keyboards, monitors, ports etc.
  • Open the Ports(COM & LPT) as shown in the figure below.
  • See the COM Port supported by Arduino Board which COM5 in this case.
  • Now open the Arduino software and go to Tools and select the Arduino board and the COM port properly.
  • The description is shown in the figure given below.
  • Just copy and paste the source code given below.
#include <LiquidCrystal.h>
//Keyboard Controls:
//
// C - Clockwise
// S - Stop
// A - Anti-clockwise

// Declare L298N Controller pins
// Motor 1
int dir1PinA = 2;
int dir2PinA = 5;
int speedPinA = 7; // PWM control
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

void setup() { 
 
Serial.begin(9600); // baud rate

lcd.begin(20, 4);
lcd.setCursor(5,0);
lcd.print("DC Motor");
lcd.setCursor(5,1);
lcd.print("Direction");
lcd.setCursor(5,2);
lcd.print("Control");
lcd.setCursor(2,3);
lcd.print("via Arduino UNO");
//Define L298N Dual H-Bridge Motor Controller Pins

pinMode(dir1PinA,OUTPUT);
pinMode(dir2PinA,OUTPUT);
pinMode(speedPinA,OUTPUT);

}

void loop() {

// Initialize the Serial interface:

if (Serial.available() > 0) {
int inByte = Serial.read();
int speed; // Local variable

switch (inByte) {

case 'C': // Clockwise rotation
analogWrite(speedPinA, 255);//Sets speed variable via PWM 
digitalWrite(dir1PinA, LOW);
digitalWrite(dir2PinA, HIGH);
Serial.println("Clockwise rotation"); // Prints out “Motor 1 Forward” on the serial monitor
Serial.println("   "); // Creates a blank line printed on the serial monitor
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Clockwise rotation");
break;

case 'S': // No rotation
analogWrite(speedPinA, 0); // 0 PWM (Speed)
digitalWrite(dir1PinA, LOW);
digitalWrite(dir2PinA, LOW);
Serial.println("No rotation");
Serial.println("   ");
//lcd.clear();
lcd.setCursor(5,1);
lcd.print("No rotation");
break;

case 'A': // Anti-clockwise rotation
analogWrite(speedPinA, 255); // Maximum PWM (speed)
digitalWrite(dir1PinA, HIGH);
digitalWrite(dir2PinA, LOW);
Serial.println("Anti-clockwise rotation");
Serial.println("   ");
//lcd.clear();
lcd.setCursor(3,2);
lcd.print("Anti-clockwise");
break;

default:
// Turn off the motor if any other key is being pressed
for (int thisPin = 2; thisPin < 11; thisPin++) {
digitalWrite(thisPin, LOW);
}
Serial.println("Wrong key is pressed");
//lcd.clear();
lcd.setCursor(0,3);
lcd.print("Wrong key is pressed");
  }
    }
      }
  • Now, upload the source code onto the Arduino UNO board as shown below.
  • In the above figure shows that the source code is uploading to the Arduino board.
   
  • Done uploading shows that the source code has been uploaded successfully to the Arduino borad.
  • Now, go to the Serial Monitor on the top right corner of the Arduino software.
  • Press C, you can see the DC motor is rotating in the clockwise direction and statement Clockwise rotation will be printed on the Serial Monitor.
  • Now, press S, the DC motor will stop and a statement No rotation will be print on the Serial Monitor.
  • If you want to rotate DC motor in anti-clockwise direction, press A then, the statement Anti-Clockwise rotation will be printed on the Serial Monitor.
  • I have made the logic in such a way that if you press any of the other buttons the DC motor will stop in reaction to that and the statement Wrong key is pressed will be printed on the Serial Monitor.
  • All of the above steps are shown in the figure shown below.
   

Final Testing of DC Motor Direction Control using Arduino

  • The screenshot of the actual circuitry for DC Motor Direction Control using Arduino is shown in the below figure:
  • You can see in the above figure that we have attached Arduino UNO board with L298 Motor Driver and then we have attached DC Motor with Arduino UNO and LCD is used to show the current movement of Motor.
  • Moreover we have also designed a small circuit which I have mentioned above and named as Voltage regulator, and it is used to step down 12V into 5V.
So, that's all from the tutorial DC motor Direction Control using Arduino. I hope you enjoyed this tutorial. In my next tutorials, I will interface this project with LabView and MATLAB. If you face any sort of problem, you can freely ask me anytime without feeling any kind of hesitation. So, will see you guys in next tutorial. Till then Take  care :)

Line Following Robot using Arduino

Hello everyone, I hope you all are fine and having fun with your lives. Today, I am going to share a very basic project named as Line Following Robot using Arduino. I have designed a three wheeler robot and have placed IR sensors beneath it to detect the black line and then I have made it move over this Black Line.

This Line Following Robot is not doing any extra feature i.e. turning or rotating back. It will just simply move in the straight line. I have also posted a short video at the botton of this tutorials which will give you better idea of how this robot moves. You should first read this tutorial and design the basic robot and once you are successful in designing the basic Line Following Robot then you should have a look at my recent Project Line following Robotic Waiter in which I have designed a Robotic waiter which follows the line and also take turns on different tables. So, let's get started with Line Following Robot using Arduino.

Line Following Robot using Arduino

  • First of all I have designed the Mechanical model of the robot, which has three wheels on it.
  • Its a triangular method in which the motors were attached to the front two wheels and the back wheel is a caster wheel, which is present in the middle of the robot.
  • Here's the image of front wheel coupled with the DC Gear Motor:
  • Now let's have a look at the rear caster wheels, shown in below image:
  • Finally, I have used Acrylic as the body of the robot.
  • Here's the assembled version of our Line Following Robot:
  • Now that we have the mechanical design of our robot and we have assembled it completely.
  • So, now comes the electronics part where we are gonna place the DC Motor Driver Circuits and will also place the IR sensors.
  • I have used Arduino board for programming of this Line following Robot.
  • First of all, I have designed the 2 relay baord for DC motors.
  • Its circuit diagram is shown in below figure:
  • We also need a voltage divider circuit because we need such a power supply from which we can get 5V, while our source battery is of 12V.
  • So, in order to do that I have used 7805 Regulator IC and have designed a simple circuit as shown in below figure:
  • Now placing all the components over the Line following Robot, it looked like something as shown in below figure:
  • Here's the Arduino code which you need to upload in your Arduino board:
#define motorL1 8
#define motorL2 9
#define motorR1 10
#define motorR2 11

#define PwmLeft 5
#define PwmRight 6

#define SensorR 2
#define SensorL 3
#define Sensor3 A0
#define Sensor4 A1

#define TableA A4
#define TableB A2
#define TableC A5
#define TableD A3

int OriginalSpeed = 200;
int TableCount = 0;
int TableCheck = 0;
int RFCheck = 10;

void setup() 
{
  Serial.begin (9600);
 
  pinMode(motorR1, OUTPUT);
  pinMode(motorR2, OUTPUT);
  pinMode(motorL1, OUTPUT);
  pinMode(motorL2, OUTPUT);
  
  pinMode(PwmLeft, OUTPUT);
  pinMode(PwmRight, OUTPUT);
  
  pinMode(SensorL, INPUT);
  pinMode(SensorR, INPUT);
  pinMode(Sensor3, INPUT);
  pinMode(Sensor4, INPUT);
  
  pinMode(TableA, INPUT);
  pinMode(TableB, INPUT);
  pinMode(TableC, INPUT);
  pinMode(TableD, INPUT);
  
  MotorsStop();
  
  analogWrite(PwmLeft, 0); 
  analogWrite(PwmRight, 0);
  delay(2000); 
 // Serial.println("fghfg");
  
}

void loop() {
  MotorsForward();
  PIDController();
}

void MotorsBackward()
{
    digitalWrite(motorL1, HIGH);
    digitalWrite(motorL2, LOW);
    digitalWrite(motorR1, HIGH);
    digitalWrite(motorR2, LOW);
}

void MotorsForward()
{
    digitalWrite(motorL1, LOW);
    digitalWrite(motorL2, HIGH);
    digitalWrite(motorR1, LOW);
    digitalWrite(motorR2, HIGH);
}

void MotorsStop()
{
    digitalWrite(motorL1, HIGH);
    digitalWrite(motorL2, HIGH);
    digitalWrite(motorR1, HIGH);
    digitalWrite(motorR2, HIGH);
}

void MotorsLeft()
{
    analogWrite(PwmLeft, 0); 
  analogWrite(PwmRight, 0);
    digitalWrite(motorR1, HIGH);
    digitalWrite(motorR2, HIGH);
    digitalWrite(motorL1, LOW);
    digitalWrite(motorL2, HIGH);
}

void MotorsRight()
{
      analogWrite(PwmLeft, 0); 
  analogWrite(PwmRight, 0);
    digitalWrite(motorR1, LOW);
    digitalWrite(motorR2, HIGH);
    digitalWrite(motorL1, HIGH);
    digitalWrite(motorL2, HIGH);
}

void Motors180()
{
    analogWrite(PwmLeft, 0); 
    analogWrite(PwmRight, 0);
    digitalWrite(motorL1, HIGH);
    digitalWrite(motorL2, LOW);
    digitalWrite(motorR1, LOW);
    digitalWrite(motorR2, HIGH);
}

void PIDController()
{
  if(digitalRead(SensorL) == HIGH){analogWrite(PwmRight, 250);analogWrite(PwmLeft, 0);}
  if(digitalRead(SensorR) == HIGH){analogWrite(PwmLeft, 250);analogWrite(PwmRight,0);}
  if((digitalRead(SensorL) == LOW) && (digitalRead(SensorR) == LOW)){analogWrite(PwmRight, 0);analogWrite(PwmLeft, 0);}
}
  • Now that's all, here's the video for Line Following Robot using Arduino which will give you better idea:
That's all for today. I hope you have enjoyed this Line Following Robot using Arduino and are gonna use it in your projects. feel free to ask in comments, if you got into any trouble. Thanks for reading. Take care !!! :)

DC Motor Direction Control with Arduino in Proteus

Hello friends, hope you all are fine and having fun with life. Today, I am going to share DC Motor Direction Control with Arduino. I have designed a complete simulation in Proteus, which will help you in understanding the controlling of DC motor. I would recommend you to first read How to Control relay in Proteus ISIS which will help you in understanding the functionality of relays because in today's tutorial, I have used relays to do the DC Motor Direction Control. I have already posted a tutorial on DC Motor Drive Circuit in Proteus ISIS.

So, for DC Motor Direction Control, I have used Arduino UNO baord, so you should also download this Arduino Library for Proteus so that you can use Arduino boards in Proteus software. I have also provide the simulation and the code for DC Motor Direction Control but I would recommend you to design it on your own so that you learn from it. If you have any problem then ask in comments and I will try to resolve them. In this project, I have used Serial Terminal. So, whenever someone, sends character "C" on serial terminal then the motor will move in Clockwise Direction and when someone sends character "A" then it will move in Anti-clockwise Direction and will stop on character "S". Anyways, lets get started with DC Motor Direction Control with Arduino in Proteus ISIS.

DC Motor Direction Control with Arduino in Proteus ISIS

  • You can download the Proteus simulation for DC Motor Direction Control by clicking the below button:
Download Proteus Simulation for DC Motor

  • So, now let's move on with designing it, first of all get the below components from Proteus and place them in your workspace:
  • Now, design a circuit in Proteus software, as shown in below figure:
  • You can see in the above figure that I have used two relays which I have used for DC Motor Direction Control.
  • Moreover, there's a Virtual Terminal through which I am sending the commands.
  • I have used Arduino UNO board for DC Motor Direction Control through Virtual Terminal. You should download the Arduino Library for Proteus so that you can use it in Proteus.
  • Now upload the below code in your Arduino software and get the hex file. You should read how to get the Hex file from Arduino.
int Motor1 = 2;
int Motor2 = 3;

void setup() {
  pinMode(Motor1, OUTPUT);
  pinMode(Motor2, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if(Serial.available())
  {
    char data = Serial.read();
    Serial.println(data);
    if(data == 'C'){MotorClockwise();}
    if(data == 'A'){MotorAntiClockwise();}
    if(data == 'S'){MotorStop();}
  }
}

void MotorAntiClockwise()
{
  digitalWrite(Motor1, HIGH);
  digitalWrite(Motor2, LOW);
}

void MotorClockwise()
{
  digitalWrite(Motor1, LOW);
  digitalWrite(Motor2, HIGH);
}

void MotorStop()
{
  digitalWrite(Motor1, HIGH);
  digitalWrite(Motor2, HIGH);
}
  • In the above code, I have designed three functions which I am calling on Serial receive.
  • The code is quite self explanatory but if you got problem then ask in comments and I will resolve them.
  • Once everything's done then run your simulation and if you have done fine then it will start working as shown in below figure:
  • Obviously, you can't see a moving DC motor in an image but you can get the idea from Relays position in above figure. :)
  • The below video will give you the better idea of How it works.

So, that's all for today. Hopefully now you have got the idea of How to do DC Motor Direction Control with Arduino in Proteus ISIS. In the next tutorial, I am gonna add speed control of DC Motor. So, till then take care and have fun. :)

LM317 Voltage Regulator in Proteus

Hello friends, hope you all are fine and having fun. In today's post we are gonna have a look at LM317 Voltage Regulator in Proteus. In the previous post, we have seen how to design a 5V Power Supply in Proteus ISIS, which I have designed using IC regulator 7805. Today I am going to share How to design LM317 Voltage Regulator Circuit in Proteus. This DC power supply is a variable one means you can set its output voltage to any level you want. In order to change its output value we have used a variable resistor and by changing its value you can change the output value. It is a basic level project and very simple but used as a base to design large industrial projects. In this project, we are going to control the speed of a DC Motor and the corresponding voltages, appearing across it. The reason for designing this variable DC power supply is that, when you are working on some engineering project then each electronic module has its own power level i.e. xbee module works on 3.3V while Arduino board works on 5V. So, there's a need to design such power supply which can provide variable voltages and we can set them according to our demand. So, for all Microcontrollers like Arduino or PIC Microcontroller or 8051 Microcontroller, I designed 5V Power supply using 7805 but for 3.3V modules like XBee, NRF24L01 etc I design this variable DC power supply using LM317. I hope now you got the importance of this LM317 Voltage Regulator.

To design this, we will be using LM317k. Basically, it is a Voltage Regulator IC. It has 3 pins. Pin # 2 is for input voltages, marked as VI. Pin # 3 is for output voltages, marked as VO, and pin # 1 is used for Regulating Voltages and it is marked as ADJ. Further, if you notice the circuit diagram, which is given in the figure, then you will see that pin # 1 is connected to a Potentiometer. Potentiometer is a Variable Resistor device and it is also known as Voltage Divider. The feature of this electronic device is that, we can adjust the voltage through it according to our own choice. It operates on 12 Volts and it gives us ease that, we can adjust its voltages from 0 to MAXIMUM (which is 12 volts in most cases). Further if we notice the circuit, then we will see that a LED is connected in parallel with a simple DC motor and a voltmeter is also connected in parallel with Motor to monitor the voltages appearing across it. Above information was a little demo about the individual components of the circuit, now let’s be practical and move towards Hardware and see how actually Electronic components respond. You should also have a look at Introduction to LM317, if you wanna read all the basics about it. So let's get started with LM317 Voltage Regulator in Proteus:

LM317 Voltage Regulator in Proteus ISIS

  • You can download this complete LM317 Voltage Regulator simulation by clicking the below button but I recommend you to design it on your own so that you learn most from it.

Download Proteus Simulation

  • First of all, place all the components in Proteus workspace, as shown in image:

  • A 12-Volt DC supply is provided to input pin (# 2) of LM317 and potentiometer is connected to Adjustable pin of LM317, which is, pin # 1.

  • At output pin we have connected DC Motor and a Voltmeter is also connected in parallel with Motor.
  • The complete circuit, ready for simulation is shown below in image:

Stage # 1
  • Set the potentiometer at 0% and run the simulation, you will notice that Motor will rotate very slowly in clock-wise direction and 1.25 volts will appear on the voltmeter across it. If all the connections are OK, and when you will run the simulation, LM317 Voltage Regulator simulation will look like as shown in the image below:

Note:
  • If you don't want to use the variable resistance, then you should use this LM317 Calculator to get value of your second resistance.
Stage # 2
  • Now, set the potentiometer value to 11% and you will see that, Motor will start to rotate with a faster rate and on voltmeter scale, we will see 6.40 volts. In this setting, the interesting thing is, LED will start to Flash and it will turn ON & OFF automatically. This phenomenon can be seen in images below:

  • Stage # 2 is our transient stage. When the potentiometers setting is below 11%, voltage appears across the motor and it also rotates but LED doesn’t glow. On the other hand, when potentiometers setting is above 11%, then LED glows continuously while motor also rotates as before, and voltmeter also gives some particular values of voltages appearing across the motor.
Stage # 3
  • Now at final stage, set potentiometer to 100% and you will observe that motor is rotating with full speed and voltmeter reading will be 10.6 volts while LED is glowing continuously. This stage of the simulation can be seen in the image below:

Now, we can conclude that, LM317 is the monitoring device of this circuit. We can set the value of potentiometer according to our own choice and by this, the speed of motor can be controlled and also the corresponding voltages, appearing across it.

Here's the video in which I have given the detailed introduction of LM317 and have also run its simulation:

Alright friends, that's all for today and I hope now you can easily design this LM317 Voltage Regulator. In the next post, I have discussed DC Motor Drive circuit in Proteus ISIS . Till than take care and be safe !!! :)

Syed Zain Nasir

I am Syed Zain Nasir, the founder of <a href=https://www.TheEngineeringProjects.com/>The Engineering Projects</a> (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform.I also work as a freelancer and did many projects related to programming and electrical circuitry. <a href=https://plus.google.com/+SyedZainNasir/>My Google Profile+</a>

Share
Published by
Syed Zain Nasir