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!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

16th May 2018, 4:48 PM
Vishnu Ram M
Vishnu Ram M - avatar
4 Answers
+ 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...
16th May 2018, 6:14 PM
seamiki
seamiki - avatar
+ 1
any other ways?
17th May 2018, 5:03 AM
Vishnu Ram M
Vishnu Ram M - avatar
+ 1
thanks I'll try it
18th May 2018, 1:39 PM
Vishnu Ram M
Vishnu Ram M - avatar