element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs 6 - Monitoring The Float Switches With Python
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ge0rgej
  • Date Created: 8 Sep 2013 12:54 PM Date Created
  • Views 1065 views
  • Likes 0 likes
  • Comments 0 comments
  • source_code
  • python
  • piface_digital
  • raspberry-pi
Related
Recommended

6 - Monitoring The Float Switches With Python

ge0rgej
ge0rgej
8 Sep 2013

image

 

The first Python code that we run deals soley with monitoring the switch state of the float switches and activating the water solenoid valve at the right times (when the Tanks are Full the mains water solenoid valve closes .... when the Tanks are Empty the mains water solenoid valve opens)

 

As I mentioned in the Introduction to this project I dont proffess to being a Python programmer by any means, but I can promise that any code that appears in this project will work. If there are any programmers out there that feel the need to have a tidy up - or make changes for the better of the project, you are more than welcome to do so.

 

 

The video at the end of this section will summarise how to get the code running, but for now try out the following steps;

 

 

 

1 - The first thing you need to do is copy the code below and save it somewhere on your Raspbery Pi, alternatively download it from GitHub via the link provided. As this is going to be modified during the project save the file as Garden_Irrigation1.py

 

 

 

 

 

 

2 - On your Raspberry Pi's desktop you will see an IDLE icon, double click IDLE and the Python Shell window will open

 

3 - In Python Shell click on File -> Open ... and locate the code that you have just saved

 

4 - Once you have opened Garden_Irrigation1.py - on the menubar click Run -> Run Module

 

image

 

You should now be up and running, and providing that all of your floats (switches) are in a closed state you should see a 'Solenoid Valve Closed' message that self updates itself. Toggle through each of the switches, turning them off one at a time and you will see the status messages change. Once you have switched off the last switch (Tank 1 - L/L) you will see that the PiFace LED associated with Output 1 lights up, and the changeover relay operates.

 

 

The above details all you need to know to be able to run your code in IDLE, but as we progress you will see that there are times when it is much easier to run code using Python's Interactive Mode. The next few steps show how this is achieved;

 

 

5 - In Linux Terminal change directory to the location where you saved Garden_Irrigation1.py

 

       at the command promp type $ cd path/to/Garden_Irrigation1.py

 

       Once you have changed directory to the location of the file, at the command prompt

 

       type $ python

 

       Python will now execute and you will be taken to the Python primary prompt

 

       type >>> execfile('Garden_Irrigation1.py')

 

You should now see the code running in your Terminal window exactly as we saw in Step 4 above.

 

       To exit Python - press Ctrl - D

 

 


 

 

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 


 

 

In the next few sections I will be putting the Raspberry Pi and PiFace to one side and focusing on one of the key elements of this project, Twitter Alerts.


  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube