How to control Relays and Joystick with Raspberry Pi

It is possible to control Relays directly through GPIOs, but for reading data from KY-023 Joystick we need two channels.  Analog to digital converter, for this reason we connect a ADS1015 A/D Converter to Raspberry Pi.
The ADS1015 and ADS1115 are low cost analog to digital converters that are easy to use with the Raspberry Pi.
We connect it through I2C bus.  The ADS1015 is  a 12-bit ADC with 4 channels, and the ADS1115 is a 16-bit ADC with 4 channels.  Both of them have a programmable gain from 2/3x to 16x so you can amplify small signals and read them with higher precision.

  • ADS1015 Datasheet
  • Connecting ADS1015 to Raspberry Pi:
    • ADS1x15 VDD to Raspberry Pi +5V Pin 2 or 4
    • ADS1x15 GND to Raspberry Pi GND Pin 6 or Pin 9 ..
    • ADS1x15 SCL to Raspberry Pi SCL Pin 5
    • ADS1x15 SDA to Raspberry Pi SDA Pin 3
  • Connecting KY-023 to ADS1015:
    • KY-023 GND to Raspberry Pi GND Pin 6,9..
    • KY-023  +5V to Raspberry Pi +5V Pin 2 or 4
    • KY-023 VRX to ADS1x15 A1 Pin 8
    • KY-023 VRY to ADS1x15 A2 Pin 9
    • KY-023 SW to  Raspberry Pi  GPIO 5 Pin 29
  • Installing Adafruit_ADS1x15 Library
    • Open a terminal window and issue these Commands
    • git clone
    • cd Adafruit_Python_ADS1x15
    • sudo python install
    • sudo aptget update
    • sudo aptget install buildessential pythondev pythonsmbus pythonpip
    • sudo pip install adafruitads1x15
  • Walk Through the Code
    • We are using tkinter Library for Graphics and Python programming language for coding.
    • We are using a Thread (joy_Thread ) to read ADS1015 and analyze the Analog value from A0 and A1 analog inputs and find out Joystick is pushed to which direction
    • check if GPIO5 Pin 29 is cleared or not(Joystick is pushed down or not)
    • set the picture of Picture Box base on location of Joystick
    • if SW is pushed then Set GPIO 22 Pin 15 for Beep Signal

  1. On Raspberry Pi Create a directory
  2. download  Test_KY-023 and unzip them in that folder
  3. On Raspberry Pi under Menu Programming select Thonny Python IDE
  4. from menu file open file
  5. Connect Relays and Joystick to Raspberry Pi
  6. run the Python file


download:   Test_KY-023

Leave a Reply

Your email address will not be published. Required fields are marked *