Skip to main content
There is no ping 5 in the BCM's GPIO. Updating answer to reflect example link given by question.
Source Link
emcconville
  • 450
  • 3
  • 11

I'd suggest using cron to schedule the fan's on/off tasks.

Scheduling tasks can be managed by the crontab command.

shell ~> crontab -e

Add each on/off task. They would look something like:

0  9 * * * /path/to/your/python/script.py on
0 21 * * * /path/to/your/python/script.py off

The actual python script would be straight forward. Import sys to evaluate the on/off argument, and the GPIO library to work with pin 5 (refer to GPIO reference to map correct pin number).

#!/usr/bin/env python
import sys
import RPi.GPIO as GPIO

# Identify which pin controls transistor
FAN_PIN = 4

# Set pin 54 as output
GPIO.setmode(GPIO.BOARD) # or GPIO.BCM )
GPIO.setup(5FAN_PIN, GPIO.OUT)

# Get what action to take
action = sys.argv.pop()

if action == "on" :
   print "Turning fan on"
   GPIO.output(5FAN_PIN, GPIO.HIGH)
elif action == "off" :
   print "Turning fan off"
   GPIO.output(5FAN_PIN, GPIO.LOW)
else :
   print "Don't know what to do"

I'd suggest using cron to schedule the fan's on/off tasks.

Scheduling tasks can be managed by the crontab command.

shell ~> crontab -e

Add each on/off task. They would look something like:

0  9 * * * /path/to/your/python/script.py on
0 21 * * * /path/to/your/python/script.py off

The actual python script would be straight forward. Import sys to evaluate the on/off argument, and the GPIO library to work with pin 5 (refer to GPIO reference to map correct pin number).

#!/usr/bin/env python
import sys
import RPi.GPIO as GPIO

# Set pin 5 as output
GPIO.setmode(GPIO.BOARD) # or GPIO.BCM 
GPIO.setup(5, GPIO.OUT)

# Get what action to take
action = sys.argv.pop()

if action == "on" :
   print "Turning fan on"
   GPIO.output(5, GPIO.HIGH)
elif action == "off" :
   print "Turning fan off"
   GPIO.output(5, GPIO.LOW)
else :
   print "Don't know what to do"

I'd suggest using cron to schedule the fan's on/off tasks.

Scheduling tasks can be managed by the crontab command.

shell ~> crontab -e

Add each on/off task. They would look something like:

0  9 * * * /path/to/your/python/script.py on
0 21 * * * /path/to/your/python/script.py off

The actual python script would be straight forward. Import sys to evaluate the on/off argument, and the GPIO library to work with pin 5 (refer to GPIO reference to map correct pin number).

#!/usr/bin/env python
import sys
import RPi.GPIO as GPIO

# Identify which pin controls transistor
FAN_PIN = 4

# Set pin 4 as output
GPIO.setmode(GPIO.BCM)
GPIO.setup(FAN_PIN, GPIO.OUT)

# Get what action to take
action = sys.argv.pop()

if action == "on" :
   print "Turning fan on"
   GPIO.output(FAN_PIN, GPIO.HIGH)
elif action == "off" :
   print "Turning fan off"
   GPIO.output(FAN_PIN, GPIO.LOW)
else :
   print "Don't know what to do"
Added additional reference link.
Source Link
emcconville
  • 450
  • 3
  • 11

I'd suggest using cron to schedule the fan's on/off tasks.

You'd add taskScheduling tasks can be managed by run crontabthe crontab command.

shell ~> crontab -e

Add each on/off task. They would look something like:

0  9 * * * /path/to/your/python/script.py on
0 21 * * * /path/to/your/python/script.py off

The actual python script would be straight forward. Import sys to evaluate the on/off argument, and the GPIO library to work with pin 5 (refer to GPIO reference to map correct pin number).

#!/usr/bin/env python
import sys
import RPi.GPIO as GPIO

# Set pin 5 as output
GPIO.setmode(GPIO.BCMBOARD) # or GPIO.BCM 
GPIO.setup(5, GPIO.OUT)

# Get what action to take
action = sys.argv.pop()

if action == "on" :
   print "Turning fan on"
   GPIO.output(5, GPIO.HIGH)
elif action == "off" :
   print "Turning fan off"
   GPIO.output(5, GPIO.LOW)
else :
   print "Don't know what to do"

