Linux Format

Working with high voltages

-

In this project we used a 12V power supply to power a pump, but you may be asking why we had to use a relay? The Pi can’t tolerate voltages over 5V and to use anything above that would risk damaging the GPIO or the Pi itself. A relay is a magnetic switch triggered by a circuit connected to the Raspberry Pi. This circuit is 5V tolerant and when activated it enables a magnet which pulls a switch inside the relay closed. There’s no connection between the Pi and high voltage circuit, which means we can safely control high voltages.

We used the Piface Relay Plus board which comes with four relays attached. Alternativ­ely, you could use a relay on a breadboard, but for safety reasons we would suggest only using a maximum voltage of 12V on the board, as anything more would require a more robust solution. this informatio­n is printed to the shell before waiting 24 hours before checking again. if rain_forecast != “rain”: print(‘Rain is not forecast’) pump(300) time.sleep(86400) else: print(‘Rain is forecast’) time.sleep(86400)

Relays are not the only solution, a transistor can also be used to control higher voltages. Transistor­s work in a similar way to a relay, in that they isolate the high voltage circuit but are controlled by a lowpower circuit. Both relays and transistor­s are low-cost methods of controllin­g high voltage projects. Remember if you are unsure about a circuit, ask someone who does before applying power!

Finally, we need to create a loop that will call the forecast() function for Blackpool for the next 24 hours. Of course, you can change the location to where ever you live. while True:

forecast(‘Blackpool,uk’,1) As usual, you will want to save your code at this point and click on Run > Run Module to test. For testing it would be prudent to reduce the time.sleep() duration to something much shorter.

Newspapers in English

Newspapers from Australia