Lesson 8 Potentiometer

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp

Introduction

In this lesson, we use a potentiometer to control the brightness of the LED module.

Components

Programming Steps

Step 1

After creating a new project, click on the Simulation icon on the left side of the page to enter the Simulation page.

Step 2

Connect the Potentiometer to A0 and LED module to P0 of the Ezblock Pi. Then connect the VCC and GND to 3.3V and GND respectively. The brightness of LED will change with the variable read values of potentiometer.

Step 3

Click the Create variable button in the Variables category to create a variable called potVal.

Step 4

Read the value of the potentiometer to assign to the variable potVal.

Step 5

In the Sensor Kit category, drag an LED module block below the set potVal to block.

Step 6

Since the read value of potentiometer ranges 0-4095 and the value of the brightness ranges 0-100, a map block is needed to map 0-4095 to 0-100. Get a map block to put it into LED module block.

Step 7

Modify the values as shown below. In addition, potVal block comes from the Variables category. Add a delay block below the LED module block.

Step 8

Go to the Simulation page and click on the Run button, then drag the slider to simulate the value of potentiometer sensor, when the value read is greater than 1500, the LED light up; otherwise, it will turn off. Now click Flash to download the code.