How to use analogRead in Arduino?
Hi Friends! Welcome you onboard. I have been writing these
Arduino tutorial for beginners for quite a while now and today we are having the next episode. Today, I'll discuss
How to use analogRead in Arduino. The analogRead is mainly used to program and address analog pins on the board. In our previous tutorial, we have seen
How to use digitalWrite Arduino Command, which deals with digital pins of Arduino but today's one deals with analog pins.
There are many types of boards available in the market ranging from
Arduino UNO,
Arduino Mega2560,
Arduino Micro and many more, which you can use based on your technical requirements.
Arduino Programming is made simple by the Arduino.cc - the manufacturer of Arduino Boards, providing an open source software and hardware features and give you the flexibility to modify and tweak the boards as per your requirements.
In this post, I'll discuss how you can easily program the Arduino Board using analogRead if you intend to target the analog pins on the board. Let's dive in.
How to use analogRead in Arduino
The analogRead is a command mainly used to program the analog pins on the board.
If you are using analogRead functions, it indicates you are making the pins as input i.e. you can connect the Arduino analog pins with any sensor and read its value by making the analog pins as input.
Following figure shows the placement of analog pins on the Arduino Uno Board.
- If you have already got a hold of some features of Arduino Board, you must have known that analog pins are 10-bit pins. It means each pin can store 0 - 1023 values.
Analog pins are different than digital pins as the later can store only two values: HIGH and LOW while the former comes with an ability to store any random value ranging from 0 - 1023 where 0 will indicate the ground signal or zero volts while 1023 will be representing 5 volts.
The voltage values are directly proportional to the values stored in the Arduino Pins. For example, if the sensor voltage is around 2.5 V then the value we get on an analog pin will be half the total value it can store in the pin i.e. 512.
Syntax:
- The syntax of analogRead is given as follows:
int data = analogRead(int pin);
where:
- Pin defines the number of a pin you are targeting. Most of the Arduino Boards come with 6 analog pins and marked as A0 to A5 while Arduino Pro Mini and Arduino Nano come with 8 pins, marked from A0 to A7 and Arduino Mega stands out in terms of having the most number of analog pins, around 16, marking from A0 to A15 on the Mega.
Return:
- analogRead returns value anywhere between 0 to 1023 depending on the voltage it gets in return.
Example:
data = analogRead (4);
Note:
- If you are aiming to read analog pins from digitalRead, you must write A4, instead of simply pointing the required pin number i.e. analogRead(A4).
Here's a sample code for testing the analogRead Arduino command:
int sensorPin = A0;
int sensorValue = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
}
I have written an Article on
Introduction to Arduino IDE - An Official Software used to program the variety of Arduino Boards. In this Article, I have broken down everything in simple steps, detailing how to select the relevant board you are working on and make it compatible with the software.
That’s all for today. I hope you have got valuable information out of this read. However, if you are unsure or have any question you can approach me in the comment section below. I’d love to help you according to the best of my knowledge. In the coming tutorial, we will have a look at
How to use analogWrite in Arduino, which is used to update the status of analog pins. Thanks for reading the article.
Sound Sensor Library for Proteus
Update: We have created a new version of this library, which you can check here:
Sound Detector Library for Proteus V2.0.
Hello friends, I hope you all are doing great. In today's tutorial, I am going to share a new Sound Sensor Library for Proteus. We are presenting this library for the first time and I would give the credit to our team, without their support it won't be possible. Proteus doesn't have this module in its library and it is used in a lot of Engineering Projects these days.
This sound sensor is used to detect the sound in the surroundings and is normally known as the Sound Detector sensor. It won't recognize the sound. As we can't produce the sound in Proteus, that's why we have placed a TestPin. When this TestPin is HIGH, that means we have sound in the surroundings and if it's LOW then there's silence. Analog sound detector sensors are also available but our sensor is a digital one. So, now let's have a look at How to download & simulate this Sound Sensor Library for Proteus:
Where To Buy? |
---|
No. | Components | Distributor | Link To Buy |
1 | Arduino Uno | Amazon | Buy Now |
Sound Sensor Library for Proteus
- First of all, download the Library files for the sound detector sensor by clicking the below button:
Sound Sensor Library for Proteus
- Open this downloaded zip file, and extract below three library files:
- SoundSensorLibraryTEP.LIB
- SoundSensorLibraryTEP.DLL
- SoundSensorLibraryTEP.HEX
- Place these three files in the Library folder of your Proteus software.
Note:
- Now restart your Proteus ISIS software and in the components section, make a search for sound sensor, as shown in the below figure:
- As you can see in the above figure, we now have 3 sound sensors in the Proteus database.
- So, now I am gonna place all of them in my Proteus workspace and here's how they look like:
- They are all similar in operation, I just changed the base color as there are different versions available.
- Now in order to make them work, we have to add the hex file.
- Double click the sensor to open its Properties panel and in the Program File section browse to SoundSensorLibraryTEP.HEX file.
- We have placed this hex file in the Library folder, here's the screenshot:
- Now click OK and our sound detector sensor is ready for simulation.
- So, let's design a simple circuit to test it out, as shown in the below figure:
- When the TestPin will get HIGH, that means we have sound in the surroundings. In that case OUT Pin will also go HIGH.
- In case of silence, OUT Pin will remain LOW.
- Let's run our simulation and test it out as shown in the below figure:
- So you can see in the above figure that LED is ON when the TestPin is HIGH and its OFF when the TestPin is LOW.
- So that's how you can detect sound in Proteus.
- I have also created this video which will give you a better understanding of How to download and use this Sound Sensor Proteus Library.
I hope you will like this Proteus Library. If you have any suggestions regarding this Proteus Library then ask in the comments and we will try our best to resolve them. Thanks for reading. :)
Introduction to Arduino IDE
Hey Guys! Hope you are doing well. Today, I'll discuss the detailed Introduction to Arduino IDE, where IDE stands for Integrated Development Environment - An official software introduced by Arduino.cc, that is mainly used for writing, compiling and uploading the code in almost all Arduino modules/boards. Arduino IDE is open-source software and is easily available to download & install from Arduino's Official Site.
In this post, I'll take you through the brief Introduction of the Software, how you can install it, and make it ready for your required Arduino module. Let's dive in and get down to the nitty-gritty of this Software.
Where To Buy? |
---|
No. | Components | Distributor | Link To Buy |
1 | Arduino Uno | Amazon | Buy Now |
Introduction to Arduino IDE
- Arduino IDE is an open-source software, designed by Arduino.cc and mainly used for writing, compiling & uploading code to almost all Arduino Modules.
- It is an official Arduino software, making code compilation too easy that even a common person with no prior technical knowledge can get their feet wet with the learning process.
- It is available for all operating systems i.e. MAC, Windows, Linux and runs on the Java Platform that comes with inbuilt functions and commands that play a vital role in debugging, editing and compiling the code.
- A range of Arduino modules available including Arduino Uno, Arduino Mega, Arduino Leonardo, Arduino Micro and many more.
- Each of them contains a microcontroller on the board that is actually programmed and accepts the information in the form of code.
- The main code, also known as a sketch, created on the IDE platform will ultimately generate a Hex File which is then transferred and uploaded in the controller on the board.
- The IDE environment mainly contains two basic parts: Editor and Compiler where former is used for writing the required code and later is used for compiling and uploading the code into the given Arduino Module.
- This environment supports both C and C++ languages.
How to Download Arduino IDE
You can download the Software from Arduino main website. As I said earlier, the software is available for common operating systems like Linux, Windows, and MAX, so make sure you are downloading the correct software version that is easily compatible with your operating system.
- If you aim to download the Windows app version, make sure you have Windows 8.1 or Windows 10, as the app version is not compatible with Windows 7 or older version of this operating system.
- You can download the latest version of Arduino IDE for Windows (Non-Admin standalone version), by clicking below button:
Download Arduino IDE
The IDE environment is mainly distributed into three sections
- Menu Bar
- Text Editor
- Output Pane
As you download and open the IDE software, it will appear like an image below:
The bar appearing on the top is called Menu Bar that comes with five different options as follow
- File - You can open a new window for writing the code or open an existing one. The following table shows the number of further subdivisions the file option is categorized into.
- As you go to the preference section and check the compilation section, the Output Pane will show the code compilation as you click the upload button.
- And at the end of the compilation, it will show you the hex file it has generated for the recent sketch that will send to the Arduino Board for the specific task you aim to achieve.
- Edit - Used for copying and pasting the code with further modification for font
- Sketch - For compiling and programming
- Tools - Mainly used for testing projects. The Programmer section in this panel is used for burning a bootloader to the new microcontroller.
- Help - In case you are feeling skeptical about software, complete help is available from getting started to troubleshooting.
The Six Buttons appearing under the Menu tab are connected with the running program as follows.
- The checkmark appearing in the circular button is used to verify the code. Click this once you have written your code.
- The arrow key will upload and transfer the required code to the Arduino board.
- The dotted paper is used for creating a new file.
- The upward arrow is reserved for opening an existing Arduino project.
- The downward arrow is used to save the current running code.
- The button appearing on the top right corner is a Serial Monitor - A separate pop-up window that acts as an independent terminal and plays a vital role in sending and receiving the Serial Data. You can also go to the Tools panel and select Serial Monitor, or pressing Ctrl+Shift+M all at once will open it instantly. The Serial Monitor will actually help to debug the written Sketches where you can get a hold of how your program is operating. Your Arduino Module should be connected to your computer by USB cable in order to activate the Serial Monitor.
- You need to select the baud rate of the Arduino Board you are using right now. For my Arduino Uno Baud Rate is 9600, as you write the following code and click the Serial Monitor, the output will show as the image below.
- The main screen below the Menu bard is known as a simple text editor used for writing the required code.
- The bottom of the main screen is described as an Output Pane that mainly highlights the compilation status of the running code: the memory used by the code, and errors that occurred in the program. You need to fix those errors before you intend to upload the hex file into your Arduino Module.
- More or less, Arduino C language works similar to the regular C language used for any embedded system microcontroller, however, there are some dedicated libraries used for calling and executing specific functions on the board.
Arduino Libraries
- Libraries are very useful for adding extra functionality into the Arduino Module.
- There is a list of libraries you can check by clicking the Sketch button in the menu bar and going to Include Library.
- As you click the Include Library and Add the respective library it will be on the top of the sketch with a #include sign. Suppose, I Include the EEPROM library, it will appear on the text editor as
#include <EEPROM.h>
- Most of the libraries are preinstalled and come with the Arduino software. However, you can also download them from external sources.
Making Pins Input or Output
The digitalRead and digitalWrite commands are used for addressing and making the Arduino pins as an input and output respectively.
These commands are text sensitive i.e. you need to write them down the exact way they are given like digitalWrite starting with small "d" and write with capital "W". Writing it down with Digitalwrite or digitalwrite won't be calling or addressing any function.
How to Select the Board
- In order to upload the sketch, you need to select the relevant board you are using and the ports for that operating system.
- As you click the Tools on the menu, it will open like the figure below:
- Just go to the "Board" section and select the board you aim to work on. Similarly, COM1, COM2, COM4, COM5, COM7 or higher are reserved for the serial and USB board. You can look for the USB serial device in the ports section of the Windows Device Manager.
- The following figure shows the COM4 that I have used for my project, indicating the Arduino Uno with the COM4 port at the right bottom corner of the screen.
- After correct selection of both Board and Serial Port, click the verify and then upload button appearing in the upper left corner of the six-button section or you can go to the Sketch section and press verify/compile and then upload.
- The sketch is written in the text editor and is then saved with the file extension .ino.
It is important to note that the recent Arduino Modules will reset automatically as you compile and press the upload button the IDE software, however, the older versions may require the physical reset on the board.
- Once you upload the code, TX and RX LEDs will blink on the board, indicating the desired program is running successfully.
Note: The port selection criteria mentioned above are dedicated to Windows operating system only, you can check this
Guide if you are using MAC or Linux.
- The amazing thing about this software is that no prior arrangement or bulk of the mess is required to install this software, you will be writing your first program within 2 minutes after the installation of the IDE environment.
Arduino Bootloader
- As you go to the Tools section, you will find a bootloader at the end.
- It is very helpful to burn the code directly into the controller, setting you free from buying the external burner to burn the required code.
When you buy the new Arduino Module, the bootloader is already installed inside the controller. However, if you intend to buy a controller and put it in the Arduino module, you need to burn the bootloader again inside the controller by going to the Tools section and selecting the burn bootloader.
That's all for today. I hope I have given you everything you needed to know about Arduino IDE. If you are unsure or have any questions, you can ask me in the comment section below. I'd love to help you the best way I can. You are most welcome to keep us updated with your valuable feedback and suggestions, they help us provide you quality work so you keep coming back for what we have to offer. Thanks for reading the article.
How to use digitalWrite Arduino Command
Hey Friends! Hope you are doing well. Today, I'll discuss the details on
How to use digitalWrite Arduino Command. The digitalWrite command in Arduino is used for writing the status of the digital Pin. The Pin assigned to this command must be an OUTPUT pin so that it can transfer data to other components like LEDs, motors, and actuators and use them as per your needs and requirements.
Arduino boards have always been a great choice for both experts and newbies, as they come with built-in peripheral functions, and no need of external components is required to drive automation and develop some basic functions on the relevant project.
Basic Arduino Software is used as a compiler and no separate burner is required to burn the required code into the board. You can simply plug the board with the computer through a USB cable and burn and compile the program by a single click on the software.
How to use digitalWrite Arduino Command
- digitalWrite Arduino Command is used to write the status of digital Pins, and can make them either HIGH or LOW. The Pin needs to be an OUTPUT Pin.
- We are working on Arduino UNO, that comes with 14 digital I/O pins and 6 analog pins. You can set these pins as an input or output using pinMode based on your technical requirements.
- These pins are labeled as 0 to 13 on the board including two serial pins called Tx and Rx appearing at the start and marked as 1 and 0 pins respectively.
- We set Pins as an INPUT when we want to read or receive data from some component like sensors. And making pins as an OUTPUT will require a digitalWrite function to write or send data to the required device like LEDs, motors etc.
- When any pin is set an as OUTPUT using the pinMode Arduino Command, it will appear as HIGH or LOW depending on the voltage applying on the pin. For voltage above 3.3V it will appear as HIGH and for GND (ground) it will appear as LOW on the software.
- Before connecting an LED to pin, make sure to set pinMode as OUTPUT when you call the digitalWrite function, otherwise LED won't be flashing with clear bright light.
Syntax for digitalWrite Arduino
- Here’s the syntax used for digitalWrite Arduino command:
digitalWrite(pin, value);
where:
- The "pin" defines the Arduino pin number used. It has to be an OUTPUT Pin.
- And "value" defines if the pin will be HIGH or LOW.
- For example:
digitalWrite(8, HIGH);
Note:
- It is worth mentioning here that digitalWrite command doesn’t store or return any value unlike most of the commands used in Arduino that help in storing some value.
Difference between analogWrite and digitalWrite
Both terms analogWrite and digitalWrite are used for same purpose i.e. sending data from Arduino, but:
- The former is used to send data in analog form i.e. 0V - 5V.
- The later only defines the HIGH and LOW value of the desired pin where HIGH is an indication, pin is getting 5V and LOW is an indication pin is set to ground or zero voltage.
That's all for today. I hope you have found this article informative. If you are unsure or have any question, you can ask me in the comment section below. I'd love to help you according to the best of my expertise. You are most welcome to keep us updated with your valuable feedback and suggestion - they help us provide you quality work so you keep coming back every now and then. Thanks for reading the article.
How to use pinMode Arduino Command
Hi Friends! Hope you are doing well. In this post, I'll uncover the details on
How to use pinMode Arduino Command. The pinMode defines the Arduino Pins, if they are used as an input or output. The
INPUT_PULLUP is another option achieved by pinMode, that is mainly used to place a virtual pull-up resistor to the input pins.
We have started
Arduino Tutorials for Beginners quite a while now for the newbies, who are really interested to get a hands-on experience with Arduino. Generally, Arduino is known as a Microcontroller, but it is a step ahead of it. The PIC microcontrollers require some basic circuit to start with but Arduino brings revolution in the automation industry by removing the need of developing any basic circuit. Although
Atmega328 is the Microcontroller used in Arduino UNO.
Also, the burner is required to burn the program in
PIC Microcontrollers, while there is no need to connect separate burner with the Arduino - simply plug it with the computer through a USB cable and start playing with it.
In this tutorial, we will thoroughly discuss what is pinMode and how to use it in the Arduino module. Let's jump right in and explore what is this about and everything you need to know.
How to use pinMode in Arduino
- The Arduino Board comes with GPIO (general purpose input output) pins that can be used in two ways i.e. input, output.
- pinMode Arduino Command is used to define the operation of these Input/output pins, there are three types of modes that can be assigned using this command and are named as:
- OUTPUT.
- INPUT.
- INPUT_PULLUP.
- There are 14 digital and 6 analog pins in the module that mainly depend on the pinMode for setting up their mode of operation as an input or output.
- In this post we mainly discuss the Arduino UNO, that is based on ATmega328 microcontroller, however, you can use other modules like Pro Mini, Mega or Leonardo as per your needs and requirements. The pinMode works same in the module no matter what type of Arduino version you are using.
Syntax for pinMode Arduino
Here's the syntax for our pinMode Arduino command:
pinMode(pin#, mode);
where:
- Pin defines the Arduino pin number used.
- There are three types of modes that can be assigned to pins of Arduino, which are:
- OUTPUT
- INPUT
- INPUT_PULLUP
Let's use Pin # 8 of Arduino and assign all possible modes to it:
pinMode(8, OUTPUT);
pinMode(8, INPUT);
pinMode(8, INPUT_PULLUP);
Note:
- It is important to note that, unlike most of the functions used in the C code for Arduino module, this pinMode doesn't store or return any value.
- You have to use any one of these three modes at a time.
Modes of pinMode Arduino
- In the previous section, we have discussed the basic syntax of pinMode, and I hope you have pretty much got the basic idea behind it.
- The only thing worth mentioning here is the difference between INPUT and INPUT_PULLUP.
- So, here's a simple code where I have made Pin # 8 as an INPUT and read its status on Serial Monitor.
int Pin = 8;
int Status = 0;
void setup()
{
Serial.begin(9600);
pinMode(Pin, INPUT);
}
void loop()
{
Status = digitalRead(Pin);
if(Status == HIGH)
{
Serial.println("HIGH");
}
if(Status == LOW)
{
Serial.println("LOW");
}
}
- Let's have a look at the Serial Monitor:
- While taking the above image, Pin # 8 was in open state and we are getting just random values.
- We are getting these random values i.e. HIGH, LOW because our Pin#8 is neither connected to +5V nor GND.
- Arduino seems confused here, and we can remove this confusion by simply changing INPUT to INPUT_PULLUP.
- As we run the Serial Monitor, we will get something shown below:
- You can see how we are getting HIGH value only, while the pin is still in open state.
- We can conclude, when we have nothing on our INPUT pin then INPUT_PULLUP will make the pin HIGH.
Difference between Read and Write
There are two ways to send or receive data. You can either define the pin as an input that helps in reading the data from an external device like sensors. Or you can define pin as an output that helps in writing and sending a command to LEDs, motors or actuators for executing the desired functions.
That's all for today. I hope you have found this post informative as per your needs and requirements and can easily use this pinMode Arduino Command. If you are feeling skeptical or have any question, you can ask me in the comment section below. I'll try and help you according to the best of my expertise. Thanks for reading the article.
Rain Sensor Library for Proteus
Hello friends, I hope you all are doing great. In today's tutorial, I am going to share a new
Rain Sensor Library for Proteus. I have got a lot of requests for designing this sensor. So finally it has been designed by our team and is ready to use in your Proteus Simulations.
Rain Sensor, as the name shows, is used for detection of rain and is common sensor used in Embedded Systems Projects. Both analog and digital rain sensors are available these days but we have only designed the digital Rain Sensor. It will give digital output and its output will be HIGH when there's rain and will remain LOW if it won't detect any rain.
As Proteus is a simulation software and we can't actually bring the rain so that's why I have placed a TestPin. If you apply HIGH to this TestPin then that's means there's rain and if TestPin is LOW then it will give LOW output and will show there's no rain. So, now let's have a look at How to download and use this Rain Sensor Library for Proteus:
Rain Sensor Library for Proteus
- First of all, download this Rain Sensor Library for Proteus, by clicking the below button:
Rain Sensor Library for Proteus
- You will get a zip file so extract it and you will find these three Library Files in it:
- RainSensorsTEP.LIB
- RainSensorsTEP.IDX
- RainSensorsTEP.HEX
- Now place these Library files in the Library folder of your Proteus software.
Note:
- Now restart your Proteus software if its already open.
- In the components search box, make a search for rain sensor as shown in below figure:
- I have designed these two rain sensors so now place both of them in your workspace.
- If everything goes fine then you will get something as shown in below figure:
- So now we have to add the hex file in our sensor, so I am gonna use the Rain Sensor Blue and will double click it to open its Properties Panel.
- In the Properties Panel, you have to find the Program File section.
- In the Program File, browse to RainSensorsTEP.HEX File and select it.
- We have download this file and placed it in the Library folder of our Proteus software.
- Here's the screenshot of my Properties Panel of Rain Sensor:
- Now after adding the Hex file, click OK to close the Properties Panel.
- Your rain sensor is now ready to be used in your Proteus Simulation.
- So, let's design a simple circuit to have a look at How this Rain Sensor works in Proteus.
- Here's the screenshot of my simple Rain Sensor simulation in Proteus:
- I have attached LogicState to TestPin and LED on the output.
- As I have explained earlier that we can't bring rain in the Proteus software, that's why I have placed a TestPin.
- So, now when TestPin is LOW that means there's no rain and when you change the TestPin to HIGH then sensor will detect rain.
- I have run my simulation and here's the output:
So that was all for today. If you got into any trouble then ask in comments and I will help you out. Thanks for reading. Take care. :)
Infrared Sensor Library for Proteus
Hello friends, I hope you all are doing great. In today's tutorial, I am going to share a new
Infrared Sensor Library for Proteus. This IR sensor is not available in
Proteus and we are sharing this library for the first time. I hope it will help in your
Embedded Systems Projects particularly related to robotics and automation. So, if you want to work on this IR Sensor then I would suggest you to first design its simulation and then try your luck with hardware.
There are different types of Infrared Sensors & modules available in the market. Some of these modules have transmitter & receiver on separate chips and are mostly get activated when someone interrupts the light. The one we have designed has a transmitter & receiver on a single chip. The IR signal transmits from the IR transmitter and if it has some obstacle in front of it then it bounces back and received by the IR receiver. You should also have a look at this list of
New Proteus Libraries for Engineering Students. So, let's have a look at How to use this Infrared Sensor Library for Proteus:
Note:
- You should also have a look at:
Where To Buy? |
---|
No. | Components | Distributor | Link To Buy |
1 | Arduino Uno | Amazon | Buy Now |
Infrared Sensor Library for Proteus
- First of all, download the Library files of this IR Sensor by clicking the below button:
Infrared Sensor Library for Proteus
- After downloading this file extract it and you will find three Library files in it, named as:
- InfraredSensorsTEP.IDX
- InfraredSensorsTEP.LIB
- InfraredSensorsTEP.HEX
- Place all these three files in the Library folder of your Proteus software.
Note:
- Once you have added the files in the Library folder, then restart your Proteus software.
- In the components section, make a search for Infrared Sensor, as shown in below figure:
- Now place this IR Obstacle Sensor in your Proteus and if everything goes fine then you will get something as shown in below figure:
- As you can see in above figure that we have four pins on our Infrared sensor, which are:
- Vcc => You need to provide +5V to this pin.
- GND => It should be grounded.
- OUT => That's output pin and it will get HIGH when this sensor will find some obstacle in front and will remain LOW in normal condition.
- TestPin => As Proteus is a simulation software so we can't actually place something in front of this sensor. That's why I have used this TestPin. If this Pin is LOW, then sensor will remain normal and if it's HIGH then sensor will behave as it has something in front of it.
- Now double click this Infrared Sensor and its Properties Panel will open up.
- In the Program File section, browse to the file InfraredSensorTEP.HEX which you have already downloaded and placed in the Library folder of Proteus.
- Here's the screenshot of Properties Panel for this Infrared Sensor:
- I have encircled the Program File in above figure and you can see I have selected the InfraredSensorsTEP.HEX.
- So, now let's design a simple circuit and have a look at how to use this Infrared Sensor in Proteus.
- Here's the screenshot of Infrared Sensor Simulation in Proteus:
- So, now let's run our Proteus simulation and if everything goes fine then you will get results, as shown in the below figure:
- I will interface this sensor with different Microcontrollers e.g. Arduino, PIC Microcontroller etc. in my coming tutorial.
- As you can see in the above figure that when TestPin is LOW then OUT Pin is also LOW means there's no obstacle and when TestPin gets 1 then OUT Pin will go HIGH and that means we have some obstacle.
So, that's all for Infrared Sensor Library for Proteus. I hope it will help you guys in your engineering projects. Let me know if you have any suggestions. Take care & have fun !!! :)
Introduction to Arduino Uno
Hi Friends! Hope you are doing great. Today, I am going to give you a detailed Introduction to Arduino Uno. It is a microcontroller board developed by Arduino.cc and is based on Atmega328 Microcontroller. The first Arduino project was started in Interaction Design Institute Ivrea in 2003 by David Cuartielles and Massimo Banzi with the intention of providing a cheap and flexible way for students and professionals to learn embedded programming.
Arduino UNO is a very valuable addition in electronics that consists of a USB interface, 14 digital I/O pins(of which 6 Pins are used for PWM), 6 analog pins and an Atmega328 microcontroller. It also supports 3 communication protocols named Serial, I2C and SPI protocol. You should also have a look at this video presentation on Arduino UNO:
- Few main features of Arduino UNO are shown in the below figure:
Arduino UNO Features and Technical Specs |
No. |
Parameter Name |
Parameter Value |
1 |
Microcontroller |
Atmega328 |
2 |
Crystal Oscillator |
16MHz |
3 |
Operating Voltage |
5V |
4 |
Input Voltage |
5-12V |
5 |
Digital I/O Pins |
14 (D0 to D13) |
6 |
Analog I/O Pins |
6 (A0 to A5) |
7 |
PWM Pins |
6 (Pin # 3, 5, 6, 9, 10 and 11) |
8 |
Power Pins |
5V, 3.3V, Vin, GND |
9 |
Communication |
UART(1), SPI(1), I2C(1) |
10 |
Flash Memory |
32 KB (0.5KB is used by bootloader) |
11 |
SRAM |
2 KB |
12 |
EEPROM |
1 KB |
13 |
ICSP Header |
Yes |
14 |
Power sources |
DC Power Jack & USB Port |
I'll try to cover each and everything related to Arduino Uno, so you get a clear idea of what it does, its main features, working and everything you need to know. Let's get started.
Where To Buy? |
---|
No. | Components | Distributor | Link To Buy |
1 | Arduino Uno | Amazon | Buy Now |
Introduction to Arduino Uno
- Arduino Uno is a microcontroller board, developed by Arduino.cc, based on the Atmega328 microcontroller and is marked as the first Arduino board developed(UNO means "one" in Italian).
- The software used for writing, compiling & uploading code to Arduino boards is called Arduino IDE (Integrated Development Environment), which is free to download from Arduino Official Site.
- It has an operating voltage of 5V while the input voltage may vary from 7V to 12V.
- Arduino UNO has a maximum current rating of 40mA, so the load shouldn't exceed this current rating or you may harm the board.
- It comes with a crystal oscillator of 16MHz, which is its operating frequency.
- Arduino Uno Pinout consists of 14 digital pins starting from D0 to D13.
- It also has 6 analog pins starting from A0 to A5.
- It also has 1 Reset Pin, which is used to reset the board programmatically. In order to reset the board, we need to make this pin LOW.
- It also has 6 Power Pins, which provide different voltage levels.
- Out of 14 digital pins, 6 pins are used for generating PWM pulses of 8-Bit resolution. PWM pins in Arduino UNO are D3, D5, D6, D9, D10 and D11.
- Arduino UNO comes with 3 types of memories associated with it, named:
- Flash Memory: 32KB
- SRAM: 2KB
- EEPROM: 1KB
- Arduino UNO supports 3 types of communication protocols, used for interfacing with third-party peripherals, named:
- Serial Protocol
- I2C Protocol
- SPI Protocol
- You can download the Arduino UNO datasheet by clicking the below button:
Download Arduino UNO Datasheet
- Apart from USB, a battery or AC to DC adopter can also be used to power the board.
Features of Arduino Uno Board
- Arduino Uno comes with a USB interface i.e. USB port is added on the board to develop serial communication with the computer.
- Atmega328 microcontroller is placed on the board that comes with a number of features like timers, counters, interrupts, PWM, CPU, I/O pins and based on a 16MHz clock that helps in producing more frequency and number of instructions per cycle.
- It is an open-source platform where anyone can modify and optimize the board based on the number of instructions and tasks they want to achieve.
- This board comes with a built-in regulation feature that keeps the voltage under control when the device is connected to the external device.
- A reset pin is present in the board that resets the whole board and takes the running program in the initial stage. This pin is useful when the board hangs up in the middle of the running program; pushing this pin will clear everything up in the program and starts the program right from the beginning.
- There are 14 I/O digital and 6 analog pins incorporated in the board that allows the external connection with any circuit with the board. These pins provide flexibility and ease of use to the external devices that can be connected through these pins. There is no hard and fast interface required to connect the devices to the board. Simply plug the external device into the pins of the board that are laid out on the board in the form of the header.
- The 6 analog pins are marked as A0 to A5 and come with a resolution of 10bits. These pins measure from 0 to 5V, however, they can be configured to the high range using analogReference() function and AREF pin.
- Only 5 V is required to turn the board on, which can be achieved directly using a USB port or external adopter, however, it can support an external power source up to 12 V which can be regulated and limit to 5 V or 3.3 V based on the requirement of the project.
Arduino Uno Pinout
Arduino Uno is based on an AVR microcontroller called Atmega328. This controller comes with 2KB SRAM, 32KB of flash memory, 1KB of EEPROM. Arduino Board comes with 14 digital pins and 6 analog pins. ON-chip ADC is used to sample these pins. A 16 MHz frequency crystal oscillator is equipped on the board. The following figure shows the pinout of the Arduino Uno Board.
Arduino UNO Pin Description
There are several I/O digital and analog pins placed on the board which operates at 5V. These pins come with standard operating ratings ranging between 20mA to 40mA. Internal pull-up resistors are used in the board that limits the current exceeding the given operating conditions. However, too much increase in current makes these resisters useless and damages the device.
- LED. Arduino Uno comes with a built-in LED which is connected through pin 13. Providing HIGH value to the pin will turn it ON and LOW will turn it OFF.
- Vin. It is the input voltage provided to the Arduino Board. It is different than 5 V supplied through a USB port. This pin is used to supply voltage. If a voltage is provided through a power jack, it can be accessed through this pin.
- 5V. This board comes with the ability to provide voltage regulation. 5V pin is used to provide output regulated voltage. The board is powered up using three ways i.e. USB, Vin pin of the board or DC power jack.
- USB supports voltage around 5V while Vin and Power Jack support a voltage ranges between 7V to 20V. It is recommended to operate the board on 5V. It is important to note that, if a voltage is supplied through 5V or 3.3V pins, they result in bypassing the voltage regulator that can damage the board if the voltage surpasses its limit.
- GND. These are ground pins. More than one ground pins are provided on the board which can be used as per requirement.
- Reset. This pin is incorporated on the board which resets the program running on the board. Instead of physical reset on the board, IDE comes with a feature of resetting the board through programming.
- IOREF. This pin is very useful for providing voltage reference to the board. A shield is used to read the voltage across this pin which then selects the proper power source.
- PWM. PWM is provided by 3,5,6,9,10, 11pins. These pins are configured to provided 8-bit output PWM.
- SPI. It is known as Serial Peripheral Interface. Four pins 10(SS), 11(MOSI), 12(MISO), 13(SCK) provide SPI communication with the help of the SPI library.
- AREF. It is called Analog Reference. This pin is used for providing a reference voltage to the analog inputs.
- TWI. It is called Two-wire Interface. TWI communication is accessed through Wire Library. A4 and A5 pins are used for this purpose.
- Serial Communication. Serial communication is carried out through two pins called Pin 0 (Rx) and Pin 1 (Tx).
- Rx pin is used to receive data while Tx pin is used to transmit data.
- External Interrupts. Pin 2 and 3 are used for providing external interrupts. An interrupt is called by providing LOW or changing value.
Communication and Programming
Arduino Uno comes with the ability of interfacing with other Arduino boards, microcontrollers and computers. The Atmega328 placed on the board provides serial communication using pins like Rx and Tx.
The Atmega16U2 incorporated on the board provides a pathway for serial communication using USB com drivers. A serial monitor is provided on the IDE software which is used to send or receive text data from the board. If LEDs placed on the Rx and Tx pins will flash, they indicate the transmission of data.
Arduino Uno is programmed using Arduino Software which is a cross-platform application called IDE written in Java. The AVR microcontroller Atmega328 laid out on the base comes with built-in bootloader that sets you free from using a separate burner to upload the program on the board.
Applications of Arduino UNO
Arduino Uno comes with a wide range of applications. A larger number of people are using Arduino boards for developing sensors and instruments that are used in scientific research. Following are some main applications of the board.
- Embedded System
- Security and Defense System
- Digital Electronics and Robotics
- Parking Lot Counter
- Weighing Machines
- Traffic Light Count Down Timer
- Medical Instrument
- Emergency Light for Railways
- Home Automation
- Industrial Automation
There are a lot of other microcontrollers available in the market that are more powerful and cheap as compared to the Arduino board. So, why you prefer Arduino Uno?
Actually, Arduino comes with a big community that is developing and sharing knowledge with a wide range of audiences. Quick support is available pertaining to the technical aspects of any electronic project. When you decide Arduino board over other controllers, you don't need to arrange extra peripherals and devices as most of the functions are readily available on the board that makes your project economical in nature and free from a lot of technical expertise.
That's all for today. I hope you have got a lot of information regarding the Arduino Uno board. However, if you are unsure or have any questions you can approach me in the comment section below. I'd love to help you according to the best of my knowledge. Keep your feedback and suggestions coming; they help us provide you quality work that resonates with your needs and requirements. Thanks for reading the article.
Smoke Detector with Arduino & MQ2 Sensor
Hello everyone, I hope you all are doing great. In today's tutorial, we are gonna have a look at How to design a
Smoke Detector with Arduino. Its quite a simple project but if you are working on any security project then you must add this feature in it. You should also download this
Gas Sensor Library for Proteus, and design its simulation.
I will use gas sensor MQ2 for this project. I have purchased MQ2 Gas Sensor module as its quite easy to interface with Arduino. Arduino board I'm using is Arduino UNO. I have also designed an
LPG Gas Leak Detect using Arduino using this MQ2 Sensor. So, let's get started with How to design Smoke Detector with Arduino & MQ2 Sensor.
Smoke Detector with Arduino & MQ2 Sensor
- First of all, we need to connect some jumper wires between Arduino and MQ2 smoke sensor shield.
- Here's the image of our Gas sensor and you can see, it has four pins in total.
- This gas sensor has four pins in total, which are:
- Vcc: We need to provide +5V.
- GND: We need to ground it.
- D0: Digital Output.
- A0: Analog Output.
- So now you will need four male to female jumper wires and connect them as shown in below figure:
- Sensor's pins are labelled on the back side and I have connected these four pins as follows:
- White Wire: Vcc of Sensor connected with +5V of Arduino.
- Black Wire: GND of Sensor connected with GND of Arduino.
- Grey Wire: D0 of Sensor connected with Pin # 8 of Arduino.
- Orange Wire: A0 of Sensor connected with A0 of Arduino.
- So, now let's design our code in Arduino software in which we will detect whether there's smoke around or not.
- I'm gonna use the analog output of our sensor and will first display the analog value in my Serial Monitor.
- I have used the below code, so copy it and upload in your Arduino board:
int Input = A0;
int SensorVal = 0;
void setup() {
Serial.begin(9600);
pinMode(Input, INPUT);
Serial.println("Interfacing of Smoke Sensor with Arduino");
Serial. println("Design by www.TheEngineeringProjects.com");
Serial.println();
}
void loop() {
SensorVal = analogRead(Input);
Serial.println(SensorVal);
delay(500);
}
- Now open the Serial Monitor of Arduino to check the analog values coming from our sensor.
- If everything goes fine then you will get something like this in your Serial Monitor:
- You can see we are getting the values in range of 420 to 450.
- You should read How to do Arduino Serial Communication, if you don't know how to get data serially.
- Now let's place a burning cigarette near it for smoke. (Cigarettes are injurious to health :P )
- When the sensor will sense smoke in its surroundings then its value will start to increase and in my case it reached to around 650.
- So, let's place a check in our Arduino coding to detect whether there's smoke or not.
- So add below code in your Arduino software and upload it to your Arduino board.
int Input = A0;
int SensorVal = 0;
int Check = 0;
void setup() {
Serial.begin(9600);
pinMode(Input, INPUT);
Serial.println("Interfacing of Smoke Sensor with Arduino");
Serial. println("Design by www.TheEngineeringProjects.com");
Serial.println();
}
void loop() {
SensorVal = analogRead(Input);
if((SensorVal > 500) && (Check == 1))
{
Serial.println("Smoke Detected . . .");
Check = 0;
}
if((SensorVal < 500) && (Check == 0))
{
Serial.println("All Clear . . .");
Check = 1;
}
//Serial.println(SensorVal);
delay(500);
}
- After uploading the code to Arduino, open your Serial Monitor.
- If everything goes fine then you will get something as shown in below figure:
- Now let me bring the cigarette close to get some smoke. (Cigarettes are injurious to health :P )
- You will get the warning as soon as it will detect smoke as shown in below figure:
- We got the detection of smoke in our Serial Terminal.
So, that's how we can easily design a Smoke Detector with Arduino & MQ2 Sensor. I think now you can quite easily design this smoke detector project at home. I hope you will enjoy it. Will meet you guys in next tutorial. Till then take care and have fun !!! :)
Magnetic Reed Switch Library for Proteus
Hello friends, I hope you all are doing great. In today's tutorial, I am going to share new
Magnetic Reed Switch Library for Proteus. We are quite proud to share it as its not been designed before. Our TEP Team has designed it and I think they need a little appreciation. :P You can interface it with any
Microcontroller like Arduino, PIC or
8051 Microcontroller etc.
As Proteus is a simulation software so we can't produce magnetic field in it. That's why, we have placed a TestPin and when you provide HIGH Signal to that TestPin then it will act as it has magnet around. Similarly, if you provide LOW Signal to that TestPin then it will behave normal and will sense no magnet around. Rite now, we have just designed two Magnetic Reed Switches but soon we will design other Reed Switches as well. So, let's get started with How to download and use
Magnetic Reed Switch Library for Proteus.
Magnetic Reed Switch Library for Proteus
- First of all, download this Magnetic Reed Switch Library for Proteus by clicking the below button:
Download Proteus Library Files
- You will get a .rar file so unzip it using winrar.
- Inside this .rar file, you will find three Proteus Library files, named as:
- MagneticReedSwitchesLibraryTEP.IDX
- MagneticReedSwitchesLibraryTEP.DLL
- MagneticReedSwitchesLibraryTEP.HEX
- Place all these three files in the Library folder of your Proteus 7 or 8 Professional.
Note:
- Here are the images of these real Magnetic Reed Switch Modules along with our designed modules in Proteus:
- We have designed these two modules, both of these modules give digital output only in Proteus but in real the reed module with red color also gives analog output.
- We are not yet able to produce analog output in Proteus, so that's why we have only digital output. :)
- Now I hope that you have placed all those three Proteus Library files in the Library folder of your Proteus software, so open your Proteus software or restart it.
- In Proteus software, go to your components search box and make a search for Magnetic Reed Switch as shown in below figure:
- Now place both of these modules in your Proteus software and they will look something, as shown in below figure:
- Double click any of these modules and its Properties panel will open up.
- Now in the Program File section, browse to our downloaded Library file MagneticReedSwitchesLibraryTEP.HEX as shown in below figure:
- Now click OK to close this Properties window.
- You can see we have four pins in total attached to our Magnetic Reed Switch, which are:
- Vcc: We have to provide +5V at this pin.
- GND: We have to provide Ground (0V) at this pin.
- D0: That's the Output Pin, it will be HIGH when some magnet is around otherwise remain LOW.
- TestPin: As Proteus a simulation so we can't provide magnetic field, that's why we have palced this TestPin. If TestPin is HIGH then it means magnetic field is around and if its LOW then there's no magnet around.
- I hope you have understood the pinout of this Reed Switch, so now let's design a simple simulation to test them out.
- So, design a simple circuit in Proteus as shown in below figure:
- Now run your simulation, and change the Logic State from 0 to 1, which is connected at TestPin.
- If everything goes fine then you will get such results:
- As you can see in the above figure that D0 Pin is HIGH when I changed the Logic State from 0 to 1 and that's why LED attached at D0 Pin is now ON.
- I have also designed a similar simulation for the other Magnetic Reed Switch and its ON state is shown in below figure:
- I have already added both of these simulations in the above download file.
- So, first add your Library and then run these simulations.
- I will soon interface this sensor with different Microcontrollers like Arduino, 8051 Microcontroller, PIC Microcontroller etc.
So, that's was all for today. I hope you will enjoy this Magnetic Reed Switch Library for Proteus and will use it in your Engineering Projects. Thanks for reading & have fun !!! :)