Relay and Relays on Microcontrollers

This is actually the collection of internet search results from google.com. All the content is simply compiled from webs

868 171 131MB

English Pages 1064 Year 2020

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

Relay and Relays on Microcontrollers

  • Commentary
  • Only first or first and second page results of Google searches are included.

Table of contents :
Google results on:
1) Definition of Relays
2)Types
3) Arduino interfacing
4) 8051 interfacing
5) Rasberry Pi interfacing

Citation preview

[email protected]

03/07/2020

4 Ways to Control Electronic Relays

An Introduction to Relays All Magazine

Board Maker  Stories Projects switches that you control (turn Guideon or off) Spotlights Relays are basically switches, by

More

applying or removing a speci c voltage to the relay device. Relays aren’t needed for most microcontroller-based projects as your microcontroller board (whether it’s an Arduino or a full computer system like a Raspberry Pi) will be able to power external devices directly from its I/O ports. Where you need relays is when you want to open/close an external circuit, or where your circuit needs to control higher voltages than your system can provide. I used a relay in my microcontroller-controlled garage door opener because I needed my project to mimic pushing a physical button (the garage door button on the wall) which required switching capabilities, not the ability to send an output voltage from the board. I used a relay in my light timer project because the project required switching on and off household electric current (110 Volts AC), which my Raspberry Pi cannot do directly. There are two common types of relays: mechanical relays and solid-state relays. Mechanical relays use an electromagnetic coil and a physical switch; when you apply a voltage, the switch activates. Solid-state relays deliver the same result, but don’t have the mechanical components; instead, they use electronic components to do the same job. Later in this article, we’ll start talking about relay boards or modules. Relays, in general, work as I’ve described them above. When you’re working with commercially produced relay modules, they usually operate in two different modes depending on how you wire the connections to the module. The supported modes are Normally Open and Normally Closed. In Figure 1, you see a depiction of a relay in Normally Open (NO) mode. In this con guration, when there’s no voltage applied to the control circuit (the relay at rest portion of the image), the switched circuit is disconnected and current can’t ow through the connection. When you apply an appropriate voltage to the control circuit, the electromagnetic coil in the relay activates and pulls the switch closed, enabling current to ow through the switched circuit.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

2/33

03/07/2020

4 Ways to Control Electronic Relays

