I need control an led to turn on automatically by 6:00 and then turn off by 45 mins daily.with GPIO pins in raspberry pi. | Sololearn: Learn to code for FREE!

+3

I need control an led to turn on automatically by 6:00 and then turn off by 45 mins daily.with GPIO pins in raspberry pi.

5/16/2018 4:48:46 PM

Vishnu Ram M

4 Answers

New Answer

+3

I do not get your lighting system(on at 06:00 for 45 minutes?) but it's not really important. if the pi is connected to the internet the time will synchronize automatically, otherwise you have to set it manually. you can get the system time in python by importing the time https://www.cyberciti.biz/faq/howto-get-current-date-time-in-python/ if the time is 06:00 turn high the gpio pin (use transistor, relay(and flyback diode) and external power for the relay coil if you plan on using more power hungry lights). if the time is 06:45 turn low the gpio pin. this is a basic approach but you can complicate it as necessary. you could also use crontab to daily run a turn on script at 06:00 and a turn off script at 06:45. again there are various ways to tackle the problem...

+2

general gpio docs https://www.raspberrypi.org/documentation/usage/gpio/ using gpio in python https://www.raspberrypi.org/documentation/usage/gpio/python/README.md scheduling python scripts with crontab http://trevorappleton.blogspot.co.id/2014/06/scheduling-python-programs-using-cron.html?m=1

+1

any other ways?

+1

thanks I'll try it