Category Archives: Raspberry Pi

Create a Dimmable LED with a Potentiometer on the Raspberry Pi

In this video lesson, we show how to create a dimmable LED on the raspberry pi using a potentiometer. Below is the schematic of the circuit we will be using.

Dimmable LED
Pot Controlled Dimmable LED

Then we used the following code to read values through the ADC0834 analog to digital chip, and then apply a PWM signal to control the brightness of the LED.

 

Sunfounder ADC0834 Analog to Digital Chip Library for the Raspberry Pi

We will be using the Sunfounder Ultimate Raspberry Pi kit in all these lessons. You can pick your kit up HERE. In order to use the ADC0834 Analog to Digital converter in your projects, you must have the following library installed on your system. In order to do this, you need to copy the code below. Then create a new program on your Raspberry Pi, and paste the code. Then the code should be saved as ‘ADC0834.py’ in the SAME folder you will be running your main python program from. Also, you may save the program in the default python library file on the raspberry pi. To do this, you can save the file to:

/usr/lib/python3.7/ADC0834.py

Note the above includes the path and the file name. Using this is a better option, as any program on python3.7 should find the library here.

 

Reading Analog Signals with the Raspberry Pi and the ADC0834

Unfortunately the Raspberry Pi has no built in Analog to Digital converters for reading analog voltage values. So, what was a very easy task on the arduino becomes a more difficult task on the Pi. However, many applications and projects on the pi require reading analog values. In order to do this, we must interface to a ADC0834 Analog to Digital Converter chip. The video above provides in depth description of how to do this, but the resources below should also help you.

ADC0834
This diagram shows to to connect the ADC8034 to the Raspberry PI

You can click on the image for a closer view of the diagram.

In order to use the chip, you will need to install a python library on the raspberry pi. Create a python file on your raspberry pi, and name it:

ADC0834.py

You must name it exactly that. Note the 0 in the above file name is a zero. Now copy and paste the following code into the file:

This file, ADC0834.py, should then be put in the following directory:

/usr/lib/python3.7/

Moving or copying the file to that directory might require use of Sudo if you get a permissions error.

Now the following code will allow you to read the analog value coming from the potentiometer in the above circuit diagram:

 

Understanding Raspberry Pi 4 GPIO Pinouts

Raspberry Pi GPIO Pinout
Diagram of physical and BCM Pins on Raspberry Pi

This shows the pinout for the Raspberry Pi 4. It shows both the BOARD numbering scheme, and the BCM numbering scheme. You define which numbering scheme you want to use in your python program. You must start by importing the GPIO Library:

import RPi.GPIO as GPIO

Then, if you use setmode to define which numbering scheme you want:

GPIO.setmode(GPIO.BOARD)

will give you the Physical Pin numbering scheme.

If you use:

GPIO.setmode(GPIO.BCM)

You will be using the BCM Numbering Scheme. I prefer the BOARD Scheme as it is  much easier to keep track of. Hope this helps.