Summer Maker Camp is Here! Board All Magazine Stories ProjectsOut Our Classes and CampsGuide Check (https://makercamp.com/workshops/)

More

Maker Faire

Shop

Maker  Spotlights

LOG IN

Make: Projects

Magazine

Maker Camp

Partner With Us

4 Ways to Control Electronic Relays

a

d

y 0

h 43

A 5

#

I’ve always been fascinated with relays, they’re so absolute, so binary. Anyway, I’ve built a few projects using relays and thought I’d share what I learned to help make it easier for others to use relays in their projects. I’m not an expert, I’m just a coder who likes to play with hardware. Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

1/33

03/07/2020

More

4 Ways to Control Electronic Relays

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Figure 1 – Normally Open relay operation

In Normally Closed (NC) mode the opposite is true (shown in Figure 2). When the relay is at rest (no voltage applied to the control circuit), the switched circuit is closed and current ows through the switched circuit. When you activate the relay by applying an appropriate voltage to the control circuit, the electromagnetic coil in the relay activates and pulls the switch open, stopping any current owing through the switched circuit. I don’t know how exactly this works internal to the relay.

Figure 2 – Normally Closed relay operation Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

3/33

03/07/2020

4 Ways to Control Electronic Relays

Relays are like other switches in that there are different con gurations

All Magazine Board Maker  More available. Two attributes drive switch con gurations: Pole and Throw. The Stories Projects Guide Spotlights

pole attribute describes how many individual circuits are controlled by the

switch. A Single Pole (SP) switch controls a single circuit. A Double Pole (DP) switch controls two separate circuits; there are essentially two interconnected switches, with each connected to its own circuit; when you toggle the switch, both circuits are affected simultaneously. The switch’s throw attribute describes the number of circuit paths provided by the switch. A Single Throw (ST) has only one circuit path. With the switch thrown one way, current ows through the circuit, with it thrown the other way, the circuit is broken and no current ows. A Double Throw (DT) switch offers two circuit paths. With the switch thrown one way, current ows through one of the circuit paths, with it thrown the other way, current ows through the other circuit path. A DT switch can also have a center Off position between the two circuit path options. So, when you’re looking at relays, you’ll see them described as something like SPST, SPDT, DPST, DPDT, etc. which should make sense now after reading the previous paragraphs. When working with relays, each relay model is different in several ways; the most important differences are in the voltage and current ratings for the relay. There are two sets of numbers you must pay very close attention to, otherwise you’ll damage your relay circuit and possibly let the smoke out of the relay or some other component. The rst is the voltage and current ratings for the control circuit, and they’re normally given as ranges. These numbers tell you what voltage and associated current are required to activate the relay. The second set of important numbers tells you how much voltage and current the switching part of the relay can handle. Let me show you an example; Figure 3 shows the product properties for a random relay from the DigiKey web site. The coil values highlighted in the gure describe how much current the relay consumes and the maximum voltage you can use with the relay. In this case, it’s a 3V relay, so you’ll need to make sure that your project can deliver 3 Volts to trigger the relay, otherwise it’s not going to work.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

4/33

03/07/2020

4 Ways to Control Electronic Relays

The second set of numbers highlighted in the gure tells you more about

Board Maker  More how toAllwork with theMagazine relay. The Switching Voltage tells you how many volts Stories Projects Guide Spotlights

you can switch with this relay. In this case, you can connect the switch circuit to circuit delivering up to 250 Volts Alternating Current (AC) or 220 Volts Direct Current (DC). The last two values specify that the relay will turn on when 2.24 Volts DC is applied to the relay. If the relay’s on, it will switch off when the applied voltage falls below 0.3 Volts DC.

Figure 3 – Relay attributes

With this brief introduction out of the way, let’s start talking about how to use relays in your projects.

Hard-wiring Relays Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

5/33

03/07/2020

4 Ways to Control Electronic Relays

Relays come in several form factors. Basically, a relay will be a rectangular All More block with at least 4 Magazine electrical connectors exposed. Stories Projects

Board Guide

Maker  Spotlights

Two of the connectors are for the control circuit, and, wait for it…the remaining two connectors are for the switched circuit. Pretty easy, right? Not exactly. If you’re not an electrical engineer (like me, I’m nothing of the sort), you might think you can just wire the relay into your circuit and you’re all set. Unfortunately, as with most electronic components, nothing is ever that simple. If you wire the relay into your circuit as I’ve described above, applying voltage, for example, from a Raspberry Pi or Arduino device (you could use any voltage source) across the control circuit should trigger the relay. However, apparently it won’t work reliably, there are latching considerations and other issues that may affect the relay’s operation. Because of this, you need to add some extra components to the circuit to make it work. I discovered this as I worked with my rst relay and found a bunch of Stack Over ow posts suggesting different ways to do it. There’s a Make: magazine article about it with a circuit diagram. Normally I’d gure this all out and write about it here for you, but there’s an easier way to add relays to your projects, actually several ways, which I’ll show you in the following sections. I’ll also show you how to trigger the relay from your project’s code in the following section as well.

Relay Modules Instead of buying relays and wiring them up with transistors, diodes and resistors, many manufacturers produce relay module boards that include everything you need. You can see an example of one in Figure 4; you can buy these modules with anywhere from 1 to 8 or more relays attached. Figure 5 shows a generic 4-relay module.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

6/33

03/07/2020

4 Ways to Control Electronic Relays

Note: Most relay modules I’ve seen don’t include any documentation, so All Magazine More you’ll pretty much have to gure out your module on yourBoard own. Stories Projects Guide

Maker  Spotlights

Relay Connections The single relay module typically exposes 6 electrical connections; three connectors for the control circuit and three for the switching circuit. They may also include a few jumper blocks like the one I’ve shown here. In most simple relay circuits, you’ll usually use only ve connections, I’ll explain why in a minute. On the left side of the gure are the control inputs. As you can see from the gure, they’re labeled as follows: • VCC • IN1 • GND In your circuits, you’ll connect an input voltage as required by the relay (for Arduino or Raspberry Pi projects, that’s usually 3 or 5 volts depending on the microcontroller) to the VCC input. It’s the relay that dictates what this voltage should be, not your microcontroller. Most modern Arduino devices provide 3V and the Raspberry Pi can provide 3V or 5V; be sure to pick a relay module that will work with these voltages. Most relay modules like this are designed to work with Arduino’s or Pi’s, so you should be OK. You’ll also connect the GND input to your microcontroller’s Ground connection. Finally, connect the IN1 pin to one of the output pins on your microcontroller. The output voltage on this pin is what triggers the relay. Using an Analog output is preferred, but since the Raspberry Pi doesn’t provide analog outputs, you can use Digital output as well. On the switched circuit side of the module, you’ll see the three switched connection points marked with the diagram shown below (the labels NO, Common, and NC are mine).

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

7/33

03/07/2020

4 Ways to Control Electronic Relays

More

All Stories

Figure 6 – Relay connections legend

Magazine Projects

Board Guide

Maker  Spotlights

The gure shows the switched connection con guration for the relay at rest. For this module, a switched connection is made between the rst and

second connectors or the second and third connectors. When you trigger the relay (by applying the appropriate voltage across the control circuit), the common connection switches to the other side. When you connect your circuit to the NO (normally open) and Common connectors, the circuit remains open until an appropriate voltage is applied to the IN1 connector on the Control circuit. The NO/Common connection closes when voltage is applied to IN1. When you connect your circuit to the NC (normally closed) and Common connectors, remains closed until an appropriate voltage is applied to the IN1 connector on the Control circuit. The NC/Common connection opens when voltage is applied to IN1. For most circuits, you just need to switch one set of wires, so you’ll switch either the NC or NO connections. For some con gurations, you’ll need two states for your circuit; in this case, you’ll use both the NO and NC connections for your circuit. By default, one connection will always be connected and they’ll switch when you apply voltage to IN1. Figure 7 shows a relay module wired for action, notice the three control connections (on the right side of the gure) with the switching connections on the NO/Common connectors. The Yellow wires in the lower left of the gure are the for the switched connection.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

8/33

03/07/2020

4 Ways to Control Electronic Relays

More

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Figure 7 – Relay module in use

For multi-relay modules, the hardware is pretty much the same, just repeated once for every relay on the board. You’ll still have to connect voltage and ground connections, but instead of the single In1 control input, you’ll have one for each relay. So, looking at Figure 5, you’ll see the VCC and GND pins in the lower-right corner of the gure, but also multiple inputs, IN1, IN2, IN3, and IN4 for this 4 relay board. You’ll connect each IN# to a separate output pin on your Arduino or Raspberry Pi device. The switched side of the module has the same NO/Common/NC connectors you saw in the single relay module, only there’s 4 sets of them here, one for each relay. Triggering the Relay Remember the jumpers I mentioned earlier? It’s possible that your relay module will have a few jumpers on it. If so, one of the jumpers will likely control whether the relay is triggered using a high voltage or a low voltage. The position of this jumper will dictate how you trigger the relay in your project’s code. Let me give you some examples. On an Arduino device, with the relay’s IN1 connector wired to the A1 analog output, you can trigger the relay with a single line of code. If the relay module Privacy - Terms is con gured to use a high voltage to trigger the relay, then you would use the Privacy & Cookies Policy

https://makezine.com/2018/03/19/control-electronic-relays/

9/33

03/07/2020

4 Ways to Control Electronic Relays

following code to turn the relay on: All Magazine Stories analogWrite(A1, 255);Projects

More

Board Guide

Maker  Spotlights

This sets the analog output of pin A1 to its highest voltage (likely 3V for the Arduino). To turn it off, you simply turn off the output voltage using the following line of code: analogWrite(A1, 0);

This sets A1’s output to zero. If the relay module is con gured to use a low voltage to trigger the relay, then you would simply ip the examples, using the following code to turn the relay on: analogWrite(A1, 0);

and the following code to turn the relay off: analogWrite(A1, 255);

The Raspberry Pi doesn’t expose Analog outputs, so you’ll have to trick it a little. The Pi does support digital output using PWM (pulse Width Modulation) which is basically an output voltage that repeats itself, well, repeatedly. The result is that it ‘looks’ like a consistent output voltage to the connected device. Using Python on the Pi, the code to toggle the relay every second looks like this: from gpiozero import LED from time import sleep # the relay is connected to GPIO pin 18 on the Raspberry Pi # replace the 18 below with whatever pin is appropriate for your # hardware setup relay = LED(18) # the following is an infinite loop in Python, it runs until you # kill the application while True: # turn the relay on relay.on() # wait a second sleep(1) # turn the relay off relay.off() # wait another second sleep(1) Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

10/33

03/07/2020

4 Ways to Control Electronic Relays

In this example, the code uses GPIO Zero, a very capable library for the Pi

All Magazine Board Maker  More that enables you to easily control most anything connected to the Pi’s GPIO Stories Projects Guide Spotlights

ports. Here, I’m using the module’s LED library to mimic the voltage output I

need for my application. In this case, the relay is connected to the Pi’s GPIO 18 pin. GPIO Zero includes other output types you could use for this as well. There you have it, a quick and easy way to connect a relay to your IoT projects. But wait, there are even easier options for you to use for your projects, check them out in the next section.

Microcontroller Add-On Boards (Shields, HATs, etc.) To make it even easier for you to add relays to your microcontroller projects, several manufacturers produce add-on boards for popular microcontroller platforms. These boards stack directly onto the microcontroller using the GPIO port (Raspberry Pi) or the header pins most other boards support. It seems like there’s relay modules for any kind of microcontroller or Single Board Computer (SBC) you can think of. Adafruit Feather For one of my projects, I used the Adafruit Feather microcontroller; the feather is an Arduino compatible suite of microcontroller boards that all share a consistent form factor and input/output pin layout. For this particular project, I used the Adafruit Feather M0 WiFi, an Arduino compatible Wi-Fi enabled microcontroller, the Adalogger FeatherWing, a real-time clock addon board for the Feather, and the Adafruit Power Relay FeatherWing. The Relay FeatherWing gave my project an easy to use relay module I could just slap onto the microcontroller and get to work. You can see the three boards, with their header pins and sockets soldered on, in the following gure.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

11/33

03/07/2020

4 Ways to Control Electronic Relays

More

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Figure 8 – Adafruit Feather board and accessories

To use them, you stack the boards on top of each other as shown in the following gure. You’ll connect your switched circuit to the blue terminals on the right side of the gure. As with the other relays, you’ll use two for either the NC or NO connection, or all three if you want to switch the relay two ways as described in an earlier section.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

12/33

03/07/2020

4 Ways to Control Electronic Relays

More

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Figure 9 – FeatherWing module stack, including relay module on top

The relay module is wired to multiple output ports on the Feather Board, but to use it, you cut through the metal pad on the back of the board for the output pin you want to use (based on which other pins are being used by other Feather add-on boards).

Figure 10 – Adafruit Feather power relay port selection options Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

13/33

03/07/2020

4 Ways to Control Electronic Relays

To trigger the relay in your Feather application, you would use something like All More the following: Stories

Magazine Projects

Board Guide

Maker  Spotlights

//The Analog pin the relay is connected to const int outputPin = SELECTED_FEATHER_PIN; //For example, if the relay is connected to Analog output A1, you would //use the following: //const int outputPin = A1; void setRelay(bool status) { //Set the relay to a specific status (on=true/off=false) Serial.print("Relay: "); if (status) { Serial.println("ON"); analogWrite(outputPin, MAXOUTPUT); } else { Serial.println("OFF"); analogWrite(outputPin, MINOUTPUT); } //Store the status we set, so that toggleRelay will be able //to accurately toggle the relay later relayStatus = status; }

In this example, what I’m showing is a constant de nition (describing which analog output pin the relay is connected to) and a function called setRelay that triggers the relay. The constant outputPin merely gives you an easy way to con gure the code for your particular hardware con guration. Instead of making you hunt around for all the parts of the code that trigger the relay, we set the relay output pin in this constant and any part of the application that wants to use it can merely reference the constant. With this approach, if you later change the relay pin, you must only change it in one place, and, once the change is made, all the different parts of the code that reference the constant will be automatically updated. The setRelay function gives the application a quick and easy way to turn the relay on or off. Instead of making a separate function to turn it on and another to turn it off, I simply used one function and pass whether I want the relay on or off as a Boolean variable passed to the function. Let me show you. To turn the relay on, any part of the application can simply execute the following code: setRelay(true); https://makezine.com/2018/03/19/control-electronic-relays/

Privacy & Cookies Policy

Privacy - Terms

14/33

03/07/2020

4 Ways to Control Electronic Relays

In this example, the true parameter passed to the function is a Boolean More

All

Magazine

Board Guide

TrueStories value that indicates On. Projects

Maker  Spotlights

To turn the relay off, you would execute the following code: setRelay(false);

The function uses a variable called relayStatus to track whether the relay is on or off, enabling a separate function called toggleRelay to toggle the status of the relay (turning the relay on it its off or off if its on). That code is particularly simple, all it does is call setRelay using the opposite of the relay’s current status: void toggleRelay() { //Flips the relay from on to off or off to on setRelay(!relayStatus); }

The !relayStatus in the code translates to NOT relayStatus , so if relayStatus is true , then false is passed to setRelay . If relayStatus is false , then true is passed to setRelay .

Tessel 2 The Tessel 2 has a relay module, shown in Figure 11. I used it to make a simple garage door controller using a simple web app hosted on the controller; you can nd the complete project on Github.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

15/33

03/07/2020

4 Ways to Control Electronic Relays

More

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Figure 11 – Tessel 2 board and relay module

The Tessel board runs JavaScript, so it’s easy to write a JavaScript-based server task running on the board and use a desktop or mobile web browser to interact with the board. For this project, the web server hosts a simple web page that contains a button to open the garage door. On the board, the code that triggers the garage door is the toggleRelay function listed below: function toggleRelay(RELAY_PORT) { //Toggle the specified relay, keeping it on for RELAY_DELAY milliseconds //first turn on the activity LED tessel.led[ACTIVITY_LED].on(); //next, the relay on relay.turnOn(RELAY_PORT, relayResult); //sleep for 500 milliseconds (half a second) sleep(500).then(() => { //Then turn the relay off relay.turnOff(RELAY_PORT, relayResult); //and turn off the activity LED tessel.led[ACTIVITY_LED].off(); }); }

As you can see from Figure 11, the relay module sports two relays, so when you call toggleRelay , you must tell it which relay is wired to the garage door button by passing a 1 or 2 to the function through the RELAY_PORT variable. The function turns on an indicator light, triggers the relay, waits a half a second, then turns the relay and the LED indicator Privacyoff. & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

16/33

03/07/2020

4 Ways to Control Electronic Relays

Particle Photon One company that makes relay modules for a variety of microcontrollers or All Magazine Board Maker More



Projects Guide SBCStories is National Control Devices. The garage door controller I actuallySpotlights use

was built using the Particle Photon and a single relay board for the Photon. You can read about the complete project at Github. For this board, shown in Figure 12, the Photon mounts in a socket on the right side of the board (as shown in the gure). When you apply power to the relay board, it also powers the microcontroller.

Figure 12 – ControlEverything 1-Channel Relay Controller for the Particle Photon

The Photon ‘platform’ is cool in that you can execute code on the board remotely, through a free cloud service. The board is mostly compatible with the Arduino microcontroller, so you code your application using C. The code to trigger the relay should look similar to what I’ve shown already, in the Photon example code shown below, I de ne some constants to tell the application which pin the relay is connected to and which pin an indicator light is connected to (its built in to the Photon). The application calls the pushButton function to trigger the relay; the function turns on an indicator

light, triggers the relay, waits a half a second, then turns the relay and the LED indicator off.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

17/33

03/07/2020

4 Ways to Control Electronic Relays

// Connect the relay to Digital 0

All = D0; Magazine More int relayPin //Stories Connect the activity LED to Digital 1 Projects

Board Guide

Maker  Spotlights

int activityLED = D1; //================================================================= // This function pushes the garage door button (through the relay, // of course) //================================================================= int pushButton(String param){ Serial.println("pushButton function called."); //Turn the activity LED on, so we can tell it's working digitalWrite(activityLED, HIGH); //Turn the relay on digitalWrite(relayPin, HIGH); //Wait half a second (or however long we determine we need to) delay(500); //Turn the relay off digitalWrite(relayPin, LOW); //Turn the activity LED off digitalWrite(activityLED, LOW); //we must return something, so return a zero (-1 means failure) return 0; }

Raspberry Pi I’ve even found a couple of relay modules for the Raspberry Pi. The rst one I worked with is the Seeed Studio Raspberry Pi Relay Board v1.0. Try out these tips for how to use the board in your projects too. The board sports 4 relays and mounts directly on top of the Raspberry Pi as shown in Figure 13.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

18/33

03/07/2020

4 Ways to Control Electronic Relays

Figure 13 – Seeed Studio Raspberry Pi Relay Board v1.0

More

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Using the board in your projects is easy. The folks at Seeed Studio created a sample Python application that enables you to interact with the board

(turning relays on an off by typing commands in a terminal window), I added some functionality to the code and published it as a Python module at https://github.com/johnwargo/Seeed-Studio-Relay-Board. To use the module, copy the library to your project folder then add the following line to the start of your Python application: from relay_lib_seeed import *

With that in place, you can turn the relay on using the following code: relay_on(int_value)

where int_value refers to the relay number (1 through 4). So, to turn relay #2 on, use the following: relay_on(2)

To turn a relay off, use: relay_off(int_value)

You can also toggle a relay using: relay_toggle_port(int_value)

Pretty simple, right? If you want a simple app you can use to play around with the board, check out my project on Github. Another relay board option is the ModMyPi PiOT Relay Board; you can nd documentation on Github. Like the Seeed Studio board, the PiOT board mounts on top of the Raspberry Pi, but with this module, you can stack multiple boards on top of each other to deliver 8, 12, or more relays for your project. You can see an example of the board shown in Figure 14.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

19/33

03/07/2020

More

4 Ways to Control Electronic Relays

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Figure 14 – ModMyPi PiOT board

A cool feature of the PiOT board is that you can toggle the relays using the push buttons mounted on the board, one for each relay. This enables you to see how the board works and even test out your project’s hardware before you’ve written any code. You’ll also use these buttons to con gure the Raspberry Pi GPIO pins used by the board, something that I would honestly prefer to do via jumpers or DIP switches instead. The board is designed for both the full-size Raspberry Pi models as well as the Pi Zero. Unfortunately, the mounting holes on the board are only suitable for mounting on the Pi Zero. For Pi Zero mounting, the board offers 4 mounting holes, so with the right standoffs and screws, you can mount the PiOT board solidly on top of the Pi Zero. For larger Pi models, for some bizarre reason the ModMyPi folks only expose two mounting holes that align with the Pi, so you can mount it, but I found that for my implementation it was unstable and shorted the relay connections whenever the board moves (which it does easily since its not mounted rmly). To help you use the board in your projects, I created the Python library at https://github.com/johnwargo/pi-relay-controllermodmypi/blob/master/relay_lib_modmypi.py. To use the library, copy the library to your project folder then add the following line of code to your Python project: https://makezine.com/2018/03/19/control-electronic-relays/

Privacy & Cookies Policy

Privacy - Terms

20/33

03/07/2020

4 Ways to Control Electronic Relays

from relay_lib_modmypi import *

More

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Next, you’ll have to con gure the application for your board con guration. In your application’s initialization code, add the following lines:

# Update the following list/tuple with the port numbers assigned to your relay PORTS = (7, 8, 10, 11) NUM_RELAY_PORTS = 4 # initialize the relay library with the system's port configuration if init_relay(PORTS): # turn all the relays off, so we're starting with a clean slate. relay_all_off() else: print("Port configuration error") # exit the application sys.exit(0)

In the PORTS variable, you’ll need to populate the list with the relay port numbers you con gured using the board’s buttons. Set the NUM_RELAY_PORTS variable to 4, 8, 12, etc. depending on how many boards

you have stacked together. With that in place, you can turn the relay on using the following code: relay_on(int_value)

where int_value refers to the relay number (1 through 4). So, to turn relay #2 on, use the following: relay_on(2)

To turn a relay off, use: relay_off(int_value)

You can also toggle a relay using: relay_toggle_port(int_value)

Pretty simple, right? If you want a simple app you can use to play around with the board, check out my project.

PowerSwitch Tail Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

21/33

03/07/2020

4 Ways to Control Electronic Relays

For my garage door opener projects, I was merely using a relay to ‘push’ a

Magazine Maker  More button,Allso the relay merely switched a low voltage circuit.Board For some projects, Stories Projects Guide Spotlights

you’ll want to use a microcontroller to switch higher voltages, like the 110V

(North America) or 220V (pretty much everywhere else) running your house lighting or other commercial appliances. You can switch those voltage levels with the solutions I’ve shown so far as many relays support switching a wide range of voltages (for example, the relays shown in Figures 5 and 6 will switch up to 250V AC or 30V DC), but you’re dealing with higher voltages which can be deadly to work with and dramatically change the wiring solution you’ll use in your project. For high voltage switching scenarios, there’s a simple solution you can use that isolates you from many of the safety issues that come with higher voltages. The solution is called a PowerSwitch Tail, and an example project I created using one is shown in Figure 15. The PowerSwitch Tail (PT) is the black box with the power cord running through it.

Figure 15 – PowerSwitch Tail project

The PT is basically a box containing a relay with its switched connection wired across one of the conductors in an AC power plug. When you apply a speci c voltage (normally between 3V and 5V) to the input connections on Privacy & Cookies Policy

https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

22/33

03/07/2020

4 Ways to Control Electronic Relays

the PT (shown with two red wires connected to it in the gure) the relay

All Magazine Board Maker  More triggers and AC current passes through the power cord. The PT is normally Stories Projects Guide Spotlights

wired for NO operation, but you can usually con gure it for NC operation as well. For this particular project, I used a Adafruit Feather with a real-time clock (RTC) module to drive the PT relay, enabling me to switch control to a light xture using logic coded in the Feather application. You can nd the complete source code for the project here.

From a coding standpoint, you’ve already seen the code you need to control the relay, it’s in the Adafruit Feather section shown earlier in the document.

Validating Relay Operation As I worked with many of these relay-based projects, I found myself regularly wiring up a simple LED circuit so I could quickly and easily see whether my project code worked correctly. Most relays make an audible click when triggered, and most relay modules have a LED wired into each relay circuit so you can tell at a glance whether the relay is on or off. However, it’s not always easy to hear the click or see the indicator light clearly. Also, with 4-relay modules, the module’s indicator LEDs are sometimes grouped together, so it’s hard to tell which LED is for which relay. I do a lot of woodworking in my shop, and as I gained experience, I quickly learned that successful makers use jigs to help them repeat tasks consistently or even perform singular, but complicated, tasks accurately. For my relay work, I created a testing jig I could wire into each of my projects as I worked on them and more easily determine the state of my project’s relays. The jig is basically a series of LEDs connected to a power source (3V DC served by two AA batteries) with each LED exposed through two open leads. When I need to test a relay circuit, I wire a LED’s leads to the NC connection on one of the relays (repeating as necessary depending on how many relays I’m using), put a couple of batteries in the battery holder and start testing my code. When the relay triggers, the LED lights or goes dark depending on the status of the relay. The following gure shows the wiring diagram for the jig.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

23/33

03/07/2020

4 Ways to Control Electronic Relays

More

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Figure 16 – Relay testing jig circuit

For my implementation of this, I used the Adafruit Perma-Proto Half-sized Breadboard as it was just the right size and allowed me to easily assemble the circuit. The coils of black and red wires shown connected to the lowerright corner of the jig are there in case I need to use that 3V power supply (the two AA batteries) for some other aspect of the project.

Conclusion Hopefully I’ve given you enough of an overview of relays and their practical application (using relay modules, add-on boards, and, of course, code) that you’ll be able to successfully add them to your projects. When working with relays, be sure that your relay is rated for both the voltage and current used in your project; you wouldn’t want to let the smoke out of a relay out of carelessness. Speaking of carelessness, when working with AC circuits or high-voltage DC circuits, be extra careful as a mistake can be deadly, or at least painful.

ADVERTISEMENT

smt172 temperature sensor

The SMT172 is the most accurate temperature se with duty cycle modulate output.

By John M. Wargo

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

24/33

03/07/2020

4 Ways to Control Electronic Relays

March 19, pm PDT All 2018, 12:39 Magazine More Stories Projects

Board Guide

Maker  Spotlights

ADVERTISEMENT

RELATED TOPICS

DEV BOARDS

ELECTRONICS

MAKE61

RELAYS

ADVERTISEMENT

ADVERTISEMENT

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

25/33

03/07/2020

More

4 Ways to Control Electronic Relays

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Plan C Live: Maker Response To Covid-19 In The UK

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

26/33

03/07/2020

More

4 Ways to Control Electronic Relays

All Stories

a

Magazine Projects

d

Board Guide

y 0

h 1

Maker  Spotlights

A 0

#

Join Dale Dougherty of Make: Community and Valeria Dammicco and Lucia Corsini, researchers at Institute for Manufacturing (IfM) at Cambridge University to talk with some of the central activators, innovators, and organizers of the open source and maker response to COVID-19 in the UK and, as the pandemic evolves, discuss the future of these newly formed distributed manufacturing networks: What will come next? What do we still need to do and which gaps are to be still addressed in order to make these networks e cient for the near future? Time: July  8, 2020 11:30 AM PDT / 6:30pm BST REGISTER to join the conversation: https://us02web.zoom.us/webinar/register/WN_Z7tNsDZcSDq_nCtyq5oQ7Q Or watch it LIVE on our youtube channel without registering. The panel includes: Ward Hills, Director of Cambridge Makespace – the community’s inventing shed in Cambridge which has been actively involved in producing PPE for the local NHS centre; Adam Clarke, Marketing Director of 3Dcrowd UK – a coordinating platform for the production and distribution of PPE/Face shields to NHS workers; https://makezine.com/2018/03/19/control-electronic-relays/

Privacy & Cookies Policy

Privacy - Terms

27/33

03/07/2020

4 Ways to Control Electronic Relays

Ashleigh Linsdell, Founder of For the Love of Scrubs – a nation wide All Board More volunteer sewing Magazine group that makes scrubs for the NHS; Stories Projects Guide

Maker  Spotlights

Mike McEwan, board member of Shield Collaborative – a cooperative of thirteen initiatives for the production and distribution of PPE for health workers & Kate Hammer, founder of CovSleeves, a project seeded within Shield Collaborative. By Caleb Kraft  @calebkraft

8 hours ago RELATED TOPICS PLAN C: MAKERS COMBATING COVID-19

ADVERTISEMENT

DataSheet PDF Search Site. Download Datasheets for Free. Offers a great collection of electronic parts datasheet. datasheetspdf.com

OPEN

ADVERTISEMENT

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

28/33

03/07/2020

More

4 Ways to Control Electronic Relays

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

DataSheet PDF Search Site. datasheetspdf.com

Download Datasheets for Free. Offers a great collection of electronic parts datasheet.

OPEN

First Look: The Sienci Long Mill Benchtop CNC Router

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

29/33

03/07/2020

4 Ways to Control Electronic Relays

The interesting thing about this kit is the extruded aluminum frame,

All Magazine Board Maker  More assembled with 3d printed brackets. This whole assembly is screwed directly Stories Projects Guide Spotlights

onto a spoilboard of your choice and can t easily within a 4’x4′ sheet.  With lead screws driving each axis, it has plenty of torque for wood routing, and I found it had no issues chewing through plywood and hardwood at decent speeds.

The full kit, with every single option and addition selected, in the largest size was under $1400 and you can go more budget friendly and get things for the smallest model down to around $900. By Caleb Kraft  @calebkraft

June 26, 2020, 8:08 am PDT RELATED TOPICS CNC

MAKE WORKSHOP

WOODWORKING

ADVERTISEMENT

ADVERTISEMENT

smt172 temperature sensor

The SMT172 is the most accurate temperature sensor with duty cycle modulated output.

Subscribe for Make: Community News Email

https://makezine.com/2018/03/19/control-electronic-relays/

Privacy & Cookies Policy

Privacy - Terms

31/33

03/07/2020

4 Ways to Control Electronic Relays

Email

More

All Stories

First Name Last Name

Magazine Projects

Board Guide

About us

Contact us

Our team

Contribute to Make:

Advertise with us

Find a Maker Faire

Help Center

Manage Magazine Subscription

Maker  Spotlights Go

Make:

    Maker Faire:

    Privacy Policy

Terms of Use

©2020 Make Community LLC. All rights reserved

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

32/33

03/07/2020

More

4 Ways to Control Electronic Relays

All Stories

a

Magazine Projects

d

Board Guide

y 0

h 2

Maker  Spotlights

A 9

#

First Look: The Longmill CNC Router

Benchtop CNC mills are a great entry point for poeple wanting to use the tools, but who also don’t have a massive shop or massive budget. We’ve seen a few over the years in this size range – under 4 foot by 4 foot. The Longmill by Sienci is a somewhat recent addition to the eld, and presents a solid option for many. The model I tried boasts a 30″ x 30″ design, though they also have a 12″x 12″ and 12″x30″ version. The kit comes with everything you need, minus the spoilboard and computer to control it.

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

30/33

03/07/2020

More

4 Ways to Control Electronic Relays

All Stories

Magazine Projects

Board Guide

Maker  Spotlights

Privacy & Cookies Policy https://makezine.com/2018/03/19/control-electronic-relays/

Privacy - Terms

33/33

International Journal of Computer Applications (0975 – 8887) Volume 58– No.20, November 2012

PraNaMa- Scripting Language in Kannada Pradeep

Namratha M

Manu G V

Mtech in Software Engineering, Department of Information Science, PESIT Bangalore, India

Mtech in Software Engineering, Department of Information Science, PESIT Bangalore, India

BE, MBA, Mtech in Computer Science, SJCIT, Chikkabalapur Technical Lead-Testing, Calsoft Labs, Bangalore,India

ABSTRACT PraNaMa is a scripting language interpreter which accepts input from a user and gives the output in Kannada. The application is implemented on Java platform and parses the scripts written in Kannada and generates results in the same language. The application allows the user to enjoy the scripting comfort in his/her language. PraNaMa is primarily meant for those who can read and write only in their native language and those who are not well versed in English but are interested in learning computer programming. PraNaMa can be a stepping stone for those who do not know or know little English and plan to learn programming, by introducing them to the basic concepts of programming in their native language Kannada. Those who are used to conventional programming can also write programs using PraNaMa provided they know Kannada. The interpreter scans every line written in the program and executes. The language has its own syntax which has to be followed when writing the script and is closely related to C language syntax. All important features that are expected of a scripting language are provided by the language, thus the user can use these small but powerful set of features to write programs and make himself familiar with programming before diving into much more complex languages like C, C++ and Java.

General Terms

operating system, often with rudimentary and in some cases more advanced programming-like control flow constructs, and is almost always usable from a stored format such as a simple text file, a section of read-only persistent storage in an embedded device, a deck of punched cards, or other mechanism. Stored sets of commands, especially those stored in files, can be generically called scripts, but usually have more specific names based upon some more conventional programming language, although a key differentiator is that even these scripting languages almost never use the normal toolchain characteristic of the language they resembleKannada Scripting Language “PRANAMA” is one such application specific language which can be used to program in Kannada. The language provides a new wave in computer programming by facilitating the users who want to learn and implement computer programs in Kannada. Kannada scripting language has some of the following features: 

Support for programming in a regional language “Kannada” and there by allow users who know the language edit and interpret programming in the same.



Well defined keywords, identifiers, functions implemented to support programming and use the same.



Well defined set of rules to govern the syntax and semantics of programming. This makes programming much easier and stick to one particular pattern.



Efficient GUI based editor to edit and also interpret the programs written. The editor also provides the features like file open, save as, save etc.



A separate output window to display the executed results in Kannada itself in a user readable format.



Efficient memory management techniques used to store and retrieve the values of variables used in the programs.



A parser which handles the written program to be passed to computer understandable format and thereby process it to give out the results.



A separate file extension for the files to be saved called “.ks” which can be recognized by the editor even when file is loaded.

Scripting language, Metadata, Keywords, Arithmetic operators, Relational Operators, Logical Expressions

Keywords PraNaMa,Function table, Memory semantics rules, Calculator program

table,

Syntax

and

1. INTRODUCTION In computer science, an interpreter[10] normally means a computer program that executes instructions written in a programming language. An interpreter may be a program that either 1.

executes the source code directly

2.

translates source code into some efficient intermediate representation (code) and immediately executes this

3.

explicitly executes stored precompiled code made by a compiler which is part of the interpreter system

A scripting language[8],[9],[11] is a command set for controlling some specific piece of hardware, software, or

This paper aims mainly at providing its users a programming experience in a regional language “Kannada”. The users can edit, interpret and thus observe the results also in Kannada.

14

International Journal of Computer Applications (0975 – 8887) Volume 58– No.20, November 2012 The user has to abide by a set of syntactic rules and thus program accordingly for better results. This project aims mainly at giving out an interpreter for regional language like Kannada through which a user can write and execute programs in Kannada. The projects builds a language and has syntax and semantic rules of its own to follow. The project has the following prominent working modules. 

Editor



Interpreter



Output window

2. FEASIBILITY STUDY 2.1. Technical feasibility : This software is well within the limits of technical feasibility. 

Hardware and Software required already exist.



Future expansion can’t pose any problems.

2.2. Economic feasibility : The end user must be convinced of the value of his investment before committing to the system study. 

Since Java is available for free, the required cost of the project is minimal.



This project consumes less memory and CPU capacity, and can be used even on low-end systems.

2.3. Operational feasibility : There is a need to project whether the system will operate and be used once it is installed, under the present conditions. Installing the relevant software requires minimum amount of complexity. The Server-side has user-friendly interface, which makes all the operations easy to use. The help module is designed to assist the end users in operating the packages.

3. SYSTEM DESIGN 3.1 The system architecture affects the performance, robustness, distributability and maintainability of a system. The particular style and structure chosen for an application may therefore depend on the non-functional system requirements: 1.Performance 2.Security 3.Safety 4.Availability 5. Maintainability 3.2 Design Considerations The main aim of our project is to provide a platform for those who want to program using a language that is typed not in English but in Kannada. This would aid those who are not well versed in English, who know Kannada and want to learn programming. Thus we have kept the features supported by PraNaMa as few as possible only retaining those features that would help the students of PraNaMa in learning higher level languages such as C, C++ in the future.

15

International Journal of Computer Applications (0975 – 8887) Volume 58– No.20, November 2012 1.3 Designing PraNaMa

Start

Input File

Pass - 1

Metadata

Pass - 2

Result

Figure 1 – Design/Flow of the ‘PraNaMa’ The high-level design shows three major components: 1.

First Pass

2.

Second Pass

3.

Meta Data

The first pass reads the input file and extracts information that will be used during the second pass and stores it as Meta Data. This information could be things like name, type and scope of variables, name and return type of functions and information about any files that are to be linked with the existing file. The

second pass handles the major part of interpreting the program written. It handles various programming constructs like the conditional statements and looping constructs. Second pass also handles the evaluation of expressions, function calls and linking of files.A detailed explanation of each of the above components is given below. 3.3.1 Pass 1: Figure 2 shows the flow/design of the first pass of the ‘PraNaMa’ interpreter

16

International Journal of Computer Applications (0975 – 8887) Volume 58– No.20, November 2012

Analyze variable declarations

Pass -1

Resolve function declarations

Store results as metadata

Figure 2 – Design/Flow of the first pass of ‘PraNaMa’ The first pass scans each line of the program and identifies all lines that contain variable declarations and function calls. Important information such as the variable name, type and scope is stored as meta-data. This meta-data is crucial for in the second pass where the values of variables forming a part of function calls and expressions need to be retrieved in order to successfully call the functions and evaluate the expressions.

Purpose Entry

3.3.2 Metadata: Metadata is used in the second pass to retrieve values of variables, to retrieve function return types and to retrieve variable types and scope of variables. Two separate tables are used to store metadata about functions and variables. The details about the entries in each table are shown in table 1 and 2. Entry

Purpose

Name

Store name

Type

Store Type of the variable

Value

Store value of the variable

Scope

Store the scope of the variable

Read a line of input

Name of the function

Type

Return Type

Parameter List

List parameter names

Parameter Types

List of types of each parameter

of

Table 2 – Function Table 3.3.3 Pass 2:

Variable

Each line from the file is read and analyzed. The analysis helps in identifying the next action that has to be performed. The action to be performed is based on the analysis of the current line. The line may be a function call, start of a loop, a conditional statement or an expression to be evaluated. Based on the type of the line an appropriate function is called to carry out the correct action. The function call may display a result or alter the memory table entries. Once the action appropriate for the current line is carried out , Pass 2 checks if there is another line that is to be read. If there is then it loops back to the step where the line is analyzed and this continues till an end of file is encountered.

Table 1 – Memory Table

Pass - 2

Name

Analyze lines YES

Call proper function

Store/Display result

NO

More lines?

Stop Figure 3 – Design/Flow of the second pass of ‘PraNaMa’

17

International Journal of Computer Applications (0975 – 8887) Volume 58– No.20, November 2012 3.4 Identifying Keywords and operators An important step in designing any computer language is to identify the keywords[6] and determine the rules to be followed while writing the program in the new language. The sections that follow will give a brief description of the keywords. 3.4.1

^

Bitwise exclusive OR

left-to-right

|

Bitwise inclusive OR

left-to-right

&&

Logical AND

left-to-right

||

Logical OR

left-to-right

=

Assignment

right-to-left

Keywords

The following are the keywords that are to be used when writing a program. ಸಂಖ್ಯೆ – Used to specify numeric data type

Table 3 – Operator precedence and associativity table. Highest precedence first.

ಅಕ್ಷರ – Used to specify string data type

4. SYSTEM WORKING

ಮಿಶ್ರ – Specifies Mixed data type(Refer. User Manual)

4.1. Basic Logic of Parsing:

ಕಾರ್ಯ- Identifies a function definition ಬರಯ – Used to print to console

Each .ks file will be parsed[5] twice. The idea of two parses is to separate file including, function declaration from actual running of the program.

ಓದು – Used in console input

4.2. First Pass:

ಆಗಿರುವವರಯಗಯ – Used to specify a loop

First parse handles four things.

ಸಯೇರಿಸಿ – Used to



It removes blank lines present in the file.

ಜಯ ೇಡಣಯ – Used to concatenate strings



Including files: A user can include files by using a specific keyword for include (explained later). This is analogous to the #include statement of a C program. This is done by appending each line of the included file to the present file.

ಕರಯ – Used to call a function



It handles declaration of user defined functions.

ಮರಳಿಸು – Used to return a value



It assigns “scope” for each line in the new generated file (after trimming of lines and appending of new files).

ನಕಲು – Used to copy strings ತಿರುಗು – Used to reverse strings ಹಯ ೇಲಿಕಯ – Used to compare strings

ಶ್ೂನೆ – Used to specify void return type 3.4.2 Operators

4.3. Second Pass:

Operators[6] form an important part of a programming language allowing us to perform

In Intrepreter.java the second pass is handled by: private int second_pass (int scopeNum, int new_scope) function. Here new_scope is used for handling user defined functions (as explained later) and scopeNum is the scope number of the block which one wants to execute. The first call to this function is done as: second_pass(0,-1) ; Here “0” is for global scope. The advantage of scopeNum lies in the fact that handling of if-else and while constructs becomes easy to implement. The function returns 1 on successful execution of function body or -1 when an error occurs.

Mathematical and logical operations. The following operators were identified as important and operators that ought to be supported by PraNaMa. Operator Description () []

+ !

Associativity

Parentheses (function call) (see left-to-right Note 1) Brackets (array subscript) Unary Logical ~ complement

plus/minus right-to-left negation/bitwise

In second_pass function each line in the file is examined and the type of the line is determined. Depending on the type of the line appropriate functions are called to handle that type. Following things are handled in second pass:

* / %

Multiplication/division/modulus left-to-right



Declaration of Statements.

+ -

Addition/subtraction



Handling of Expressions



Handling of implicit functions: Write and Read.



Handling of User defined functions



Handling of Constructs: if-else and while.

left-to-right

Relational less than/less than or left-to-right < >= Relational greater than/greater than or equal to == !=

Relational is equal to/is not left-to-right equal to

&

Bitwise AND

4.4. Declaration of Statements: The rule in Ganlipi is that every variable must be declared before it is used., every declaration statement can be of two

left-to-right

18

International Journal of Computer Applications (0975 – 8887) Volume 58– No.20, November 2012 types one for each different data type supported by ganaka i.e. Akshara ( string) and Sankhye ( float ). The type of variable declared is identified by first word in statement and appropriate variable declaration functions are called. User can declare a single variable or an array. A single variable can be initialized in declaration but an array cannot be initialized. The functions take care of allocation of memory for variables in memory table and initialization of values. More on memory table is explained later. 4.5. Handling of Expressions:

Besides these, other tokens include: NUM = KANNUM = CONSTANT = quotes (“ “ ). NUMVAR = floating point value STRVAR = value.

A variable which contains A variable which contains string

4.7. Operator Precedence[6]: Operator

Description

Associativity

()

Parentheses (expression or function call)

left-to-right

[]

An expression statement is one of the following :

All real numbers. Real numbers in Kannada. All characters within double

Brackets(array subscript)

a = 10 ; b = a+10 ; c = a*b ; ( Operators can be logical, relational or arithmetic ) a = "hello"+"how"+"are"+"you"; b = a+ “nice weather” ; a=b=c=0; a; When a line in the file is judged to be an expression statement the Exrpession.Evaluate function is called with the current line , memory object and current line number as parameters.Expression.java and ExpressionVal.java are generated using Byacc/J[2] with calc.y as input grammar and ExpressionLex.java is generated using Jflex[1] with calc.flex as input file.

+ -

Unary plus/minus * / %

Multiplication /modulus

right-to-left /division

left-to-right

+ -

Addition/subtraction

left-to-right

< >=

Relational greater than/greater than or equal to == !=

Relational is equal to/is not equal to

left-to-right

The Evaluate function basically tries to reduce one of the many grammar rules. Once a reduction is done the corresponding action associated with the grammar rule is executed.

&

Bitwise AND

left-to-right

|

Bitwise OR

left-to-right

&&

Logical AND

left-to-right

4.6. Explanation of Tokens:

||

Logical OR

left-to-right

=

Assignment

right-to-left

TOKEN NAME

TOKEN SYMBOL

TOKEN NAME

TOKEN SYMBOL

LOR

||

LSPAREN

[

LAND

&&

RSPAREN

]

ASSIGN

=

GT

>

PLUS

+

GTE

>=

MINUS

-

LT