Recipe to Control a Relay Wired to an ArduinoThe digital pins on an Arduino are able to function as digital outputs and control devices. Their outputs don't have a huge amount of drive current, but they have enough drive to control some relays. In this recipe, we configure an Arduino pin as an output. If you wire a relay input to this output, and the relay's input requirements are within the capabilities of the Arduino (the Uno spec says outputs are 5V and drive up to 40mA), the relay will turn its output on and off. IngredientsFor this recipe, you will need:
ScriptThe Script is as follows:
To run this Script, you need 2 parameters: the arduino_port and relay_pin parameters. The arduino_port parameter is the name of the USB port where the Arduino is plugged in. On *nix hosts, the USB port name is in the "/dev" directory. To see the devices in order of their creation, type "ls -lrt /dev" at a shell prompt and look near the bottom of the list for your Arduino's USB port. The relay_pin parameter defines the Arduino pin where the relay is located. It has a default value of 3. As an example, for an Arduino at USB port "/dev/ttyUSB0" with a relay at pin 3, the Script parameters are:
Running the ScriptRun the Script, and then go to the Device Explorer page. Click on the "arduino" device and click on its "relay" pin. Enter either |