Instructions

Deliverable A

Create your own code to generate a PWM signal at a configurable frequency. Use a 4-bit input, so the full range should be represented by 0-15. For example, an input of 4 should produce a 25% duty cycle. Write code that uses your PWM to change the brightness of an LED from 0 to full in 4 seconds (so increase 25% each second). Test that code at the following PWM frequencies: 20Hz, 50Hz, 100Hz, 200Hz. Demonstrate this at all four frequencies.

Deliverable B

For this deliverable, we want to connect a motor to the Arduino. The previous Elegoo tutorial linked uses an outdated kit to run a motor. Instead, use this link: https://download.elegoo.com/01%20STEM%20Kits/02%20Mega%202560/Complete/ELEGOO%20The%20Most%20Complete%20Starter%20Kit%20for%20MEGA%20V1.0.2023.05.05.zip. Follow Lesson 29 to connect and test your motor.

Once you are done with that, try to control your motor with the PWM code you wrote in Deliverable A. Does it work at any frequency?

When you are done experimenting with your PWM code, use the hardware PWM (analogWrite) to control the motor, increasing speed from 0 to full (255) in 4 seconds. Demonstrate this.

Deliverable C

For this deliverable, you will build a “Useless Machine”. For example, see: https://www.youtube.com/watch?v=kproPsch7i0. You are encouraged to be creative when accomplishing this! To receive full credit, you need to:

  • Read when a physical switch of some kind is turned on.
  • Use an actuator of some kind to physically turn the switch off in a reasonable amount of time to demonstrate in class.

You are encouraged to use anything in your kit to accomplish this. Be creative with your interpretation of what a “switch” and “actuator” mean. When in doubt, ask the instructor if your solution meets the objective. You do not need to build a rugged, permanent setup for this. You only need to make sure it can survive a demo. Switches and other hardware will be available to borrow.

Turn in to Blackboard

  • A zip file with the following code named after the deliverable it corresponds to:
    • Deliverable A (4 points)
    • Deliverable B (4 points)
    • Deliverable C (4 points)
  • A PDF with answers to the following questions. If needed, use the datasheet for the AVR processor used on the Arduino Mega (found here: https://www.microchip.com/en-us/product/atmega2560) to answer these questions.
    1. At what frequency did you find that your PWM controlled an LED without visible blinking? (4 points)
    2. At what frequency, if any, did you find that your PWM (not the hardware PWM) controlled a motor without chattering (stopping and starting frequently)? (4 points)
    3. How many PWM pins are on the Arduino Mega (AVR ATMEGA2560)? (5 points)
    4. What is the frequency used by each pin on the Arduino Mega (AVR ATMEGA2560)? (5 points)

Rubric

Demo

  • Deliverable A
    • 5 points
  • Deliverable B
    • 10 points
  • Deliverable C
    • 15 points