Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

Ποτενσιόμετρο

Available Languages
Picture
Picture

Εισαγωγή

Picture
Για εσάς που ξεκινάτε τώρα με την ρομποτική και γενικότερα τα ηλεκτρονικά, θα έχετε αναρωτηθεί πως μπορούμε να αλλάξουμε την φωτεινότητα ενός LED χωρίς να χρειάζεται να αλλάζουμε συνεχώς αντιστάσεις στο κύκλωμα μας. Είναι αρκετά απλό, με την χρήση ενός ποτενσιόμετρου ή αλλιώς μιας μεταβλητής αντίστασης. Σε αυτόν τον οδηγό θα μάθετε να χρησιμοποιείτε το ποτενσιόμετρο με την χρήση του Grove- Rotary Angle Sensor για να αλλάξετε την φωτεινότητα ενός LED.

Τα υλικά που θα χρειαστείτε και η σύνδεση

Για το tutorial αυτό θα χρειαστείτε:
  • Arduino UNO
  • Grove Base Shield
  • Rotary Angle Sensor
  • LED (Συνδέστε το Grove-LED στην D3 είσοδο του Grove-Base Shield)
Picture

Ο κώδικας

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*macro definitions of Rotary angle sensor and LED pin*/

#define ROTARY_ANGLE_SENSOR A0
#define LED 3  //the Grove - LED is connected to PWM pin 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);
    pinMode(ROTARY_ANGLE_SENSOR, INPUT);
    pinMode(LED,OUTPUT);   
}

void loop()
{   
    float voltage;
    int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
    voltage = (float)sensor_value*ADC_REF/1023;
    float degrees = (voltage*FULL_ANGLE)/GROVE_VCC;
    Serial.println("The angle between the mark and the starting position:");
    Serial.println(degrees);

    int brightness;
    brightness = map(degrees, 0, FULL_ANGLE, 0, 255);
    analogWrite(LED,brightness);
    delay(500);
}
Κατεβάστε τον κώδικα απ' εδώ και ανοίξτε το αρχείο με το Arduino IDE.
grove-_rotary_angle_sensor.zip
File Size: 0 kb
File Type: zip
Download File

Συγχαρητήρια !

Picture
Μόλις ολοκλήρωσες άλλο ένα tutorial με το Grove !

Αν το έκανες και εσύ και σου φάνηκε εύκολο γράψε την άποψη σου κάτω στα σχόλια !
Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates