LAB: Pulse Width Modulation (PWM)
Last updated
Was this helpful?
Last updated
Was this helpful?
āđāļāđāļēāđāļāļŦāļĨāļąāļāļāļēāļĢāļāļģāļāļēāļāļāļāļ PWM
āļŠāļēāļĄāļēāļĢāļāļŠāļĢāđāļēāļāļāļĢāļēāļāļŠāļąāļāļāļēāļ PWM āđāļāļĒāđāļāđ Arduino board āđāļāđ
āļāļēāļĢāļāļāļĨāļāļāļāļĢāļąāļāļāđāļē potentiometer āļāļāđāļāđ duty cycle 50% āļāļąāļāļāļķāļāļāļĨāļāļĢāļēāļ āđāļĨāļ°āļāđāļēāļāļāđāļēāļāļ§āļēāļĄāļāļĩāđ(Hz), āđāļĢāļāļāļąāļ(V) āļāļēāļāļāļĢāļēāļāļāļĩāđāđāļāđ
Arduino mega2560
1
myDAQ
1
Potentiometer
1
Arduino IDE
āđāļāļĢāđāļāļĢāļĄ NI ELVISSmx
//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 āļāļĩāđāđāļāđāļĢāļąāļāļĄāļāļāļŦāļĄāļēāļĒ