Silicon ChipArduino-Based GSM Remote Monitoring Station - March 2014 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Cruise ships are technical marvels
  4. Feature: Digital Cameras Come of Age by Barrie Smith
  5. Feature: Retro Round-Up: Nostalgic Radio Is Back! by Kevin Poulter
  6. Subscriptions
  7. Project: Arduino-Based GSM Remote Monitoring Station by Nicholas Vinen
  8. Project: Precision 10V DC Reference For Checking DMMs by Jim Rowe
  9. Review: Cadex C7400ER-C Battery Analyser by Nicholas Vinen
  10. Project: Burp Charger For NiMH & Nicad Batteries by John Clarke
  11. Product Showcase
  12. Project: 230V/10A Speed Controller For Universal Motors, Pt.2 by John Clarke
  13. Book Store
  14. Feature: A Look Back At Ferrite Core Memory: Bits You Can See by Brian Armstrong
  15. Vintage Radio: The 1956 Sony Gendis TR-72 transistor radio by Dr Hugo Holden
  16. Order Form
  17. Notes & Errata
  18. Market Centre
  19. Advertising Index
  20. Outer Back Cover

This is only a preview of the March 2014 issue of Silicon Chip.

You can view 46 of the 112 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Arduino-Based GSM Remote Monitoring Station":
  • Arduino software for the GPRS Remote Monitoring Station (Free)
  • Arduino GPRS Remote Monitoring panel artwork (PDF download) (Free)
Items relevant to "Precision 10V DC Reference For Checking DMMs":
  • Precision 10V DC Reference Mk2 PCB [04104141] (AUD $5.00)
  • Precision 10V DC Reference Mk2 PCB pattern (PDF download) [04104141] (Free)
  • Precision 10V DC Reference Mk2 panel artwork (PDF download) (Free)
Items relevant to "Burp Charger For NiMH & Nicad Batteries":
  • NiMH/Nicad Burp Charger PCB [14103141] (AUD $15.00)
  • PIC16F88-I/P programmed for the NiMH/Nicad Burp Charger [1410314A.HEX] (Programmed Microcontroller, AUD $15.00)
  • Complementary pair of logic-level Mosfets (CSD18534KCS/SPP15P10PL-H) (Component, AUD $7.50)
  • Firmware (ASM and HEX) files for the NiMH/Nicad Burp Charger [1410314A.HEX] (Software, Free)
  • NiMH/Nicad Burp Charger PCB pattern (PDF download) [14103141] (Free)
  • NiMH/Nicad Burp Charger panel artwork (PDF download) (Free)
Items relevant to "230V/10A Speed Controller For Universal Motors, Pt.2":
  • 230V/10A Universal Motor Speed Controller PCB [10102141] (AUD $10.00)
  • 230V/10A Universal Motor Speed Controller prototype PCB [10102141] (AUD $2.50)
  • PIC16F88-I/P programmed for the 230V/10A Universal Motor Speed Controller [1010214A.HEX] (Programmed Microcontroller, AUD $15.00)
  • Parts for the 10A 230VAC Universal Motor Speed Controller (Component, AUD $45.00)
  • Firmware (ASM and HEX) files for the 230V/10A Universal Motor Speed Controller [1010214A.HEX] (Software, Free)
  • 10A/230VAC Universal Motor Speed Controller PCB pattern (PDF download) [10102141] (Free)
  • 10A/230VAC Universal Motor Speed Controller panel artwork (PDF download) (Free)
Articles in this series:
  • 230V/10A Speed Controller For Universal Motors, Pt.1 (February 2014)
  • 230V/10A Speed Controller For Universal Motors, Pt.1 (February 2014)
  • 230V/10A Speed Controller For Universal Motors, Pt.2 (March 2014)
  • 230V/10A Speed Controller For Universal Motors, Pt.2 (March 2014)

Purchase a printed copy of this issue for $10.00.

