Updated 24 September 2020

Kits and Gadgets Electronics Inc.
Farwaniya, Kuwait 80003
Kuwait

ph: +965 99571844

kits@kits-gadgets.com

  • Electronic Kits
  • Parts on Sale
  • Parts in StockClick to open the Parts in Stock menu
    • Resistor
    • Potentiometer
    • Capacitor
    • Trimmer Capacitor
    • Transistor
    • Crystal
    • Diode
    • LED
    • Diac
    • Thyristor
    • IC Socket
    • IC - Logic
    • IC - Linear
    • IC - Op-Amp
    • IC - VLSI
    • Relay
    • Motor
    • Lamp
    • Transducer
    • Gear
    • Switch
    • Heatsink
    • Parts Store Inventory
  • Brand New Items
  • Used Items
  • Power Supply
  • Raspberry Pi VaultClick to open the Raspberry Pi Vault menu
    • Demonstration Kit
    • Demonstration Kit - R3
    • The P1 Header Guide
    • BBC BASIC Tutorials
    • Activating the GPIO
    • LED Program
    • Motor Program
    • Solenoid Program
    • Stepper Motor
    • 8 Relay Program
    • GPIO as Input
    • Motors and Sensors Connection Diagram
    • Autonomous Program
    • Infrared Sensor
    • Ultrasonic Sensor
    • Camera Controller
    • PWM Program
    • Robotic Arm
    • STRYDER Robot
    • Demo Kit Program
  • Arduino VaultClick to open the Arduino Vault menu
    • Stepper Motor w/ LED
    • DCMotor
  • NodeMCU ProjectsClick to open the NodeMCU Projects menu
    • Running 8 LEDs
    • 8 LEDs and ULN2803
    • 8 LED Active Modes
    • ON-OFF Switch
    • Switch, Relay and LEDs
    • Motor Drive Interface
    • Connecting to Wi-Fi
    • IR Sensor
  • More GPIOsClick to open the More GPIOs menu
    • Accessing the P5 GPIOs
  • Prototypes
  • Computer Parts
  • Picture GalleryClick to open the Picture Gallery menu
    • Other Prototypes
    • Revived HP Laptop
    • Dismantled Helicopter
    • Dismantled Phone
    • ACER Laptop Repair
    • Revived Laptop
    • Inside of Electric Drill
    • Video Cam Automation
    • My Tours and Travels
  • My Original DesignClick to open the My Original Design menu
    • Handycam Automation
    • Autonomous Robot
  • What's New!Click to open the What's New! menu
    • Article-1
    • Article-2
    • Article-3
    • Article-4
    • Article-5
    • Article-6
    • Article-7
    • Article-8
    • Article-9
    • Article-10
    • Article-11
    • Article-12
    • Article-13
    • Article-14
    • Article-15
    • Article-16
    • Article-17
    • Article-18
    • Article-19
    • Article-20
    • Article-21
    • Article-22
    • Article-23
    • Article-24
    • Article-25
    • Article-26
    • Article-27
    • Article-28
    • Article-29
    • Article-30
    • Article-31
  • Forum
  • Video GalleryClick to open the Video Gallery menu
    • IR Proximity Sensor
    • Robot Vacuum Cleaner
    • Robotic Arm - RPi
    • Raspberry Pi Demo Kit
  • About Us
  • Contact Us

Solenoid Program

DRIVING A SOLENOID

 

Raspberry Pi can be programmed to activate or switch-ON many things from switches, LEDs, lamps, motors, buzzers and solenoids. It can be programmed also to output pulse of specific frequency. LEDs and some small lamps can be driven directly from GPIOs since it consumes less current within the output current range of the GPIOs. However, you cannot drive or wise to connect a solenoids directly to the GPIO since it could damage your RPI due to in-rush current, inductive kick, or excessive current when the solenoid is energized. You need to use a drive interface for such purpose to handle much higher current load.

The simple way to do it is by using a motor drive interface such as shown here. Instead of using it for driving a motor it will work also to drive a solenoid. So it has a double purpose! You can just connect Pin 2 and Pin 7 of L293 IC to RPI directly. The 12 Volts DC supply on Pin 8 depends on the load. So, if you use a 5 Volts solenoid you can connect it directly to 5 Volts DC line. Thereby, using only a single supply for L293 and RPI. 

  

 

