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

Force Sensitive Resistor - Αισθητήριο πίεσης

Available Languages
Greek
English

Εισαγωγή

Picture
Στο σημερινό tutorial  θα χρησιμοποιήσουμε ένα αισθητήριο μεταβλητής αντίστασης του οποίου η τιμή της αντίστασης αλλάζει ανάλογα με την πίεση που ασκούμε σε αυτό.

​ Στόχος μας είναι να μεταβάλλουμε την φωτεινότητα ενός led πιέζοντας το με το δάκτυλό μας.

Τα υλικά που θα χρειαστούμε

Γι΄αυτο το tutorial θα χρειαστούμε:
  • Arduino uno
  • Breadboard
  • Force sensitive resistor
  • LED
  • Αντιστάσεις 10KΩ& 220Ω
Picture

Το κύκλωμα

Picture
Οι συνδέσεις είναι αρκετά απλές και εύκολες. Ακολουθήστε το παραπάνω breadboard σχηματικό.

Ο κώδικας

Πως λειτουργεί ο κώδικας:
  • Διαβάζουμε την αναλογική τιμή απ' το μεσαίο pin του ποτενσιόμετρου
    -> value=analogRead(potPin)
  • Κάνουμε αντιστοίχιση αναλογικών τιμών (0-1023) σε PWM (0-255)
    -> value = map(value, 0, 1023, 0, 255);
  • Στέλνουμε την τιμή PWM στο LED
    -> 
    analogWrite(ledPin, value);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* How to use a Force sensitive resistor to fade an LED with Arduino
   More info: http://www.ardumotive.com/how-to-use-a-force-sensitive-resistor-en.html 
   Dev: Michalis Vasilakis // Date: 22/9/2015 // www.ardumotive.com  */
   

//Constants:
const int ledPin = 3;     //pin 3 has PWM funtion
const int sensorPin = A0; //pin A0 to read analog input

//Variables:
int value; //save analog value

void setup(){
  pinMode(ledPin, OUTPUT);  //Set pin 3 as 'output' 
  Serial.begin(9600);       //Begin serial communication
}

void loop(){
  value = analogRead(sensorPin);       //Read and save analog value from potentiometer
  Serial.println(value);               //Print value
  value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
  analogWrite(ledPin, value);          //Send PWM value to led
  delay(100);                          //Small delay
}
Κατεβάστε τον κώδικα απ' εδώ και ανοίξτε το αρχείο με το Arduino IDE. Ανοίξτε την σειριακή οθόνη απ' το μενού εργαλεία του Arduino IDE.
forcesensor_tutorial.zip
File Size: 0 kb
File Type: zip
Download File

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

Picture
Μόλις ολοκληρώσατε άλλο ένα Arduino tutorial! 
Εύκολο, δύσκολο? Πείτε μου πως σας φάνηκε στα σχόλια παρακάτω!
​

Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


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