How to use analogWrite in Arduino?

Hey Fellas! Hope you are getting along with life pretty well. This post is another addition in this Arduino Tutorial for Beginners series. Today, I'll discuss How to use analogWrite in Arduino? The analogWrite is mainly used to update the status of analog pins and is also used to map the analog values on the PWM (Pulse Width Modulation) pins. You can check the article that I have posted previously on How to use analogRead in the Arduino - this command addresses the analog pins on the board and reads its status, while today's one does the exact opposite. In this post, I'll try to break down each and everything related to analogWrite in simple steps, so you can grab the main idea pretty well. Let's jump right in.

How to use analogWrite in Arduino?

  • The analogWrite Arduino command is used to update the status of analog pins and also used to address the PWM pins on the board.
  • The PWM pins are 8-bit pins, terming that you can set the duty cycle somewhere between 0 -255.
  • The duty cycle is described as the amount time the signal switches between ON and OFF condition. It is mainly written in percentage.
  • If the signal remains turned ON half of the total duty cycle and OFF in another half, then the duty cycle will be 50%.
  • The analogWrite comes handy when you plan to control the motor speed or the intensity of any LED.
  • The value you write on the PWM pins will control the speed.
  • For example, if you intend to run the motor at full speed, you will set the value 255 i.e. the maximum value it can handle that will ultimately run the motor at full speed.
  • Similarly, setting value as "0" will be sending no signal and motor won't start.
  • And if the motor requires to be run at half speed, then you will set the value 127 or 128 -  half of the maximum value that will cause the motor to be running at half speed.
  • Arduino Uno comes with PWM pins available on digital pin number 3,5,6 and 9,10,11. You can put any number, out of these pins.
  • Now let's have a look at How to use analogWrite Arduino command:
Syntax

analogWrite(int pin, int value);

where:
  • "pin" is the pin number you are targeting.
  • "value" is the duty cycle that can be set anywhere between 0  to 255 where former indicates the OFF condition and later indicates the system is running at full speed.
Example

analogWrite(10, 175);

Note: The analogWrite command doesn't return or store any value, unlike analogRead that returns value anywhere between 0 to 1023 depending on the voltage it gets in return from the connected sensor or device. The Arduino IDE is an official software used to program the Arduino Boards. It is an open source software, giving you the flexibility to program the Arduino Board as per your technical needs and requirements. It is free of cost and help is readily available on the Arduino site in case you feel any difficulty in shaping the desired code on the board. That’s all for now. I'll be writing more articles on how to code Arduino. If you are feeling skeptical about anything, making it difficult for you to grab the basic idea, you can approach me in the comment section below. I’d love to help you the best way I can. In the coming tutorial, we will have a look at How to use Arduino PWM Pins. Thanks for reading the article.

Introduction to CR1220

Hi Fellas! Hope you are getting along with life pretty well. I am back to give you a daily dose of useful information. Today, I'll unlock the details on the Introduction to CR1220.  It is known as a lithium coin battery that comes with a high voltage around 3V and encompasses an ultra-compact design, helping you gid rid of the hassle of buying two or three extra traditional batteries, saving both cost and space required to adjust these cells in the relevant devices. In this post, I'll try to cover each and everything related to CR1220, breaking down its details in simple steps you can get a hold what is this about and how it is used for. Let's dive in and explore everything you need to know about this battery.

Introduction to CR1220

  • CR1220 is a button cell, also known as lithium coin battery, that is mainly used in high power devices such as keyless entry devices, glucose monitors, heart-rate monitors, and toys & games.
  • It comes in cylindrical shape and can retain power for a maximum period of time. If it is spared alone for one year, it will discharge only 1% of the total battery capacity.
  • This battery is slightly different from CR2032 in terms of battery capacity, weight and lithium content as former comes with 35mAh capacity with 0.8g weight and 0.006 grams lithium content while later contains 285mAh capacity, 3gram weight, and 0.109gram lithium content.
  • It features small and compact shape, making it an ideal choice for hard to reach places.
  • Prior precautions are required to keep this device safe and away from the kids. If swallowed, this device can cause a severe health damage or death in some cases due to the chemical composition it incorporates.
  • The output voltage it can deliver is around 3V, enough to drive some small devices like wristwatches and glucose monitors.
  • Both positive and negative electrodes are stainless steel SUS430 and Nickel plated.
  • It is important to note that, no coatings or other foreign objects are required on the surface of terminals that can severely affect the real use or performance of this coin cell.
  • Battery compartments work best to encapsulate this battery, making it safe and away from the kids. They can be designed using two methods: an extra mechanical tool like a screwdriver is required to unlock the battery compartment or you can apply two independent movements of the securing mechanism by a single hand.
  • These battery compartments come with an ability to retain different cells where capacities will vary by size.
CR1220 Features
Features of any device can help you better understand major functions associated with it, helping you make a final decision before picking the device for your relevant project. Following are the main features of CR1220.
Classification Coin Cell Battery or Lithium Energizer
Product Name CR1220
Output Voltage 3V
Chemical System Lithium / Manganese Dioxide (Li/MnO2)
Capacity 35 mAh
Energy Density 153 milliwatt hr/g
Weight 0.8 gram
Lithium Content 0.006 grams
Self Discharge 1% / year
Type Non-Rechargeable
Maximum Operating Temperature 70 °C
Minimum Operating Temperature -30 °C
 
  • Some cells are made from different chemical compositions, making them mechanically interchangeable which may directly service life voltage stability of the cell.
CR1220 Dimensions
Following figure shows the dimensions of CR1220.
  • The dimensions are given in mm vs inches.
  • Pay special heed while selecting the coin cell for a required device, the wrong pick can intensively affect the device performance, resulting in a sheer hindrance in the operating process.
CR1220 Applications
CR1220 comes with a wide range of applications that require temporary power on the fly. Following are some major applications of this coin cell.
  • Keyless entry devices
  • Glucose monitors
  • Implantable cardiac defibrillators
  • Heart-rate monitors
  • Artificial cardiac pacemakers
  • Toys & games
That's all for today. I hope you have found this read useful. If you are feeling skeptical 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 expertise. Feel free to keep us updated with your valuable feedback and suggestion, so we keep providing quality work and you keep visiting us for what we have to offer. Thanks for reading the article.
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