Download Print this page

AZ-Delivery KY-025 Manual

Reed sensor module

Advertisement

Quick Links

Welcome!
Thank you for purchasing our AZ-Delivery KY-025 Reed Sensor Module. On
the following pages, you will be introduced to how to use and set up this
handy device.
Have fun!

Advertisement

loading
Need help?

Need help?

Do you have a question about the KY-025 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for AZ-Delivery KY-025

  • Page 1 Welcome! Thank you for purchasing our AZ-Delivery KY-025 Reed Sensor Module. On the following pages, you will be introduced to how to use and set up this handy device. Have fun!
  • Page 2 Areas of application Education and teaching: Use in schools, universities and training institutions to teach the basics of electronics, programming and embedded systems. Research and development: Use in research and development projects to create prototypes and experiments in the fields of electronics and computer science. Prototype development: Use in the development and testing of new electronic circuits and devices.
  • Page 3 consult a doctor. Caution: Keep the product out of the reach of children and pets to avoid accidental contact and swallowing of small parts. Note: Store the product in a safe, closed container when not in use. Attention: Avoid contact of the product with food and drinks.
  • Page 4 Table of Contents Introduction......................3 Specifications....................4 The pinout......................5 How to set-up Arduino IDE................6 How to set-up the Raspberry Pi and Python..........10 Connecting the module with Atmega328p............11 Sketch example..................12 Connecting the module with Raspberry Pi.............14 Python script....................15 - 2 -...
  • Page 5 Introduction The KY-025 reed sensor module is a reed switch, a magnetic switch that changes its state when exposed to a magnetic field. The module is normally opened, which means, when there is no magnetic field near the module, con- tacts in the switch are opened.
  • Page 6 Specifications » Operating voltage range: from 2.7V to 5V DC » Output: digital and analog » Dimensions: 15 x 36mm [0.6 x 1.4in] The analog output pin voltage sensitivity can be adjusted via an on-board blue potentiometer. With some adjustment of the potentiometer, when the analog voltage is read via an analog to digital converter (ADC for short) inside the microcontroller on the Atmega328p, the ADC value of the voltage is around the value 1023, and that is when there is no magnetic field near the reed sensor.
  • Page 7 The pinout The KY-025 reed sensor module has four pins. The pinout diagram is shown on the following image: - 5 -...
  • Page 8 How to set-up Arduino IDE If the Arduino IDE is not installed, follow the link and download the installation file for the operating system of choice. For Windows users, double click on the downloaded .exe file and follow the instructions in the installation window. - 6 -...
  • Page 9 For Linux users, download a file with the extension .tar.xz, which has to be extracted. When it is extracted, go to the extracted directory and open the terminal in that directory. Two .sh scripts have to be executed, the first called arduino-linux-setup.sh and the second called install.sh.
  • Page 10 Almost all operating systems come with a text editor preinstalled (for exam- ple, Windows comes with Notepad, Linux Ubuntu comes with Gedit, Linux Raspbian comes with Leafpad, etc.). All of these text editors are perfectly fine for the purpose of the eBook. Next thing is to check if your PC can detect an Atmega328p board.
  • Page 11 If the Arduino IDE is used on Windows, port names are as follows: For Linux users, for example port name is /dev/ttyUSBx, where x repre- sents integer number between 0 and 9. - 9 -...
  • Page 12 How to set-up the Raspberry Pi and Python For the Raspberry Pi, first the operating system has to be installed, then ev- erything has to be set-up so that it can be used in the Headless mode. The Headless mode enables remote connection to the Raspberry Pi, without the need for a PC screen Monitor, mouse or keyboard.
  • Page 13 Connect the KY-025 module with the Atmega328p as shown on the following connection diagram: KY-025 pin > Mc pin > Red wire > Black wire > Green wire > Blue wire With this set-up, both analog and digital pins of the KY-025 module are used. - 11 -...
  • Page 14 Sketch example #define REED_D_PIN #define REED_A_PIN void setup() { pinMode(REED_D_PIN, INPUT); Serial.begin(9600); void loop() { Serial.print("Digital: "); Serial.print(digitalRead(REED_D_PIN)); Serial.print(" - Analog: "); Serial.println(analogRead(REED_A_PIN)); delay(1000); - 12 -...
  • Page 15 Upload the sketch to the Atmega328p and open Serial Monitor (Tools > Serial Monitor). The result should look like the output on the following image: - 13 -...
  • Page 16 With this set-up, the Raspberry Pi is used to read only the digital pin of the KY-025 module. If the analog pin has to be used, use the analog to digital converter of the Atmega328p or external analog to digital converter like the ADS1115 (which is not covered in this eBook).
  • Page 17 Python script import RPi.GPIO GPIO from time import sleep GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) # Pin setup for the module Digital_PIN GPIO.setup(Digital_PIN, GPIO.IN) print('[Press CTRL + C to end the script!]') try: # Main program loop while True: GPIO.input(Digital_PIN): print('Magnet detected') else: print('No magnet') sleep(1) # Wait for a second...
  • Page 18 Save the script by the name Reed25.py. To run the script open terminal in the directory where the script is saved and run the following command: python3 Reed25.py The result should look like the output on the following image: To stop the script press CTRL + C on the keyboard. - 16 -...
  • Page 19 If you are looking for the high quality microelectronics and accessories , AZ-Delivery Vertriebs GmbH is the right company to get them from. You will be provided with numerous application examples, full installation guides, eBooks, libraries and assistance from our tech- nical experts.