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

How to use a Potentiometer

28/10/2019
Available languages:
Picture
Picture

Introduction 

Picture
For those beginning to learn about robotics, particularly in the area of building circuits, you may have come across the question of how to change the brightness of a LED, without having to keep switching parts. Quite simply, the solution to this issue is a potentiometer.

In this tutorial you will learn how to use a potentiometer with Raspberry Pi board to fade an LED.

Let's get started!

What you will need - Hardware

For this tutorial you will need:​
  • GPIO Breakout
  • Breadboard
  • LED
  • 330 Ohm resistor
  • Potentiometer(e.g. 5KΩ)
Picture

The Circuit

Picture
The connections are pretty easy, see the image above with breadboard circuit schematic.

The code

 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
31
32
33
34
#Libraries
import RPi.GPIO as GPIO
from time import sleep
#Set warnings off (optional)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
#Set Button and LED pins
Button = 23
LED = 24
#Setup Button and LED
GPIO.setup(Button,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(LED,GPIO.OUT)
#flag = 0

while True:
    button_state = GPIO.input(Button)
    print(button_state)
    if button_state == 0:
        GPIO.output(LED,GPIO.HIGH)
    else:
        GPIO.output(LED,GPIO.LOW)
    sleep(1)
    '''
    if button_state==0:
        sleep(0.5)
        if flag==0:
            flag=1
        else:
            flag=0
    if flag==1:
        GPIO.output(LED,GPIO.HIGH)
    else:
        GPIO.output(LED,GPIO.LOW)  
    '''   
Download the code from here and open it with Thonny Python IDE or run it from terminal.
raspberrypi_button_led.zip
File Size: 0 kb
File Type: zip
Download File

Well Done!

You have successfully completed our first Raspberry Pi "How to" tutorial and you learned how to use a potentiometer
I hope you liked this, let me know in the comments.
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