Below is the simple Solenoid PROGRAM that you can write using Notepad, Wordpad or MSWord. Just  export this text file to RISCOS BBC BASIC preloaded on any Raspberry Pi and save it as BASIC program. This program can activate and release the solenoid once or continously. The control is through the standard keyboard connected on RPI USB port. However, I'm using a mini wireless keyboard when I wrote this program. There should be no problem since most keyboards uses the same standard ASCII code though BBC BASIC convert this to different code .

 

   THE PROGRAM

   10 REM This program will demonstrate activation of solenoid using motor drive.

   20 REM Program for Raspberry Pi Demonstration Test Kit
   30 REM Programmed by: Rolly Estomaguio
   40 REM Created on: 12 May 2014
   50 REM http://www.kits-gadgets.com
   60 ON ERROR PRINT REPORT$;" at line ";ERL:END
   70 PROCinit
   80 PRINT "Press 'S' or 'E' to activate - ESC to finish. SPACEBAR or 'O' to cut-off "
   90  GOTO 210
  100  DEFPROCinit
  110 OSCLI"RMEnsure GPIO 0.00 RMLoad GPIO"
  120 OSCLI"RMensure GPIO 0.40 ERROR Please install the GPIO module"
  130 SYS"GPIO_EnableI2C",0
  140 SYS"GPIO_ExpAsGPIO",2
  150 SYS"GPIO_GetBoard" TO PiType%
  160 DIM A%(16)
  170 IF PiType%=12 A%()= 3,4,17,27,22,10,9,11,7,8,25,23,15,14,24
  180 REM OTHER GPIOs NOT ACTIVATED 2,18,28,29,30,31
  190  ENDPROC
  200 REPEAT
  210 L$= GET$: OFF
  220 IF L$= "O" OR L$= "o" THEN PROC_release
  230 IF L$= "S" OR L$= "s" THEN PROC_sol
  240 IF L$= "Q" OR L$= "q" THEN QUIT
  250 IF L$= "R" OR L$= "r" THEN RUN
  260 IF L$= "E" OR L$= "e" THEN SYS "GPIO_WriteData",24,1
  270 GOTO 210
  280 SYS "GPIO_WriteData",A%(N%),1
  290  DEFPROC_release
  300 FOR E%= 1 TO 16
  310 SYS "GPIO_WriteData",A%(E%),0
  320  NEXT
  330 GOTO 210
  340 DEFPROC_sol
  350 K%= INKEY (1)
  360 SYS "GPIO_WriteData",24,1: SYS "GPIO_WriteData",23,0
  370 SYS "GPIO_WriteData",23,1: SYS "GPIO_WriteData",24,0
  380 REM  FOR D%= 1 TO  5000000: NEXT
  390 IF INKEY (-99) THEN SYS "GPIO_WriteData",24,0: SYS "GPIO_WriteData",23,0: GOTO 210
  400 FOR D%= 1 TO 1500000: NEXT
  410   SYS "GPIO_WriteData",24,0
  420   SYS "GPIO_WriteData",23,0
  430 FOR D%= 1 TO 1000000: NEXT
  440  PROC_sol

 

NOTE:  

You can modify the program to elimate the use of GOTO command and LINE NUMBERS. Otherwise just enjoy it if it didn't bother you.

 

RUNNING THE PROGRAM: 

To activate once and hold : Type " E"

To release                           : Type "O"

For continued ON & OFF  : Type "S"

To stop                                : Press SPACEBAR

 

WHY SOLENOID?

You can do many things with the function of solenoid such as:

1. Activating electrical switches

2. Door or Window lock

3. Trigger for mechanical movement

4. Closing and opening liquid and gas valves

5. Automatic hole puncher and cutter

 

 

 

 

 

 

 

 

 

 

 

 

 

Copyright 2013 Kits and Gadgets Electronics Inc. All rights reserved.

Web Hosting by Yahoo

Kits and Gadgets Electronics Inc.
Farwaniya, Kuwait 80003
Kuwait

ph: +965 99571844

kits@kits-gadgets.com