LAB: Pulse Width Modulation (PWM)

āļˆāļļāļ”āļ›āļĢāļ°āļŠāļ‡āļ„āđŒ

  1. āđ€āļ‚āđ‰āļēāđƒāļˆāļŦāļĨāļąāļāļāļēāļĢāļ—āļģāļ‡āļēāļ™āļ‚āļ­āļ‡ PWM

  2. āļŠāļēāļĄāļēāļĢāļ–āļŠāļĢāđ‰āļēāļ‡āļāļĢāļēāļŸāļŠāļąāļāļāļēāļ“ PWM āđ‚āļ”āļĒāđƒāļŠāđ‰ Arduino board āđ„āļ”āđ‰

LAB: āļāļēāļĢāļŠāļĢāđ‰āļēāļ‡āļŠāļąāļāļāļēāļ“ PWM

āļāļēāļĢāļ—āļ”āļĨāļ­āļ‡āļ›āļĢāļąāļšāļ„āđˆāļē potentiometer āļˆāļ™āđ„āļ”āđ‰ duty cycle 50% āļšāļąāļ™āļ—āļķāļāļœāļĨāļāļĢāļēāļŸ āđāļĨāļ°āļ­āđˆāļēāļ™āļ„āđˆāļēāļ„āļ§āļēāļĄāļ–āļĩāđˆ(Hz), āđāļĢāļ‡āļ”āļąāļ™(V) āļˆāļēāļāļāļĢāļēāļŸāļ—āļĩāđˆāđ„āļ”āđ‰

āļ­āļļāļ›āļāļĢāļ“āđŒāļ—āļ”āļĨāļ­āļ‡

Component
Quantity

Arduino mega2560

1

myDAQ

1

Potentiometer

1

āđ‚āļ›āļĢāđāļāļĢāļĄ

  1. Arduino IDE

  2. āđ‚āļ›āļĢāđāļāļĢāļĄ NI ELVISSmx

Schematic

Circuit Diagram

Code

//Arduino Mage 2560 read potentiometer and write LED
int sensorPin = A8;    // connect this pin to potentiometer
int ledPin = 2;      // connect this pin to external LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT); // set this pin to output
  Serial.begin(9600); // start serial monitor
}


void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  sensorValue = map(sensorValue, 0,1023,0,255);
  // turn the ledPin on
  analogWrite(ledPin, sensorValue);
  Serial.println(sensorValue); // bright LED with read value
  
}

āļšāļąāļ™āļ—āļķāļāļœāļĨāļāļēāļĢāļ—āļ”āļĨāļ­āļ‡

  1. āļšāļąāļ™āļ—āļķāļāļ āļēāļžāļ§āļ‡āļˆāļĢ āļœāļĨāļāļĢāļēāļŸ, serial monitor āđāļĨāļ°āļ­āļ˜āļīāļšāļēāļĒāļāļēāļĢāļ—āļ”āļĨāļ­āļ‡āļĨāļ‡ template āļ—āļĩāđˆāđ„āļ”āđ‰āļĢāļąāļšāļĄāļ­āļšāļŦāļĄāļēāļĒ

Last updated

Was this helpful?