Friday, June 18, 2021

Project 4: Arduino Analog Input - Control LED Blinking

Project 4: Arduino Analog Input - Control LED Blinking

Main Ideas:

Introduction to the new electronic parts potentiometer (variable resistor). Introduction to the Analog Inputs and analogRead function. 






Project Description

We will use the potentiometer connected to analog pin (A0) to simulate inputs signal from sensor and we will use the analog input signal to control the speed of LED blinking.

Circuit

  • RED LED
  • 1* Pushbutton 
  • 2* 10K Resistor
  • 1* 1K Resistor
  • Arduino UNO



Code

int sensorValue = 0;

void setup()

{

  pinMode(A0, INPUT);

  pinMode(13, OUTPUT);

}

void loop()

{

  // read the value from the sensor

  sensorValue = analogRead(A0);

  // turn the LED on

  digitalWrite(13, HIGH);

  // pause the program for <sensorValue> millseconds

  delay(sensorValue); // Wait for sensorValue millisecond(s)

  // turn the LED off

  digitalWrite(13, LOW);

  // pause the program for <sensorValue> millseconds

  delay(sensorValue); // Wait for sensorValue millisecond(s)

}


No comments:

Post a Comment