Last week in Part 2 we used ezCircuit Designer software to do the on-screen wiring of our temperature alarm....
..and then we physically wired-in the battery pack, temperature sensor and buzzer. (All the components are available in the eLab6 EZ Starter Kit that with the eLab6 module, costs AUD$44.50 + GST.)
Now it’s time to write the software that runs the temp alarm. Don’t worry – you don’t need any existing computer programming skills!
Note: this story assumes that you have read and understood the previous parts in this series. If you haven’t done this, it’s unlikely you will achieve success with the following project!
|
Flow Chart
Before we get into the software writing, let’s think again about what we want the temp alarm to do.
This flowchart shows the approach. We need to:
(1) Monitor the temperature sensor
(2) Compare the measured temperature with the internal set-point (the set-point is the temp we want the module to remember)
(3) Turn on the buzzer if the temp is above the set-point
That’s the flowchart that will underpin the ezCoreChart software that we’ll now build.
EzCoreChart
The first step is to open ezCircuit Designer and then, if our Temp Alarm doesn’t appear on-screen, to open our saved file.
Press the button shown here by the arrow, and ezCoreChart will open. (If it doesn’t open, you may not have downloaded and installed ezCoreChart. Go to eLabtronics for this software.) By opening ezCoreChart from ezCircuit Designer, all the information you’ve put into ezCircuit Designer is transferred across to the new program.
The beginning of the flowchart (the software program that will run our Temp Alarm) is shown here highlighted within the red oval. As you can see, a test program for the buzzer comes up automatically. However, because we’re so confident, we don’t need to take this step. To get rid of the ‘BuzzerTest’ box, click on it once and then press the ‘Delete’ button at the top right. ‘OK’ the pop-up box and then the buzzer test box will be gone.
The screen will now look like this.
You might remember that when we thought of how a temp alarm would work, we said that the first step was that the module would need to monitor the temperature sensor, and how this was an input. Click on the Input box ...
...and down below in the Icon properties box will appear AnalogConv, as highlighted here in red. ‘AnalogConv’ means ‘analog conversion’ and what that means is that this software box allows the ‘brains’ to understand any variable voltage signal within the range of 0-5 Volts. (Voltage is like electrical pressure.)
So by using this icon, the electronic module will recognise the output of an appropriate temperature sensor, light sensor, pressure sensor (etc), or in fact any signal that varies within the range of 0-5V (eg in a car, an airflow meter or MAP sensor).
Click on AnalogConv and then move your cursor across to directly underneath ‘Start Main’ oval. By then clicking at that spot, an AnalogConv icon will be inserted in the software flowchart – as shown here.
Now we need to configure the AnalogConv icon. Double click on it and a box pops up. There are two user-definable elements – the Source and the Destination.
‘Source’ means: what input is the AnalogConv supposed to be looking at? By accessing the drop-down menu at Source, TempSensor comes up – so select that. (This label is available because you already wrote it in ezCircuit Designer!)
The default Destination is ‘Result’ – you can leave this as it is. Incidentally, you can at any time check the settings of AnalogConv icon by double clicking it.
So in this step we have configured the microcontroller to look for TempSensor on the pin to which we’ve already connected it, and then to call this reading the ‘Result’. The next step is to compare the Result with an internally set value.
Click on Numbers, then select Compare. Place the Compare box directly beneath AnalogConv, as shown here.
Double clicking on the inserted Compare box brings up these options. You can firstly select the Source (use the drop-down menu to select Result (which is what we just said the output of the AnalogConv was called), and then type in the number you want the temp switch to trigger at. So how do you work out that number?
The temp sensors supplied in the EZ Starter Kit have an output of 10 millivolts per degree C and work from minus 40 to plus 125 degrees C. (Note: there are 1000 millivolts in a volt.) However, rather than start at 0 volts at 0 degrees C (which means the sensor wouldn’t be able to work at freezing point as there’d be no signal output to measure!), the sensor at 0 degrees C has an output of 500 millivolts. (This is called a 500 millivolt offset.)
So if you want the temp alarm to trigger at 40 degrees C, you do this calculation for the set-point: 40 degrees C x 10mV = 400 mV, plus 500mV (the offset) = 900mV, or 0.9 volts. So for a 40 degree set-point, you type in 0.9.
If you wanted the sensor to trigger at 0 degrees C, the calculation would be 0 degrees C x 10mV = 0, plus 500mV = 500mV, or 0.5V.
If you wanted the sensor to trigger at minus 10 degrees C, the calculation would be minus 10 degrees C x 10mV = minus 100, plus 500mV = 400mV, or 0.4V.
If you’re sitting in a room at normal temperature, set the value at 0.7, which corresponds to 20 degrees C.
But there's one further tricky bit. The above calculations are correct if the module is being powered by 5V. If it's being powered by 4.5V (ie three 1.5V cells) then the temperature set-point will be lower than indicated.
|
OK, so we have the temperature trip point number written in the software – so what’s next?
You can now select Above, Below or Equal, depending on whether you want the output to trigger above, below or equal to the selected value – in this case, tick ‘Above’. Leave the hysteresis slider as it is.
After you’ve done the above step, you’ll see the software automatically adds a whole lot more boxes to the program, as shown here. But there’s no need to panic – just look at the box labels. Directly under Compare is ‘If above’. In this box is ‘Y’ for Yes and ‘N’ for No. If the value read from the temp sensor is above the value you’ve set, the program flow diagram moves in the ‘Yes’ direction. If the value read from the temp sensor is below the value you’ve set, the program flow diagram moves in the ‘No’ direction. Let’s do the Yes first.
We know that if the temp is above the set-point, we want to turn on the buzzer. Click on Outputs at the top-right of the screen, and then select ‘OnOffPin’. Place OnOffPin under Y (for Yes). The screen should then look like this.
Double click on OnOffPin and this box will pop up. It shows that the Destination is the Buzzer (great, that’s what we want!) and that the buzzer will be switched on. That’s all fine; we don’t need to make any changes so just press OK.
So let’s take a step back. From the top of the program, we use AnalogConv to recognise and import the temperature sensor reading. In Compare we then compare that temp value with an internal set value (the value that is memorised). If the temp is above the internally set value, we turn on the buzzer through the use of OnOffPin.
Then the program finishes.
Hmmm. The fact that it finishes means that the program will work only once – not what is wanted! In fact, what we need to do is loop the running of the flowchart (ie the program) around to the beginning, so it keeps on going on and on and on (and...). We do this in two steps.
Firstly we insert an ‘Address’ box immediately after Start Main...
...and then we insert a GoTo just before the End Main box. The program then jumps back to Address whenever it reaches GoTo. Therefore, whenever power is switched on, the program goes round in an endless (and very fast!) loop.
But there’s one final problem. Once the buzzer gets switched on, what switches it off? The program loop can keep on running but the buzzer, once it has triggered for the first time, will stay triggered. To overcome that problem, we insert an OnOffPin as shown here and then set its output to Off. That way, the buzzer will stay off until it is deliberately switched on.
Have a good look at the program, running through the functions of each box in your head. If you need to be reminded of what each box does, double click on it. It’s really important to ensure that the program makes sense to you. You don’t want to look at the screen and see just a bunch of coloured boxes; you want to see a logical flow diagram that switches on the buzzer when the temperature is above the set-point you’ve specified.
If all is OK, click on File and then save the program using an appropriate name.
Programming the Module
Transferring your newly written program to the eLab6 is done in this way. The module is left switched off during the programming procedure.
Plug the programming cable into the Programmer and then the USB port. The Programmer’s yellow LED should light. Then plug the programmer into the eLab.
Press the ‘Send Program to Chip’ button. The software will ask if you want to save the program (you do) and then a box will come up showing the programming status. At the end you’ll see a green bar and the words ‘write successful’.
Unplug the programmer and then the Temperature Alarm is ready to be tested.
Testing
When you turn on the eLab6, and if it’s above 20 degrees C, the buzzer should sound. (If you can hear the buzzer only very faintly, take off its paper seal.) By applying ice to the sensor, you should be able to make the buzzer turn off.
If the Temp Alarm doesn’t work, check:
-
That the wiring of the module connections (the temp sensor and buzzer) are as shown in ezCircuit Designer.
-
The software program, especially ensuring that the AnalogConv has TempSensor selected as the Source, and OnOffPin has Buzzer selected as the Destination. Also ensure that the selected temp trip-point corresponds to a temperature range that is appropriate for how you are testing.
-
When programming the module you get the green bar at the end of the programming process.
When the system is working correctly, try changing the selected trip-point temp value in the software. Reprogram the module and check that the change is effective.
You can also alter the program so that the buzzer operates when the temp is below the set-point. Alter the tick box in the Compare icon...
...and then insert an OnOffPin below ‘If below...Y’ as shown here. Then send the new program to the module.
To alter the output from being a buzzer to a LED, you don’t need to make any software changes. Just select a LED from the eLab6 EZ Starter Kit and wire it in place of the buzzer, with the white wire to Connector 2 and the black wire to (-).
Conclusion
ezCoreChart allows the very quick and simple assembly of programs that can achieve real outcomes. The Temperature Alarm shown here can be used for:
-
Frost alarm
-
Greenhouse temp alarm
-
Solar water heater monitoring
-
Intake air temperature alarm
-
Oil temp alarm
-
Coolant temp alarm
-
Amplifier or computer temp alarm
...and many other uses. The temp sensor can work in free air or be potted in epoxy for use in fluids. The wires to the temp sensor can also be extended as required.
Next week we’ll add an external pot that lets you easily adjust the trip-point, and do some very tricky things by using two temp sensors rather than just the one.
Download the ezCoreChart Temperature Alarm softare program below:
|
Go here for the next in this series.