I'd suggest using cron to schedule the fan's on/off tasks.

You'd add task by run crontab

shell ~> crontab -e

Add each on/off task. They would look something like:

0  9 * * * /path/to/your/python/script.py on
0 21 * * * /path/to/your/python/script.py off

The actual python script would be straight forward. Import sys to evaluate the on/off argument, and the GPIO library to work with pin 5.

#!/usr/bin/env python
import sys
import RPi.GPIO as GPIO

# Set pin 5 as output
GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.OUT)

# Get what action to take
action = sys.argv.pop()

if action == "on" :
   print "Turning fan on"
   GPIO.output(5, GPIO.HIGH)
elif action == "off" :
   print "Turning fan off"
   GPIO.output(5, GPIO.LOW)
else :
   print "Don't know what to do"

I'd suggest using cron to schedule the fan's on/off tasks.

Scheduling tasks can be managed by the crontab command.

shell ~> crontab -e

Add each on/off task. They would look something like:

0  9 * * * /path/to/your/python/script.py on
0 21 * * * /path/to/your/python/script.py off

The actual python script would be straight forward. Import sys to evaluate the on/off argument, and the GPIO library to work with pin 5 (refer to GPIO reference to map correct pin number).

#!/usr/bin/env python
import sys
import RPi.GPIO as GPIO

# Set pin 5 as output
GPIO.setmode(GPIO.BOARD) # or GPIO.BCM 
GPIO.setup(5, GPIO.OUT)

# Get what action to take
action = sys.argv.pop()

if action == "on" :
   print "Turning fan on"
   GPIO.output(5, GPIO.HIGH)
elif action == "off" :
   print "Turning fan off"
   GPIO.output(5, GPIO.LOW)
else :
   print "Don't know what to do"
Cleaned grammer
Source Link
emcconville
  • 450
  • 3
  • 11

I'd suggest using cron to schedule task of turning the fanfan's on/off tasks.

You'd add task by run crontab

shell ~> crontab -e

Add each on/off task. They would look something like:

0  9 * * * /path/to/your/python/script.py on
0 21 * * * /path/to/your/python/script.py off

The actual python script would be straight forward. Import sys to evaluate the on/off argument, and the GPIO library to work with pin 5.

#!/usr/bin/env python
import sys
import RPi.GPIO as GPIO

# Set pin 5 as output
GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.OUT)

# Get what action to take
action = sys.argv.pop()

if action == "on" :
   print "Turning fan on"
   GPIO.output(5, GPIO.HIGH)
elif action == "off" :
   print "Turning fan off"
   GPIO.output(5, GPIO.LOW)
else :
   print "Don't know what to do"

I'd suggest using cron to schedule task of turning the fan on/off.

You'd add task by run crontab

shell ~> crontab -e

Add each on/off task. They would look something like:

0  9 * * * /path/to/your/python/script.py on
0 21 * * * /path/to/your/python/script.py off

The actual python script would be straight forward. Import sys to evaluate the on/off argument, and the GPIO library to work with pin 5.

#!/usr/bin/env python
import sys
import RPi.GPIO as GPIO

# Set pin 5 as output
GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.OUT)

# Get what action to take
action = sys.argv.pop()

if action == "on" :
   print "Turning fan on"
   GPIO.output(5, GPIO.HIGH)
elif action == "off" :
   print "Turning fan off"
   GPIO.output(5, GPIO.LOW)
else :
   print "Don't know what to do"

I'd suggest using cron to schedule the fan's on/off tasks.

You'd add task by run crontab

shell ~> crontab -e

Add each on/off task. They would look something like:

0  9 * * * /path/to/your/python/script.py on
0 21 * * * /path/to/your/python/script.py off

The actual python script would be straight forward. Import sys to evaluate the on/off argument, and the GPIO library to work with pin 5.

#!/usr/bin/env python
import sys
import RPi.GPIO as GPIO

# Set pin 5 as output
GPIO.setmode(GPIO.BCM)
GPIO.setup(5, GPIO.OUT)

# Get what action to take
action = sys.argv.pop()

if action == "on" :
   print "Turning fan on"
   GPIO.output(5, GPIO.HIGH)
elif action == "off" :
   print "Turning fan off"
   GPIO.output(5, GPIO.LOW)
else :
   print "Don't know what to do"
Post Made Community Wiki
Source Link
emcconville
  • 450
  • 3
  • 11
Loading