Using Grove-Rotary Angle Sensor(P) to Control Grove LED © GPL3+

Using Arduino/Genuino 101 to control the brightness of an LED through Grove-Rotary Angle Sensor(P) .

  • 570 views
  • 0 comments
  • 2 respects

Components and supplies

About this project

This is a project which shows the simple plug-and-play feature of the Grove starter kit. In this project, the Grove Rotary Angle Sensor is used to control the brightness of the LED socket kit.

Code

code for the projectC/C++
/*macro definitions of Rotary angle sensor and LED pin*/
    #define ROTARY_ANGLE_SENSOR A0
    #define LED 2//the Grove - LED is connected to D3 of Arduino
    #define ADC_REF 5//reference voltage of ADC is 5v.If the Vcc switch on the seeeduino
                     //board switches to 3V3, the ADC_REF should be 3.3
    #define GROVE_VCC 5//VCC of the grove interface is normally 5v
    #define FULL_ANGLE 300//full value of the rotary angle is 300 degrees
    void setup() 
    {
        Serial.begin(9600);
        pinsInit();
    }

    void loop() 
    {
        int degrees;
        degrees = getDegree();
        Serial.println("The angle between the mark and the starting position:");
        Serial.println(degrees);

        int brightness;
        /*The degrees is 0~300, should be converted to be 0~255 to control the*/
        /*brightness of LED                                                   */
        brightness = map(degrees, 0, FULL_ANGLE, 0, 255); 
        controlBrightness(brightness);

        delay(500);
    }
    void pinsInit()
    {
        pinMode(ROTARY_ANGLE_SENSOR, INPUT);
        pinMode(LED,OUTPUT);
    }

    /*PWM control brightness                        */
    /*If brightness is 0,the LED is off.            */
    /*The Greater the brightness, the brighter the LED.*/
    /*The range of brightness is 0~255              */
    void controlBrightness(int brightness)
    {
        analogWrite(LED,brightness);
    }
    /************************************************************************/
    /*Function: Get the angle between the mark and the starting position    */
    /*Parameter:-void                                                       */
    /*Return:   -int,the range of degrees is 0~300                          */
    int getDegree()
    {
        int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
        float voltage;
        voltage = (float)sensor_value*ADC_REF/1023;
        float degrees = (voltage*FULL_ANGLE)/GROVE_VCC;
        return degrees;
    }

Schematics

connecting Grove -Rotary Angle Sensor(P)
it shows on which pin (A0) you have to connect the Grove -Rotary Angle Sensor(P) to the Grove Base shield which is mounted on Arduino 101 .
Img 20171107 180829 dtcxsvzq2a
connecting Grove -LED socket kit
it shows on which pin (D2) you have to connect the Grove -LED socket kit to the Grove Base shield which is mounted on Arduino 101 .
Img 20171107 181010 x4tznkvhda
Full Set Up of the Project
this is how the final project look like
Img 20171107 181107 8xdrkbtpqr

Comments

Similar projects you might like

A Microwave Interface for the IKEA Duktig Kids Kitchen

Project showcase by Myles Eftos

  • 553 views
  • 3 comments
  • 4 respects

Music Adaptive RGB LED with Arduino and Processing

Project in progress by ounane mohamed elfarouk

  • 865 views
  • 6 comments
  • 9 respects

Cellular IoT with Blynk & Hologram

by Moheeb Zara

  • 4,712 views
  • 9 comments
  • 16 respects

Monitoring Temperature Remotely with Blynk for Dummies

Project in progress by Cmtelesann

  • 997 views
  • 2 comments
  • 4 respects

Add Remote Control to Your Lamp

Project tutorial by littlelab

  • 635 views
  • 2 comments
  • 4 respects

Servo Signals and Characterization

by 3 developers

  • 684 views
  • 1 comment
  • 10 respects
Add projectSign up / Login