Wednesday 25 November 2015

Arduino Lab 4: Potentiometer (Twist Pot)

Purpose:
This lab will teach you how to make one LED blink faster or slower when you turn the potentiometer.
Modified: The modified version will make the LED fade when you turn the potentiometer.

Equipment:
-1 potentiometer (10k ohms)
-1 330 ohm resistor
-1 LED (any colour)
-1 wire (red)
-1 wire (black)
-4 wires (any colour) 
-1 USB cable 
-1 breadboard 
-1 Arduino UNO

Program Details:
-Download Arduino here

Time to Program and Complete:
-Approximately 35 min (for 2 parts)

Results:
-There were some spelling mistakes in the code, but after I fixed them it worked completely fine.

Photo/Video:




Modified Program






Program:
int sensorPin = A0;
int ledPin = 13;
int sensorValue = 0;
void setup()
{
  pinMode (ledPin , OUTPUT);
}
void loop()
{
  sensorValue = analogRead(sensorPin);
  digitalWrite(ledPin , HIGH);
  delay(sensorValue);
  digitalWrite(ledPin, LOW);
  delay(sensorValue);
}

Program Modifications:
--Modified version-- To make the LED fade when we turn the potentiometer.

int sensorPin = A0;
int ledPin = 9;
int senorValue = 0;
void setup()
{
  pinMode(ledPin, OUTPUT);
}
void loop()
{
  int value = analogRead(sensorPin) / 4;
  analogWrite (ledPin, value);
}

Helpful Tips:
-Check spelling

References:
-Arduino website: arduino.cc 
-New Innovator: Lab 4

No comments:

Post a Comment