Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering

Tutorial 7: DC motor speed control using ATtiny85

By Ashutosh Bhatt

In the previous two tutorials of this series, we have seen how to vary the intensity (brightness) of LEDs using the PWM output of ATtiny85. In this tutorial, we shall use a PWM output to vary the speed of a DC motor.

DC Motor speed varies as the potentiometer is varied. As we have learned in the previous tutorial, the potentiometer gives an analog output of 0 to 5 V. ATtiny85 takes this analog input and generates a PWM output to vary the speed of the DC motor.  Let’s see how it is done.

If you are not following this tutorial series from the beginning, then you should go through the following two tutorials that explain and demonstrate how to work with ATtiny85 and a step-by-step guide on how to build a hello world (LED blinking) application.
How to work with ATtiny85
LED blinking using ATtiny85

Circuit diagram

Circuit connections
The circuit is built using only 3-4 components. The potentiometer (pot) has three pins and the middle (slider) terminal is connected to pin 2, analog input pin A1. The other two terminals of the pot are connected with 5V and Gnd, as shown. PWM output pin PB0 drives DC motor using Darlington transistor TIP122. It is connected to the base input of TIP122 through a current limiting resistor of 220 Ω. The collector output of TIP122 drives the DC motor, and the emitter is connected to ground. The motor is given a 12 V supply, and ATtiny85 is given a 5 V supply, as shown.

Circuit operation
When the pot is varied, it gives analog voltage output from 0 to 5V. This is shown as an analog input to ATtiny85. The inbuilt ADC of ATtiny85 will convert this into digital, giving a digital value between 0 to 1023 (because of 10-bit resolution). Based on this value, it will generate PWM output on PB0 pin to vary the speed of the DC motor

Program
The program is written in Arduino IDE software using a C programming language. It is compiled, and an HEX file is created that is downloaded into the internal FLASH of ATtiny85

Program logic
Program logic is straightforward. First, ATtiny85 will read analog voltage on analog input pin A1, and it will get the value between 0 to 1023. This value will generate PWM output on pin 5 (PB0) by dividing this value by 4. The value is divided by four because the PWM value is between 0 to 255 while the input range is 0 to 1023.

ATtiny dc motor codeIn the next tutorial, we shall learn to generate different color using RGB LED.

You may also like:


  • ATtiny85 microcontroller tutorials, Part 5: LED intensity control using ATtiny85

  • ATtiny85 microcontroller tutorials, Part 3: Building LED blinking application using…

  • ATtiny85 microcontroller tutorials, Part 4: LED chaser using ATtiny85
  • ATtiny85
    ATtiny85 microcontroller tutorials, Part 1: Introduction

  • ATtiny85 microcontroller tutorials, Part 2: Working with ATtiny85

Filed Under: Tutorials
Tagged With: Arduino, ATtiny85
 

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Adjustable 0 to 30V 2A DC Power Supply Circuit (Part 1/13)
  • Adjustable +/- 1.25V to +/-22V 1A Power Supply Circuit (Part 2/13)
  • Adjustable 0 to 15V 1A Mini Power Supply (Part 3/13)
  • Constant 12V Power Supply for LED Circuits (Part 4/13)
  • Constant +/-9V DC Symmetrical Power Supply Circuit (Part 5/13)
  • Making a Circuit Breaker (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

“ee

“ee

“ee

“ee

“ee

“ee

Recent Articles

  • STMicroelectronics and MACOM announce successful RF GaN-on-Si prototypes
  • Infineon expands its CoolSiC portfolio
  • STMicroelectronics and AWS collaborate for secure IoT connections
  • Pet feeding system using WhatsApp (protocol bridging with MQTT)
  • STMicroelectronics launches new MDmesh MOSFETs

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd ldr led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics Research robot samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • RFIC LNA cascode base and ground layout problem
  • Unable to launch virtuoso: libvisadev.so error
  • DIY test leads - source for lead ends?
  • P-Channel MOSFET always on
  • Space Vector PWM Help Needed

RSS Electro-Tech-Online.com Discussions

  • Adding Current Limit Feature to a Buck Converter
  • 24v dc relays not de-energising
  • How do I test amplifier speaker output polarity?
  • How to get lots of PCBs made cheap?
  • XOR Gate Circuit From Diodes
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
  • Women in Engineering