LED Blink Speed / Analog Sketch

Share on facebook
Share on google
Share on twitter
Share on linkedin
A VPN is an essential component of IT security, whether you’re just starting a business or are already up and running. Most business interactions and transactions happen online and VPN

I’m doing a series of mini projects that will build up to a motor controller, but need to get some basics across first. This first sketch is a Arduino, reading a potentiometer on an analog port, and using that data to control the blink speed of a LED on a PWM port. The potentiometer (pot) connects to ground and +5 on the outside legs, and Analog 0 on the center leg. The LED connects + to pin 7 and – to a 270 ohm resistor connected to ground. The value of the pot determines the delay on the LED. This not true PWM, that’s coming next.

(video uploaded to youtube)

int sensorPin = A0;    // Analog input pin to pot
int ledPin = 7; // PWM pin to LED
int sensorValue = 0; // variable to store pot value

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);
  // turn the ledPin on
  digitalWrite(ledPin, HIGH);
  // stop the program for <sensorValue> milliseconds:
  // turn the ledPin off:
  digitalWrite(ledPin, LOW);
  // stop the program for for <sensorValue> milliseconds:

Steve Spence

Steve Spence

Leave a Reply

Leave a Comment

Your email address will not be published. Required fields are marked *