Project Three – Analog Input v1.0b

Introduction

The purpose of this sketch is to demonstrate a form of analog input using the potentiometer Grove. We will use this to set the delay for our blinking LEDs from project one.

Connect the LED module to the D1/D2 Digital I/O jack, like it was in Projects 1 and 2. Arduino Pin D1 powers the LED Grove’s SIG connector, and Arduino Pin D2 connect to the LED Grove’s NC connector.

Connect the Potentiometer module to the Analog A0/A1 input jack.

The Potentiometer module produces an analog voltage on its SIG output, which is connected to Arduino A0 analog input on the A0/A1 input jack.

Now upload the following Arduino sketch:

// Project Three - Analog Input
//

void setup()
{
  pinMode(1, OUTPUT);
}

void loop()
{
  digitalWrite(1, HIGH);
  delay(analogRead(0));
  digitalWrite(1, LOW);
  delay(analogRead(0));
}

The maximum delay value is 1023, as this is the upper limit of the value returned by the analogRead() function. You could use mathematical functions to increase or scale down the range of the delay.

Help us make it better

Welcome to the new documentation system of Seeed Studio. We have made a lot of progress comparing to the old wiki system and will continue to improve it to make it more user friendly and helpful. The improvement can't be done without your kindly feedback. If you have any suggestions or findings, you are most welcome to submit the amended version as our contributor via Github or give us suggestions in the survey below, it would be more appreciated if you could leave your email so that we can reply to you. Happy Hacking!