LAB: Pulse Width Modulation (PWM)
āļāļļāļāļāļĢāļ°āļŠāļāļāđ
āđāļāđāļēāđāļāļŦāļĨāļąāļāļāļēāļĢāļāļģāļāļēāļāļāļāļ PWM
āļŠāļēāļĄāļēāļĢāļāļŠāļĢāđāļēāļāļāļĢāļēāļāļŠāļąāļāļāļēāļ PWM āđāļāļĒāđāļāđ Arduino board āđāļāđ
LAB: āļāļēāļĢāļŠāļĢāđāļēāļāļŠāļąāļāļāļēāļ PWM
āļāļēāļĢāļāļāļĨāļāļāļāļĢāļąāļāļāđāļē potentiometer āļāļāđāļāđ duty cycle 50% āļāļąāļāļāļķāļāļāļĨāļāļĢāļēāļ āđāļĨāļ°āļāđāļēāļāļāđāļēāļāļ§āļēāļĄāļāļĩāđ(Hz), āđāļĢāļāļāļąāļ(V) āļāļēāļāļāļĢāļēāļāļāļĩāđāđāļāđ
āļāļļāļāļāļĢāļāđāļāļāļĨāļāļ
Component
Quantity
Arduino mega2560
1
myDAQ
1
Potentiometer
1

āđāļāļĢāđāļāļĢāļĄ
Arduino IDE
āđāļāļĢāđāļāļĢāļĄ 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
}
āļāļąāļāļāļķāļāļāļĨāļāļēāļĢāļāļāļĨāļāļ
āļāļąāļāļāļķāļāļ āļēāļāļ§āļāļāļĢ āļāļĨāļāļĢāļēāļ, serial monitor āđāļĨāļ°āļāļāļīāļāļēāļĒāļāļēāļĢāļāļāļĨāļāļāļĨāļ template āļāļĩāđāđāļāđāļĢāļąāļāļĄāļāļāļŦāļĄāļēāļĒ
Last updated
Was this helpful?