Things used in this project

Hardware components:
Punch Through LightBlue Bean+
×1
SeeedStudio Grove Rotary Angle Sensor
×1
SeeedStudio Grove LED Bar
×1
Software apps and online services:
Ide web
Arduino IDE
Punch Through Bean Loader

Code

Grove LED Bar with Rotary ControllerArduino
#define ROTARY_ANGLE_SENSOR A3 // The input pin used for the sensor
#define ADC_REF 5 // This matches the operating voltage we set to 5V
#define GROVE_VCC 5 // VCC of the grove interface which is often 5V
#define NUM_OF_LEDS 10 // Number of LEDs in the LED bar

#include <Grove_LED_Bar.h>

Grove_LED_Bar LEDbar(A4, A5, 1); // Setting the data and clock pins used

void setup() 
{
  pinMode(ROTARY_ANGLE_SENSOR, INPUT);
  LEDbar.begin();
}

void loop() 
{
  // Measure the number of LEDs that should be on
  // based on the angle of the rotary sensor
  int lightLevel = getLightLevel();

  // If light level is above 0, set LED bar accordingly
  if (lightLevel) {
    
    // Turn on the LEDs up to the measured light level
    for (int i = 1; i <= lightLevel; i++) {
        // Turn on 
        LEDbar.setLed(i, 1);
        delay(100);
    }
    
    // Turn off the rest of the LEDs in reverse order
    for (int j = 10; j > lightLevel; j--) {
        // Turn off 
        LEDbar.setLed(j, 0);
        delay(100);
    }
    
  } else {
    
    // Turn off all LEDs 
    for (int k = 1; k <= 10; k++) {
        // Turn off
        LEDbar.setLed(k, 0);
    }
  }
}

int getLightLevel()
{
  // Take reading, measure voltage, and calculate 
  // number of LEDs which should be turned on
  int reading = analogRead(ROTARY_ANGLE_SENSOR); 
  float voltage = (float)reading*ADC_REF/1023;
  float level = (voltage*NUM_OF_LEDS)/GROVE_VCC;
  return level;
}

Credits

Karel
Karel Kalthoff

happily building connected products at Punch Through Design

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

    Get Notified When Door Is Unlocked: LightBlue Bean/Node-Red
    Easy
    • 291
    • 2

    Full instructions

    Get notifications by email when your door has been unlocked.

    Electronic Egg Toss Game
    Easy
    • 618
    • 13

    The classic picnic game is messy, but this version will let you practice indoors.

    Bluetooth RC
    Easy
    • 992
    • 15

    Work in progress

    RC car controlled using BLE.

    Hypnos Pendant
    Easy
    • 1,842
    • 12

    Full instructions

    A wearable that promotes mindfully spending your time, which also helps trigger lucid dreams.

    LightBlue Bean: Arduino Basics
    Easy
    • 1,286
    • 15

    Protip

    This little Bluetooth board is ideal for wearable tech and tiny robots. Get started with these projects!

    Getting Started with Bluetooth Low Energy (BLE)
    Easy
    • 5,136
    • 18

    Protip

    In this tutorial, we'll learn how to set up BLE GATT services to make a thermometer using Intel's Arduino 101

    Add projectSign up / Login