Arduino-based GSM Remote Monitoring S Need to keep an eye on electronic/electrical gear or a power supply in remote locations, such as on a moored boat, holiday house or farm? A loss of mains/solar/wind power or failure of equipment such as pumps could be a disaster – unless you know about it straight away. This unit will send you an SMS as soon as something goes wrong. A RECENT INCIDENT illustrates how useful a Remote Monitoring Station like this can be. An acquaintance of one of our staff members has a farm with cattle on it but he’s not always around to keep an eye on things. During the Christmas break, a lightning strike took out the mains power back at the pole and so the water pump at the homestead stopped working. This pump also supplies water to the cattle troughs and they were quickly emptied by the thirsty cattle 26  Silicon Chip during the hot weather. Fortunately, a neighbour checks on the property every few days and so the problem was discovered in time, before any cattle were lost. But even so, if he’d had a monitoring unit such as this one, he would have known about the problem almost immediately. Another good example is for monitoring a boat on a mooring or in a berth. It’s common for a boat to rely on shore power or solar panel/wind generator to keep the batteries charged. The batteries are needed to start the motor(s) and also power the bilge pumps which need to be kept operational at all times. You really need to know straight away if the boat loses power or starts taking on significant quantities of water (as indicated by frequent running of the bilge pumps) and so some form of remote monitoring is very useful. Most boats don’t have any sort of permanent phone or internet connection but are generally moored in an area with mobile phone coverage so this project is quite applicable. And if you have an alarm system siliconchip.com.au The Remote GPRS Monitor uses a Freetronics Eleven Arduino module (left) and a Seeed Studios Arduino GPRS shield (right). The latter accepts a phone SIM card (on the back) so that it can send and receive SMS messages Station By NICHOLAS VINEN with an output that can indicate when it goes off, this unit can also alert you should your alarm be triggered – whether that alarm is in a house, boat, caravan, etc. In fact you could even wire it up to the ignition system on a vehicle in order to get an alert each time its engine is switched on. What it does This unit has five analog inputs and five digital inputs. It constantly monitors the states of those 10 inputs, according to a set of rules that you siliconchip.com.au Connecting the two modules together is easy – the GPRS shield simply plugs into the Arduino module via the on-board headers on either side. Note that the GPRS shield shown here uses an external antenna but later versions of this module have an onboard antenna. March 2014  27 6 DIGITAL 5 ANALOG TERMINALS ON BOX LID 4 3 6 5 4 3 2 2 1 PARTS IN THIS SHADED AREA ARE ON PROTOTYPING BOARD 1 CON3 CON2 DIGITAL ANALOG 10k 5x 10k D0 A5 D1 A4 D2 A3 D3 5x 22k A2 D4 A1 D5 A0 D6 6x 10k D7 D8 D9 S2 2 GND D13 GND λ LED2 ACTIVITY GND 5V AREF A K 22k Vin D12 3 1 S1 D11 CON4 INHIBIT POWER D10 3.3V SDA RESET SCL 22 Ω 1W SC CON1 A K A B1 6V/1.3Ah SLA IOREF K A LED1 ZD1 6.8V 1W CHARGING ARDUINO REMOTE MONITORING STATION λ K 2.2k FREETRONICS ELEVEN PLUS GPRS SHIELD 20 1 4 9V DC INPUT D1 1N4004 ZD1 LEDS K A A K 1N4004 A K Fig.1: the circuit for the Remote GPRS Monitoring Station. It’s based on an Arduino “Eleven” main board (with an ATmega328 microcontroller) and a GPRS add-on module. The extra circuitry shown here includes a battery and simple charger to power the unit, two control switches, two status LEDs and input protection and signal conditioning for the voltages or switches being monitored. create. If any of the inputs goes into a state which is abnormal, after a preset delay, it will send an SMS to your phone with the state of all the inputs. It can also be set up to send a periodic SMS too. That way, you can keep an eye on, say, battery voltages even when they are not critical, to get an idea as to whether the battery is being charged properly. And you can also prompt the unit to report to you at any time, by sending an SMS to its phone number. You can also redirect its messages remotely (eg, if your phone’s battery has gone flat). The five analog inputs can monitor voltages in the range of 0-15V with reasonable accuracy – good enough to check the charge state of a lead-acid battery. It’s also possible to connect various kinds of analog output sensors but extra interface circuitry may be required, depending on their voltage 28  Silicon Chip levels (as explained later). The digital inputs can be driven with a 0V/12V or 0/24V signal or can be connected to switches or relay terminals to track their opening or closing. Each input can have a separate delay before triggering an alarm, so events which occur periodically can be monitored. For example, you can get an alert if a bilge pump runs more than once every four hours, indicating a larger amount of water ingress than usual. You can also get an alert if a pump (or something else) runs for too long a period. The Remote Monitoring Station has an internal battery that is kept charged either from mains power via a plugpack or a solar panel, so that a power failure will not cause it to “go silent”. It can also be configured to send you an alert if its own battery is running down or if its power source has failed. The suggested battery powers the unit for about two days without charging but larger batteries can be used. With a solar panel, the unit becomes totally wireless and can be located just about anywhere that there is periodic sunlight and mobile phone coverage. How it works Most of the work is done by two prebuilt boards; an Arduino host board which in this case is the Freetronics “Eleven” module and a GPRS (General Packet Radio Service) ‘shield’ board from Seeed Studios. This shield board allows the unit to send and receive SMS (Short Message Service) messages. You need a SIM card and associated mobile phone number too; a low-cost, pre-paid SIM is suitable but you can also use a ‘post-paid’ SIM. The rest of the circuitry is quite simple and consists of a battery, trickle siliconchip.com.au Main Features •  Monitors up to five analog inputs (0-16V) and up to five digital inputs (0/12V or 0V/24V or open/closed switches). •  Sends an SMS message to a pre-defined phone number upon alert and/or periodic updates. •  Alert conditions can be defined individually for each input, including a time delay. •  SMS messages can be remotely redirected and status updates can be requested. •  Operates from internal battery for 48 hours; can be kept charged from mains or a solar panel. charger, the analog/digital input interface and some indicator LEDs and control switches. There is no custom PCB as this circuitry is all built on a Freetronics Arduino prototyping shield or uses point-to-point wiring in the case. Fig.1 shows the circuit. The five digital inputs connect to input pins on the Arduino board via 10kΩ protection resistors. It is therefore safe to apply voltages in the extra-low voltage (ELV) range to these inputs (maximum ±60V). A voltage above 3V will be read as high while below 1.5V, it will read as low. Anything in-between is undefined. A small pull-up current is sourced from each of these pins just before the state is sampled, so any which are open-circuit will read as high. Thus, you can connect a switch, relay or open-collector/drain device between a digital input and ground. The input will then read high when the switch or transistor is off or low when it is on. The analog inputs go to the Arduino microcontroller’s A1-A5 ADC inputs via 22kΩ/10kΩ resistive dividers. Since the micro runs from a nominal 5V supply, that gives a linear input range of 0-16V. The analog inputs are digitally filtered by repeated sampling and averaging, to reduce noise pick-up. While voltages above 16V cannot be read by the analog inputs, damage will not occur as long as the applied voltage is within the ELV range (±60V). Analog input pin A0 is connected to monitor the unit’s own battery voltage. Since this is a maximum of 7.5V, a different divider is used (10kΩ/10kΩ). Battery power The whole thing is powered directly from a 6V sealed lead acid (SLA) battery. The Arduino “Eleven” board has an onboard 5V regulator and this is used to supply power to itself and siliconchip.com.au the GPRS ‘shield’. The charging arrangement is very simple, consisting solely of reverse polarity protection diode D1, a 22Ω current-limiting resistor and a 6.8V zener diode to prevent over-charging. There is also a green LED (LED1) with 2.2kΩ current-limiting resistor connected across the input, to indicate charging. With a 9V DC regulated plugpack, the float charge current is (9V - 0.7V - 6.8V) ÷ 22Ω = 68mA. This gives a dissipation in the 22Ω resistor of 100mW. The charge current (and resistor dissipation) increases if the battery is flat but only to about 150mA/500mW; slightly more if using a 9V solar panel in bright sunlight. Since the specified battery is 1.3Ah and the circuit draws about 20mA, that means that a full charge will take about 24 hours. Hence this circuit is most applicable to situations where charging power will almost always be present (eg, mains power). It can be used with a solar panel but you may find that a larger battery or better charging arrangement (or both) are required for reliable operation during overcast days. The rest of the circuitry consists of power switch S1, inhibit switch S2 and activity indicator LED2 with its associated 22kΩ current-limiting resistor. S2 is used to prevent the unit from sending text messages. This is useful during set-up but also if a genuine failure occurs; once you (or somebody else) has arrived to fix the problem it has alerted you to, you can stop it sending more messages by toggling S2. S2 can then be reset once the problem is fixed. LED2 flashes in various different patterns to indicate what’s going on. It flashes periodically and briefly during normal operation. The high-efficiency blue LED only requires a drive current of 0.1mA and with brief flashes, the Parts List 1 Freetronics “Eleven” Arduino board or similar (Jaycar XC4210) 1 Seeed Studios Arduino GPRS shield (www.seeedstudio.com – Cat. SLD01098P) 1 SIM card 1 Freetronics Mega Prototyping Shield for Arduino (Jaycar XC4257) 1 UB2 jiffy box or similar (Jaycar HB6012, Altronics H0152/ H0182/H0202) 1 9V DC regulated plugpack or similar supply 1 chassis-mounting DC socket to suit power supply (Jaycar PS0522 or PS0524) 1 small 6V SLA battery (eg, Jaycar SB2495) 2 6-way chassis-mounting terminal barrier strips (Jaycar HM3168) 4 M3 x 9mm tapped Nylon spacers 8 M3 x 6mm machine screws 2 M3 x 10mm machine screws 4 M3 nuts 2 M3 Nylon nuts 4 6.3mm red spade quick connectors 2 6.3mm piggyback spade connectors 1 2.1mm-ID DC power plug or cable with plug 2 mini SPDT chassis-mounting toggle switches 1 20-pin dual female splittable jumper wire, 300mm (www. seeedstudio.com CAB115C3O) 1 20-way snappable pin header, 2.54mm pitch 1 300mm length foam-cored double-sided tape Light and heavy-duty hookup wire (various lengths and colours) Semiconductors 1 green 3mm LED 1 blue 3mm LED 1 6.8V 1W zener diode 1 1N4004 1A diode Resistors (0.25W, 1%) 6 22kΩ 1 2.2kΩ 12 10kΩ 1 22Ω 1W 5% overall effect on battery life is minimal. LED2 is lit continuously while an SMS is being sent, which takes about 25 seconds as it takes some time to March 2014  29 (D12) (D13) (D5) (D6) (D4) (D3) (D2) 22k k 10 k 10 k 10 k 10 k 10 1 CON3 6 1 CON4 CON2 6 2 3 1 (CON4) (CON3) (CON2) 1 x 10k (LH END) + 5 x 22k TOP VIEW (Vin) (A0) (A1) (A2) (A4) (A3) (A5) 6 x 10k (GND) BOTTOM VIEW Fig.2: follow these layout diagrams to fit the components to the Arduino prototyping ‘shield’. This has a grid of separate pads so insulated wires are added to make some of the connections. The pads around the edge connect to the I/O pins on the Arduino and GPRS modules. The bottom side overlay at right shows where additional links are required to connect components on the prototyping ‘shield’. Make these connections using wire lead off-cuts or solder bridges as necessary. ‘acquire’ a mobile phone tower. If the inhibit switch is set to prevent an SMS from being sent, the occurrence of an alert condition will cause the unit to rapidly flash LED2 for several seconds. This lets you check that the unit’s operation is correct without using up SIM card credit. LED2 remains off either if the unit is switched off or if the battery is flat and the unit has gone into power-saving mode. You can tell which is the case by simply examining the state of the power switch (S1). GPRS shield The GPRS shield/module is the most critical part of this project and the one that we are using is particularly easy to use and quite modestly priced, too. Is it from Chinese manufacturer and distributor “Seeed Studios” and can be ordered via their web page (see below). It has a SIM900 module from SIMCom which works particularly well but also has other circuitry such as a power supply for this module, SIM card holder and antenna. There are actually two versions of this shield. For this project, we are using the original version (v1.0) but this is no longer available. The revised version (v2.0) functions more or less identically but has a few improvements. It has a more efficient switchmode power supply, which means a slightly longer battery life. It also has an onboard antenna, eliminating the external whip. The other improvements are a softstart circuit for when it is powered on and off and some shielding to improve reception and protect the unit from static discharges. Since the original version is no longer available, constructors will need to use the revised version but it should be a straight drop-in replacement with no other changes required. Communication between the AT­ mega328 microcontroller on the Ard­ uino host board and the SIM900 are via an onboard serial port. This uses the ‘software’ serial port on the Arduino (on pins D7 & D8), leaving the ‘hardware’ serial port for debugging. The ‘software’ port uses more processor power but in our application, this is not important. The GPRS module can be purchased from www.seeedstudio.com/depot/ gprs-shield-v20-p-1379.html with free registered airmail postage or simply go to the Seeed Studios homepage (www.seeedstudio.com) and search for “gprs”. More information on this module and how to drive it can be found at: http://www.seeedstudio.com/wiki/ GPRS_Shield_V2.0 and http://rwsdev. net/wp-content/uploads/2013/02/ Sim900-rev01-Application-Note.pdf Besides the bidirectional serial port, which is used to send commands and data (eg, SMS message contents), Arduino pin D9 is used to turn the GPRS module on and off; it operates in parallel with the onboard pushbutton. We use this to keep the GPRS module off to save power, except for when a message needs to be sent or received. Power saving We keep the microcontroller on the Arduino board in ‘sleep’ mode most of the time. It wakes up roughly once per second to read the state of each input, then calculates whether an alert condition exists. If so, it then checks whether a message has been sent recently. If all is normal or if a message has already been sent in the recent past, it immediately goes back to ‘sleep’. While using a pre-built Arduino Table 1: Resistor Colour Codes   o o o o o No.   6   12   1   1 30  Silicon Chip Value 22kΩ 10kΩ 2.2kΩ 22Ω 4-Band Code (1%) red red orange brown brown black orange brown red red red brown red red black brown 5-Band Code (1%) red red black red brown brown black black red brown red red black brown brown red red black gold brown siliconchip.com.au Construction The first step is to set up the GPRS module. The SIM card is fitted to the holder by sliding the cover and lifting it up, then sliding the card into the slots with the contact side facing the contacts on the PCB. Push it all the way home, then slide the cover back across to lock it in place. You then need to check and possiliconchip.com.au Fig.3: the front panel label artwork and drilling template for the GPRS Remote Monitoring Station. It suits a UB2 jiffy box. SILICON CHIP SMS On Remote GPRS Monitor 5 3 Off + . 9V DC sibly set the jumpers which control which serial port is used (hardware or software). There are two jumpers on a 3x2 pin header matrix. Set these for the software serial port (“SWserial”), as labelled on the module. You can then plug the GPRS shield into the Freetronics “Eleven” board and apply power via a USB cable. You should see the green power LED light On SMS Off GND 1 2 3 2 GND 1 Active Charging Slow flash = idle Steady = sending SMS Fast flash = alert, SMS inhibited Off = switched off or low battery While conceptually simple, the software for the Arduino board in this project is quite extensive. It uses the micro’s “Watchdog Timer” to wake it up periodically to check the input states and this is also used as a timekeeping device. There are various counters to keep track of how long it has been since the last SMS was sent, how long since the last unprompted update, how long since it has checked for an incoming SMS and so on. If sending a message, the unit also takes that opportunity to check if there are any incoming messages and if so, scans them for valid commands and takes the appropriate action. If a long period passes with no outgoing messages, it will power up the GPRS module anyway, to check for incoming messages. This interval is adjustable as it is a compromise between a fast response to incoming messages and battery life. So that the unit can continue mon­ itoring the inputs and sleeping (to conserve power), interactions with the GPRS module are handled by a simple “state machine”. This means that after the GPRS module is powered up, the micro goes back to sleep, then wakes up a short time later and communicates with it – rather than remaining active while waiting for it to become ready. If you want more details on how the software operates, it is wellcommented so the best approach is to download and read it (from www. siliconchip.com.au). 4 Software 4 5 Digital Analog module saves a lot of effort, there is a disadvantage regarding its current consumption while idle. There are various LEDs which remain powered, the regulator has a relatively high quiescent current and so on, so it draws about 20mA even in sleep mode whereas a custom board could be designed to draw less than 1mA. Still, given the relatively large battery capacity, this isn’t a major problem. on the GPRS board and by holding down the power button on the side of that board for about one second, it should power on. You will then see the red LED come on and after some time, a second green LED should start flashing with a cadence of 64ms on, 800ms off (ie, about one flash per second). Assuming the SIM card is ready to go, this should change after a few more March 2014  31 This is the view inside the completed Arduino Remote Monitoring station. Most of the extra parts are mounted on the case lid and on the prototyping shield, with the latter then plugged into the headers on the GPRS shield. The battery is held in place on the bottom of the case using double-sided foam adhesive tape. seconds to 64ms on, 3s off (ie, one flash per three seconds) to indicate that it has found the mobile network. Once you’ve verified that, you can unplug the USB cable and move on to the next step in the construction. Interface board assembly Next, fit the components to the prototyping shield. Start with the four pin headers on the underside of the board which plug into the GPRS shield (these are supplied with the PCB). The easiest way to ensure they are fitted straight is to push the 4-pin headers into the sockets on the Arduino host board, 32  Silicon Chip then place the prototyping shield on top and solder the pins. Follow with the resistors, as shown on the layout diagram of Fig.2, starting with those which are flat on the board and following with the vertical ones. It’s a good idea to bend some of the leads over before soldering them and trim them slightly longer, so that they can be used to form the bottom side links later. You can then fit the top-side pin headers, followed by the wire links, which should be made with small gauge insulated wire. We used “Kynar” wire-wrapping wire. When all the parts are on the board, finish by making the solder bridges on the underside as shown in Fig.2. For those where you were not able to leave sufficient lead length, use short lengths of lead off-cuts. Alternatively, you can bridge solder between adjacent pads, although given the relatively wide spacing, this can be tricky. When finished, plug this board into the GPRS shield. Case preparation The next job is to drill the required holes in the lid. Copy the label (Fig.3) and use this as a drilling template. You siliconchip.com.au (UB2 BOX LID) SCALE: 91% OF ACTUAL SIZE ANALOG S2 S1 2.2k A K A LED1 DIGITAL LED2 22k + k 10 k 10 k 10 k 10 k 10 D1 22 Ω 1W 1 CON3 6 1 CON4 CON2 6 2 3 1 ZD1 6.8V FREETRONICS ELEVEN + GPRS SHIELD + PROTO BOARD – 6V 1.3Ah SEALED LEAD-ACID BATTERY CON1 K (UB2 BOX INSIDE) Fig.4: the complete wiring diagram. The battery, switch and LED connections are mostly ‘air-wired’, while ribbon cable fitted with individual pin sockets is used to plug into the headers on the Arduino interface shield. can also download this as a PDF file from the SILICON CHIP website (free for subscribers) and print it out. Once the holes have been drilled, remove the template, then print or copy another label onto photographic paper. This siliconchip.com.au label can then be laminated and attached to the lid using double-sided tape or spray adhesive, making sure that the hole locations in the label line up with the holes in the panel. The holes in the label can then be cut out using a sharp hobby knife. Next, fasten the two 6-way terminal barrier strips to the lid using M3 x 10mm machine screws and nuts, then mount the two toggle switches in place. The two LEDs can then simply March 2014  33 TO SENSOR +5V IC1a: ½ LM385 100nF OR LMC6482AIN 3 2 8 IC1a 1 4 TO ANALOG INPUT 27k GAIN = 10× 3.0k be pushed through their 3mm holes and glued into place using either hot melt glue or silicone sealant (or you can use plastic bezel mounting clips). The next hole required is that for the DC input socket. This goes in the side of the case, as shown in the photos. Place it slightly higher than half-way up the side of the case and centre it between the two adjacent corners. Enlarge the hole using a tapered reamer until the DC socket fits through, then secure the socket in place. Assembly You can now fasten the SLA battery down into the case using two strips of double-sided foam tape (see Fig.4). That done, complete the rest of the wiring as shown in the wiring diagram – see Fig.5. You then need to mount the Free­ tronics Arduino module in the case. Unplug the GPRS shield/prototyping board and use the Arduino board as a template to drill the four mounting holes in the bottom of the case. That done, fit four tapped spacers using short M3 screws, then use more screws to hold the Arduino module on top and plug the other boards back in. Note that we had to put ours adjacent to the edge of the case, so that the external antenna connector passed through the side. However, as stated above, the revised GPRS module has an internal antenna, so this is not required. For the connections from the pin headers on the Arduino module, the easiest method is to cut lengths of splittable jumper wire. These generally come as 20-way rainbow cable with separate female “Dupont” connectors for each strand. You can get this from Seeed Studios at the same time as you order the GPRS module (see parts list) but similar cables are available from other sources such as Little Bird 34  Silicon Chip Fig.5: a simple gain stage to interface sensors with low output voltages to the Remote Monitoring Station. The LM358 can be used where the output level will be below 3V at all times; the LM6482AIN can give an output of up to nearly 5V. Gain can be calculated as (27kΩ + 3kΩ) ÷ 3kΩ = 10 and using this formula, resistors can be selected for different gain values. Electronics (http://littlebirdelectronics.com). Individual female-to-female header jumper cables can also be used but tie them into bundles to keep them neat. Either way, strip the cut ends and solder them to the terminal barrier lugs, switch lugs and LED leads as shown. Now for the power supply wiring. You can crimp the quick connectors to the wires if they are sufficiently thick but component leads are too thin and will need to be soldered; do this quickly so as not to melt the glue holding the plastic surround in place. Perhaps the easiest approach is to push the piggy-back terminals onto the battery connectors, then trim the leads of the zener diode so it just fits between these and solder it to two crimp connectors. Watch the polarity when you plug this in or it will get very hot, very fast! You can then solder the connections from the DC socket to the exposed zener leads. As shown, the ground connection is direct whereas the positive side goes via a diode and 1W resistor wired in series. For the power connection to the Arduino board, either cut a DC power cable to length (eg, from a dud plugpack) or make up a twin-core cable with a DC plug. Either way, test the plug for fit first – a 2.5mm inner dia­ meter DC plug will go into the socket on the Arduino board (2.1mm ID) but will not make a reliable connection. You can then plug the two remaining quick connectors into the battery piggy-back terminals and solder the free ends of the DC power cable as shown. Complete the wiring as shown in Fig.4, including the wiring for the two LEDs. Connecting sensors Various sensors with analog outputs can be connected to the analog inputs on this device however not all will have suitable voltage swings. As specified, the inputs have a resolution of approximately 16mV. This is not suitable for reading the output of a sensor with, say, a 0-100mV swing. To increase the sensitivity of a given input, you can change the resistive divider. Best resolution is about 5mV, with the lower 10kΩ resistor in the associated divider removed. That will be sufficient for say a temperature sensor with an output of 10mV/K, giving a resolution of about 0.5°C and a range of about -250°C to +250°C. However, for a pressure sensor which gives 25mV full scale, this is still no good. In that case, you need to wire up an op amp to give some gain. Fig.5 shows the basic arrangement but we’ll leave the rest of the details up to you. Some sensors may require a more complex arrangement; refer to the manufacturer’s literature. Set-up Before programming the Arduino board, you need to customise the settings for your situation. Download the Arduino IDE (Integrated Development Environment) from http://arduino.cc/ en/main/software and load it up. You will then need the “sketch” for this project, which is available from the SILICON CHIP website (free for subscribers). Open up that ‘sketch’ (.ino file extension) which will launch the Arduino IDE. The first couple of pages of code contain the settings, as shown in Fig.6. The first entry is the phone number to receive alerts, which goes within the quotation marks. It must be in international format, ie, for Australia start with “+61” and then follow with the area code (drop the first zero) and the rest of the phone number. As shown, Australian mobile numbers will thus start with “+614”. The next entry is the SIM card PIN. You only need to set this if your SIM card has PIN protection. If so, make sure this is correct! Most new SIMs either have no PIN or it is set to the default value of 0000. Again, put it in quotes. Following that is a field to enter your carrier’s “Message Centre” phone number. This is a number through which messages are routed and can usually be found somewhere on the carrier’s website. For example, our test SIM was on the Vodafone network and we found the appropriate number at http://support.vodafone.com. siliconchip.com.au Software Settings typedef struct { float upper; float lower; float gain; } adiv; typedef struct { float minval; float maxval; signed long delaysec; } alimit; typedef struct { unsigned char state; signed long delaysec; } dlimit; // Phone number to send alerts to: char SMS_Destination[32] = “+614xxxxxxxx”; // PIN number for the SIM card, if used: char SMS_PIN[5] = “0000”; // SMS message centre number for your carrier: char SMS_MSG_CENTRE_NUM[32] = “+614xxxxxxxx”; // SMS command password, must be contained in a received SMS for any commands to work char SMS_PASSWORD[] = “simon says”; // Send an SMS once a day (ie, 24 hours x 60 minutes x 60 seconds, 0 = off): unsigned long SMS_send_interval = 60*60*24; // Never send an SMS more than once every half hour: unsigned long SMS_min_send_interval = 30*60; // Check for SMS reception every half hour (0 = off) unsigned long SMS_recv_check_interval = 30*60; // How long to suppress messages for after a STOP command is received (default eight hours) unsigned long SMS_suppress_time = 8*60*60; alimit alimits[] = { /* analog input configuration */ { /* min voltage */ 5.5, /* max voltage */ 6.9, /* delay (sec) */ 60 }, // battery voltage { /* min voltage */ 0.0, /* max voltage */ 16.0, /* delay (sec) */ 15*60 }, // input A1 { /* min voltage */ 0.0, /* max voltage */ 16.0, /* delay (sec) */ 15*60 }, // input A2 { /* min voltage */ 0.0, /* max voltage */ 16.0, /* delay (sec) */ 15*60 }, // input A3 { /* min voltage */ 0.0, /* max voltage */ 16.0, /* delay (sec) */ 15*60 }, // input A4 { /* min voltage */ 0.0, /* max voltage */ 16.0, /* delay (sec) */ 15*60 } // input A5 }; dlimit dlimits[] = { { /* expected state */ 1, /* delay (sec) */ 15*60 }, // input D1 { /* expected state */ 1, /* delay (sec) */ 15*60 }, // input D2 { /* expected state */ 1, /* delay (sec) */ 15*60 }, // input D3 { /* expected state */ 1, /* delay (sec) */ 15*60 }, // input D4 { /* expected state */ 1, /* delay (sec) */ 15*60 } // input D5 }; adiv adivs[] = { /* analog input dividers */ { /* upper resistor (kOhms) */ 10.0, /* lower resistor (kOhms) */ 10.0, /* gain */ 1.0 }, // battery voltage divider { /* upper resistor (kOhms) */ 22.0, /* lower resistor (kOhms) */ 10.0, /* gain */ 1.0 }, // input A1 divider { /* upper resistor (kOhms) */ 22.0, /* lower resistor (kOhms) */ 10.0, /* gain */ 1.0 }, // input A2 divider { /* upper resistor (kOhms) */ 22.0, /* lower resistor (kOhms) */ 10.0, /* gain */ 1.0 }, // input A3 divider { /* upper resistor (kOhms) */ 22.0, /* lower resistor (kOhms) */ 10.0, /* gain */ 1.0 }, // input A4 divider { /* upper resistor (kOhms) */ 22.0, /* lower resistor (kOhms) */ 10.0, /* gain */ 1.0 } // input A5 divider }; float Low_Battery_Level = 5.0; // do not flash LED or send SMS with battery below this voltage Fig.6: first lines of the software showing the settings which can be customised to suit your application. Text written /* like this */ or prefixed with a double-slash (“//”) indicates a comment which has no effect on the operation of the software. au/articles/FAQ/Vodafone-messagecentre-number The next entry is the SMS command password. You can control the unit remotely by sending it messages containing certain text commands but they are ignored unless the message also contains this password. The default siliconchip.com.au is “simon says” but you can change it to something else to protect against the unlikely event that somebody else figures out your unit’s phone number. The next four settings are time intervals, specified in seconds. You can use “*” as a multiplication operator to make setting them easier, eg, 4 * 60 * 60 works out to four hours (four hours times 60 minutes per hour times 60 seconds per minute) as does 4 * 3600. The first is the interval at which the unit will send you status updates, regardless of the input states. The default is once per day (24 hours). However note that the time of day that the mesMarch 2014  35 Fig.7: before programming the Arduino board, it must first be plugged into a USB port and assigned to a serial port as shown here (Windows 7). sages are sent is determined by when the unit is first switched on and if it loses power completely, that will reset the timing. Also, the time-keeping isn’t exact so it will likely drift over time (although you can reset the timing remotely). If you don’t want to get messages unless something is wrong, set this item to “0”. The next time interval specifies the minimum message sending interval. The default is every half hour. So if there is a continuous alert, you will get at most two messages per hour until the alert goes away (or you tell it to stop). The third time interval determines how often the unit powers the GPRS module up to check for incoming messages. The default is half an hour but as explained earlier, a shorter time will give a faster response to incoming messages but use up the battery faster. This can also be set to zero, in which case the unit will only check for incoming messages after sending a message. The final time interval sets how long messages are suppressed after an appropriate command is received by the unit. The default is eight hours. Note though that you can send another command to tell it to resume sending messages to override this if necessary. Input settings Now you will need to tell the unit 36  Silicon Chip the expected state of each input that is connected, ie, define what will trigger an alert. This is done separately for the five analog inputs and the five digital inputs. Start with the analog inputs. The first line sets the acceptable voltage range for the internal battery. The default is for a minimum of 5.5V and a maximum of 6.9V, with a delay of one minute. So if the battery voltage drops below 5.5V or goes above 6.9V and stays there for more than a minute, an alert condition will occur and a message will be sent (unless messages are being suppressed). The following five lines work the same way except that these define the minimum and maximum allowed voltages for the five external analog inputs. If an input is not connected, leave the range as 0-16V so it can never generate an alert. If you want to generate an alert when an input is within a voltage range (rather than outside it), swap the minimum and maximum values. So, for example, if the minimum is set to 9V and the maximum to 8V, the unit will generate an alert when the voltage at that input is in the range of 8-9V and not if it is below 8V or above 9V. Next, set the expected states for the five digital inputs and their associated alert delays. If a digital input is not connected, set the expected state to 1 (high). If an input is connected to a relay/switch with the other end to ground, that input will change to 0 (low) when the contacts are closed. Regarding the delay setting, say you want to make sure a pump runs at least once an hour and the switched +12V supply to that pump is connected to a digital input. Set the expected state to 1 and the delay to be 60*60 or 3600 seconds (one hour). Thus, when the pump switches off, the alert timer starts. If it does not go high (switch on) again within an hour then an alert will be generated. If you want to set a maximum interval to generate an alert (eg, to ensure a pump doesn’t run too often), put a minus sign in front of the period, eg -3600. Finally, if you have changed any of the analog input divider resistors, update the values in the “adivs” table so that the software can scale the input voltages correctly. You will also need to set the gain to a figure other than 1.0 if you are applying any gain to the signal being fed to the input. Programming it Having finished altering the settings to suit your usage case, in the Arduino IDE, press CTRL+R or select the “Verify / Compile” option from the “Sketch” menu. After a few seconds, you should see a message at the bottom of the window giving the “Binary sketch size”. If you don’t, or if there are error messages, fix any mistakes you have made in the settings and verify again until it succeeds. You can then plug the Arduino board into your PC using a USB Type A to Mini Type B cable (typically supplied with the Arduino board) and upload the software and settings by pressing CTRL+U or selecting “Upload” from the “File” menu. Note that when you plug the Arduino into your PC, it may take some time for it to be fully detected and you must wait for this to occur before uploading the sketch or it will fail. In Windows, you can check that it has been detected by going to the “Devices and Printers” section of the Control Panel. Fig.7 shows the result on a Windows 7 PC. As you can see, the Arduino board is detected as a “Freetronics 8U2 USB” on COM17. If you then open the “Tools” menu in the Arduino IDE, under the “Serial Port” sub-menu, you siliconchip.com.au The phone SIM card is inserted into a carrier on the back of the GPRS shield as shown here, while the battery holder is left empty. This view shows the GPRS shield board plugged into the Arduino board, ready for installation in the case. can then select COM17. You should then see an indication that it is connected in the bottom-right corner of the IDE and you can then proceed to upload the software. After a successful upload, unplug the USB connection, plug in the DC socket from the battery power supply and your unit should be ready to test. Testing Start with the SMS inhibit switch in the “SMS Off” position. Apply charging power and the green LED should come on. The voltage across the battery should be slowly rising. Switch the unit on and the blue LED should start to flash at 1Hz (with a short on-time). Trigger an alert condition and after the set delay, the blue LED should flash rapidly for a few seconds and this will repeat once per minute. Next, set the inhibit switch to “SMS On” and after a short delay, the unit should send an alert SMS to your siliconchip.com.au phone. If this fails, the LED will flash rapidly, as it did when inhibited. In this case, check that the SIM is valid, is inserted correctly and you have set the correct PIN. Power supply Since the charging arrangement is very simple, the supply needs to have reasonable regulation. An unregulated 9V plugpack is not suitable (without increasing the current-limiting resistor value). A 9V regulated plugpack or small 9V solar panel should be fine and either can be connected directly to the power input. If you want to charge the unit from a 12V battery or use an unregulated 9-12V plugpack, the 1W currentlimiting resistor should be increased to at least 68Ω. Operation Once you have verified it’s working, the unit is pretty much just a “set and forget” affair. However, there are some commands which may be sent remotely if necessary. You should be able to determine the unit’s phone number by waiting for it to send you a message, then adding the remote number to your phone book. If you send a message to this number containing the password string (set earlier), plus at least one command, the unit will act accordingly once it has received that message. As noted earlier, this won’t necessarily be immediate. You can include multiple commands in a message. The commands are: •  “suppress” – the unit will not send you any more messages for some time, unless you send a “resume” command. This time is set in the Arduino software header and defaults to eight hours. •  “resume” – cancels any “suppress” command. •  “status” – causes the unit to immediately send an input status report. •  “reset” – resets the timing of periodic status updates. If, say, the unit is set to send an update every 24 hours, the next update will be (roughly) 24 hours from the reception of this command. •  “redirect <phone number>” – send future messages to the specified phone number instead of the one configured in the software. If power is lost (eg, the battery discharges totally), it will revert to the original number. The phone number must start with a + followed by the country code, area code and phone number. The messages sent by the unit have the following format: Batt: 6.21V [OK] Analog: 0.00V [OK] 0.00V [OK] 0.00V [OK] 0.00V [OK] 0.00V [OK] Digital: 1 [OK] 1 [OK] 1 [OK] 1 [OK] 1 [OK] This shows the battery voltage, the voltage at each analog input in sequence (1-5) and then the status of each digital input in sequence (0/1). If any of these is outside its specified range, the “[OK]” is replaced with an exclamation mark, followed by an indication of how long this has been the case. This example message is 123 characters long and the maximum length of a standard SMS is 160 characters. The message length can increase slightly if it displays voltages higher than 9.99V or if any of the inputs is out of range. The maximum length is around 150 characters and so will always fit in a SC single SMS. March 2014  37