Smart Hob by Alex Ross-Martin & Chris Cobb

Overview:

Many houses use electric hobs, these are quite inefficient and waste a lot of energy by over-heating and then stay hot for a long time after being switched off. They are present in 31% (Gov Report 9: Domestic appliances, cooking &
cooling equipment) of homes all over the uk and so a small energy saving would equate to big net savings.

On of the inherent inefficiency of the hob when it is being carefully used, a large amount of energy is wasted by users who are not using their hobs properly, such as boiling over or maintaining a temp that is above what is needed.

Project Aim:

To produce a device capable of monitoring and controlling the temperature of a hob to ensure that it is operating at its most efficiently. As well as the sustainability benefits, it should enhance the users cooking experience and be easy to use.

Research:

Stats:

The average house uses 1.5kwh per day cooking.

How much energy does it take to boil 1 litre of water on the hob?

Our experiments showed that bringing a pan of water to the boil over 10 minutes used 0.2Kwh.

Additionally we found that after bringing water to a boil, we could continue to boil water for 4 minutes after switching it off due to the retained heat in the ring.

How will our project help users?

Evidence shows that telling people alone is not enough to make them change their habits, that is why our project will aim to automatically improve energy usage without the user having to do anything. Additionally it should make the cooking process easier which will encourage them to use it.

Components:

-Arduino R3 Uno

-DS18B20 waterproof temperature sensor

-Max6675 breakout board

-K type thermocouple

-LCD display

-i2c board for LCD

-Buttons

-240v relay (5v input)

Using sensors to plot temperature

Our first step was using both our sensors to read the temperature of the hob and the water.

IMG_20180409_173821

Both sensors use their own libraries to convert data to a useable format, you need to use the correct functions to call the data from the sensors in order to use it.

Hob&water1

Once we had both sensors working together we could easily record the temps on the serial plotter like this.

Relay control of the hob

hot plate guts

This hob is very simple, having essentially only on/off switches. This meant we could control it using a relay inline in the positive feed.

Simple on or off relay control is as simple as writing pins high or low, but for more accurate control “time proportioning control” is used, this is where a window of maximum on time is created, then the relay can be turned on for a proportional of that window equivalent to the desired output.

ie if 50% power is required relay is on for 1/2 the window.

This system is very easy to set up and can be good for use with relays due to the fact it doesn’t produce excessive switching.

Control system

The bulk of this project has been spent on understanding and applying control to the hob. We started with a very simple “bang-bang” control, however this proved completely unusable due to the large thermal lag in the system.

We needed something better, hence we started investigating PID control.

This highly tuneable method is an industry standard for maintaining tight control over closed-loop systems. It uses 3 terms to compute the output needed to get a measured variable to a set value and keep it there, the first is proportion, which means increasing the output in proportion to the gap (error) between the measued and desired variables. It also takes account of the previous errors in the integral term and uses these to try to address consistent errors, this makes it adaptive to change in the system. The final term is the differential, which tries to predict what the next error will be based on how the error is changing, this can be used to make the system react quickly to upsets.

Writing an entire controller from scratch would be time consuming, luckily there is an arduino library available for the job. However implementing the library is not the easiest task, it requires careful tuning and a good knowledge of the underlying system.

https://create.arduino.cc/editor/AlexRossMartin/87a0c311-3678-44ac-bf07-eadfa69ec2b1/preview?embed

After several hours attempting to tune it, the controller was only able to be kept within 15* of the setpoint. However this could be improved with additional tuning time.

The user inteface

A key part of the project has been trying to add benefit to the user experience of cooking on the hob. Inspiration came from the simple interface on a microwave, where an lcd displays time and input is given by buttons.

IMG_20180419_151759[1]

Bringing it all together

The final version contains 2 sequential PID controllers, setup to feed into one another. Using this method, the stabilisation temperature of the water was improved significantly, now being stable to within a few degrees.

https://create.arduino.cc/editor/AlexRossMartin/f4c363ca-7c6d-43a6-a0f7-c628da934096/preview?embed

updated code, 23/04/2018:

https://create.arduino.cc/editor/AlexRossMartin/df786638-a882-4350-b65a-650b23975ed3/preview?embed

IMG_20180419_153307[1].jpg

Conclusion

In conclusion, this project has demonstrated the use of PID control to reduce the energy consumption of a hob.

With some careful tuning it could have a very good impact on reducing as well as benefiting the cooking experience.

Continuing from PID

Foreword:

After our previous work on PID control of the hob, despite the challenges of tuning we decided to press on with development of the code.

I decided to experiment with my earlier idea of using sequential PID controllers to better regulate the temp. I also made the effort to re-organise some of the code and group it into individual functions.

https://create.arduino.cc/editor/AlexRossMartin/539598fa-0b47-4f4e-92b3-f5a210f0255b/preview?embed

Despite the ropey tuning, this version was surprisingly stable. I think due to the thermal capacitance of the water. I feel confident that with better tuning it could do a reasonable job!

 

Now that we had some semblance of a working controller, we had to add the extra functionality which would make it into a consumer product.

These functions are:

  • LCD display showing temps and cooking time.
  • Buttons for adding cooking time.

I decided to start on adding the buttons, they are simple enough to wire up, we have them switching the signal to low.

buttons

Luckily I had already written a sketch for a descending timer, for use with some earlier code. It allows users to input a time in 30 second increments and will proceed to run the desired main loop function once no button has been pressed for 30 seconds.

Combining:

Next was combing this with the code I had already written for controlling the hob.

https://create.arduino.cc/editor/AlexRossMartin/e82a0180-8ab1-4218-b602-78520436eab5/preview?embed

My first attempt was just adding the two together without causing any errors, which was easy enough.

Next up I added some actual functionality to the timer as well as including a function which converts time in millis to an output in hh:mm:ss.

https://create.arduino.cc/editor/AlexRossMartin/2e81abf7-3f96-4d4d-b9bb-7b2f5952d469/preview?embed

I took this video showing the timer in action.

LCD screen:

In order to save space on the arduino, we decided to use the i2c bus. Coding it all in was pretty straight forward. I also made a few adjustments to the organisation of the code.

LCD

https://create.arduino.cc/editor/AlexRossMartin/f4c363ca-7c6d-43a6-a0f7-c628da934096/preview?embed

 

Video in action:

 

 

 

Conclusion:

We are pretty pleased with the amount we have managed over the last week, the controllers will definitely need to tuning and i would like to add more functionality if possible, particularly including the cooling rate estimator from earlier in the project.

 

I think due to the poor tuning it will be difficult to quantify the sustainable benefits, It is clear that a well tuned PID controller would reduce the energy consumption of the hob, since it would not over shoot the desired temp.

 

Alex&Chris

Continuing from bang-bang.

Foreword:

At the conclusion of the last post we had slightly given up hope on developing a really robust solution to our control problem.

we went back to the drawing board and decided to compare directly the hob and water temps whilst under human control.

Using the following code and outputting to the serial monitor, we plotted these graphs.

https://create.arduino.cc/editor/AlexRossMartin/862a54f6-5dfb-4814-b627-4cfa38ffa96f/preview?embed

As you can see the gradient at which the temp increases is pretty linear. This is good because it means the rate can be predicted.

We then decided to turn the hob off and observe the ramping down, here our original hypothesis was proven to be right! After turning the hob off at temp of ~160* and water temp of 98* (an aggressive boil), we got 4 more minutes of sustained boiling before making the judgement that although the water was still bubbling, it did not qualify as  rolling boil. We observed that the temp of the hob when this happened was around 130*.

Next:

We now assume that 135* is enough to sustain a boil in the water, we should now be able to simplify our model to running a closed loop PID controller which only monitors the hob temp and infer that a stable hob temp of 135* will be enough to maintain the boil.

I began by downloading the arduino PID library, which has taken care of the complex mathematical side of things and leaves the tuning and implementation.

https://create.arduino.cc/editor/AlexRossMartin/99728b40-9a1d-418a-8e2a-31752cc6f1f5/preview?embed

This is the example code for using the PID library to control a relay.

I had to edit it to make use of our max6675 thermocouple.

https://create.arduino.cc/editor/AlexRossMartin/87a0c311-3678-44ac-bf07-eadfa69ec2b1/preview?embed

Once we did this and uploaded the code we found a strange issue…

we needed to examine the serial plotter to have ago at tuning the PID, however when we opened it we found that the sensor reading was stuck at one value. First we thought that there must be something wrong with our variables, meaning a new value was not getting written to the value but we double checked the code and were pretty sure this was not the case. We then realised that everytime you closed the serial monitor and opened it again, it was stuck at a different value.

We went back and checked the data sheets and discovered that the max6675 takes 0.22 seconds to calculate it’s new values and our loop function was cycling much faster than that. After this we added a sensor refresh statement to the code which fixed the problem.

First run:

now that our PID control was working we had a first run.

PID control 1st run

It is some way off being stable, but that is to be expected given that we are using arbitary tuning values. We will have a go at tuning it next but first…

Hardware lag:

We have been facing consistent problems with lag in the system, which makes control difficult. We had assumed that our system was in 2 layers, the hob plate itself and then the water/pan, but whilst working today we noticed through a gap in the hob that the heating element itself is completely seperate and the gap between them is responsible for the continued increase of the hob even after we have turned the element off.

We believed that our placement of the sensor in direct contact with the hob plate was giving us an accurate reading of the input temp to the system but that is clearly not the case. We will relocate the sensor much closer to the heating element and that should help make control easier.

 

 

 

 

 

Tuning:

After the hardware adjustment I had a go at tuning the PID controller, based on what I read here.

Initially I set the gains for the integral and derivative functions to 0, effectively turning them off.

After several hours of slaving, I managed to get it oscillate around the set point by around 15*. The values i used were kp =128, ki = 0.1, kd = 2.

At this point I decided to give up on calibrating further and try to progress with the code.

Alex & Chris

week 4: Bang bang controller

Foreword:

Following on from our observations that the pan of water would maintain a steady rolling boil if the hob was at 135* we decided to try to build a simple “bang bang controller” to do that.

What is that?

In control theory, a bang–bang controller otherwise known as 2 step or on–off controller, also known as a hysteresis controller, is a feedback controller that switches abruptly between two states.  They are often used to control something that accepts a binary input, for example a furnace that is either completely on or completely off. Most common residential thermostats are bang–bang controllers.

A water heater that maintains desired temperature by turning the applied power on and off (as opposed to continuously varying electrical voltage or current) based on temperature feedback is an example application of bang–bang control. Although the applied power switches from one discrete state to another, the water temperature will remain relatively constant due to the slow nature of temperature changes in materials. Hence, the regulated temperature is like a sliding mode of the variable structure system setup by the bang–bang controller.

Symbol for a bang-bang control
IMG_20180417_213638.jpg

Application:

In our temperature control system, the most simple application of a bang-bang control is simply 2 cases: if the temp is below the target temp, switch the hob on; if the temp is above it, switch it off.

This can be described by a quick if statement:

https://create.arduino.cc/editor/AlexRossMartin/96b2197e-b7c7-4b12-871b-f9758dc8a61c/preview?embed

Bangbang1bangbang2bangbang3

This is the code as simplified as possible and as you can see from this graph it doesn’t do a very good job of controlling the temp. The switching produces an alternating massive overshoot above and below the target, it overshot the target temp of 100* by almost 40*.

This highlights a key problem with simple controllers like this, which is they don’t cope well with lag. They can be quite effective in a system where the control acts immediately but since our entire project revolves around the fact that there is heat lag in the hob it will not be as effective.

That is not to say that a bang-bang controller can be completely ineffective, because if you are using a completely closed system then the lag should be consistent and you will be able to introduce some parameters to tune it out. This is the case in hot water boilers, which use a fixed element and volume of water.

What next?

Next we have a choice, do we stick with a simple on/off controller and try to add some more complexity to get it to be more stable or move to a PID controller which ought to be better but will be substantially more complicated and therefore much easier to make errors in the code.

Well what is a PID controller?

proportional–integral–derivative controller (PID controller or three term controller) is a control loop feedback mechanism widely used in industrial control systems and a variety of other applications requiring continuously modulated control. A PID controller continuously calculates an error value e(t) as the difference between a desired setpoint (SP) and a measured process variable (PV) and applies a correction based on proportional, integral, and derivative terms (denoted PI, and D respectively) which give the controller its name.

In practical terms it automatically applies accurate and responsive correction to a control function. An everyday example is the cruise control on a road vehicle; where external influences such as gradients would cause speed changes, and the driver has the ability to alter the desired set speed. The PID algorithm restores the actual speed to the desired speed in the optimum way, without delay or overshoot, by controlling the power output of the vehicle’s engine.

The first theoretical analysis and practical application was in the field of automatic steering systems for ships, developed from the early 1920s onwards. It was then used for automatic process control in manufacturing industry, where it was widely implemented in pneumatic, and then electronic, controllers. Today there is universal use of the PID concept in applications requiring accurate and optimised automatic control.

IMG_20180417_213646.jpg

 

  • Term P is proportional to the current value of the SP − PV error e(t). For example, if the error is large and positive, the control output will be proportionately large and positive, taking into account the gain factor “K”. Using proportional control alone in a process with compensation such as temperature control, will result in an error between the setpoint and the actual process value, because it requires an error to generate the proportional response. If there is no error, there is no corrective response.

 

  • Term I accounts for past values of the SP − PV error and integrates them over time to produce the I term. For example, if there is a residual SP − PV error after the application of proportional control, the integral term seeks to eliminate the residual error by adding a control effect due to the historic cumulative value of the error. When the error is eliminated, the integral term will cease to grow. This will result in the proportional effect diminishing as the error decreases, but this is compensated for by the growing integral effect.

 

  • Term D is a best estimate of the future trend of the SP − PV error, based on its current rate of change. It is sometimes called “anticipatory control”, as it is effectively seeking to reduce the effect of the SP − PV error by exerting a control influence generated by the rate of error change. The more rapid the change, the greater the controlling or dampening effect.

 

The controller does not require all terms to work well, you can use only the P, the PI or the full PID. Each layer should give you better and better control, however due to the fact that the controller will need tuning, it may be more difficult to make it stable the more terms that are added.

Examples

With PID controllers in mind, we began browsing online to see if there were any examples we could use.

As it turned out, we found multiple examples of arduino powered sous vide builds which were producing very similiar functionality to what we were looking for.

Ada-fruit sous viduino.

I then found this example which claimed to be self-tuning, so I had a go with it.

code here:

https://create.arduino.cc/editor/AlexRossMartin/4df2ef43-79ea-4623-bc70-588591704178/preview?embed

After editing the code to fix the target  temp at 90* and add some extra serial monitoring, we could run the code and get it to maintain the water to +-5*c.

However this is not good enough for maintaining a rolling boil and the code was far too complex to make any serious adjustments to. None the less I was able to spend some time getting to understand the majority of the functions in the code and dealing with such a long piece of code taught me a few lessons about good lay out and making code easy to understand.

I believe that the reason this code could not stabilise the temperature was due to the measuring system we were using, it was set up to measure the water temp directly using a ds18b20, which we also used. However our system also had an element which was not being measured, the hob plate itself, this was acting as a thermal capacitor, meaning the controller did not have direct control of the water temp, it had to go through the hob plate. Thus depending on the hob plate’s current temp the control system would have to apply a different amount of heat to get the same change in water temp.

Conclusion:

At this stage in the project, we realized that we would need to take account of both water temp and hob temp to successfully maintain a boil. I drew this diagram describing an ideal system of control.

IMG_20180417_233047[1].jpg

It describes a system of sequential PID controllers where the output of the first is used as the set point for the second.

Unfortunately…

It is too late in the project to attempt to resolve that level of detail. We went back to the drawing board…

to be continued…

2: Electric hob heat wastage device

Foreword:

Our new concept was a way to take advantage of the residual heat from electric hobs and use it our advantage. In order to do this we had to figure out a way to estimate the rate that it was cooling.

The maths:

In order to estimate cooling rate, I used this equation which describes exponential cooling.

IMG_20180416_212154

I converted that equation into code, which used the two sensors we had available to take readings.

https://create.arduino.cc/editor/AlexRossMartin/3739fec9-9a1d-482f-a8b3-9815bf4a4e94/preview?embed

The problems I had with the code early on were small teething problems, where i wrongly defined variables and tried to do calculations with different types.

I also didn’t know how to print time in hour.minute.second format, but was able to find an example online which I put in.

The circuit:

IMG_20180409_115021

Cooling rate calculator_bb

Here is the code in action, as you can see it calculated that the hob would take 2.30 to cool by 20%. This means that you could turn the hob off early and maintain enough temp to keep cooking, thereby reducing your energy consumption.

IMG_20180409_122023

IMG_20180409_173821

I think this demonstration has showed that there is potential in the idea, next up we will try to give some kind of control to the arduino so that it can maximise efficiency of the hob.

 

Alex & Chris

Week 3: Measuring energy usage of a hob

In order to quantify the effect of our project on electricity consumption, we needed to establish a base line.

Although the project would ideally be built in to a 4 ring home hob, this is not practical for prototyping, therefore we decided to use a small single ring electric hotplate for now. Since it has a mains plug that makes it extra easy to measure its consumption by using a plug in power monitor.

To establish a baseline I will boil water for 10 minutes from a cold start. To make the test repeatable, I will measure exactly 1 litre of water, use the same pan and begin the clock from the moment I turn it on. I will also measure the start temp of the water as well as the ambient air temperature.

IMG_20180416_181604

The experiment will be carried out as followed:

  • Ensure power meter is zeroed.
  • Fill pan with 1 litre of tap water.
  • Measure water temp.
  • Measure ambient temp.
  • Begin timer.
  • Turn hob to max setting.
  • When water is visually observed to be boiling, turn down to medium heat.
  • As soon as timer reaches 10 minutes unplug the hob.
  • Read values from power meter.

This should be a close representation of typical usage and give us an idea of the energy savings we can make.

The results are in! The 10 minute on time used 0.2 KWh. It only actually reached a boil after about 7 minutes, so was on constantly during that time.

 

Inside the hob we are using the switch looks like this:

IMG_20180411_163115

It is about the cheapest possible thermostatic switch, it uses to layers of metal (the spring like bit) when this is heated the different thermal expansion properties of the parts mean that it changes shape and causes the switch to open. the white plastic boss is moved inwards by the knob and applies varying amounts of pre-load to the spring and by this method the temperature can be adjusted.

 

This switch is very reliable but not super precise and doesn’t give the user any accurate control over the temperature.

We are anticipating that we should be able to improve both the efficiency and usability of the hob by controlling it electronically.

Further Experiments:

We also wanted to find out how well we could estimate whether or not water was boiling by monitoring its temperature in different locations.

 

Earn your Energy. A sustainable education concept.

Hello again,

For the second brief of this project we were instructed to produce an electronics project to affect a positive environmental impact.

Working in pairs, undertake a 5-week physical computing design or interaction design project. The aim of this project is to create a significant reduction in environmental impact either in the home or in a business setting. This will probably be either by using Arduino with sensors and actuators to directly reduce energy consumption, or to increase efficiency, or to effect a positive change in behaviour by using the Arduino to give feedback and “nudges” to users. Create a beautiful reliable working prototype of your design, test it and present this project in a mini exhibition in the Atrium and in a series of online blog posts. “

I was very excited about this brief, I’m particularly interested in sustainable design as a whole. However, the more we thought about it the more we struggled to come up with an idea which warranted the use of an Arduino without becoming super gimmicky.

The idea we eventually settled on was “Earn your Energy”, an education concept for children. The idea is a linked pair of plug adapters and pedometers which record the physical activity of the child wearers, this information is relayed to the plug adapter which only allows Tvs/Games Consoles/Pcs to be switched on once the children have completed a recommended amount of physical exercise.

This should have a double benefit, not only reducing the amount of electricity used by devices but also encouraging children to exercise more. Not only this but by a careful matching of the required exercise to the amount of time that devices can be switched on, children can be taught about the cost / difficulty of energy production.

IMG_20180312_115112

With this Idea in mind, we began researching the project. We needed to find out a number of things:

  • How to make a small pedometer
  • How to design communication between the pedometer and the plug adapter
  • How many steps do children need each day?
  • How many hours of electronic use are acceptable for a child?
  • How many steps would equate to enough energy to power a TV etc?

On the first front, I read this tutorial for making a pedometer and had a go:

Arduino Pedometer

The first problem I found was that the tutorial used an ADXL 3 axis accelerometer, whilst the one I had was an MPU-6050.

ADXL335

MPU-6050

I read this tutorial for using the MPU-6050, which requires downloading two additional libraries, I2Cdevlib and MPU6050.

After installing these libraries, the tutorial asks you to open a piece of example code, which has been created for using the DMP (digital motion processing) chip on the breakout board.

The code is https://create.arduino.cc/editor/AlexRossMartin/374b1cca-cab9-46b4-8e28-c4398f307178/preview?embed

Unfortunately I have repeatedly received errors when trying to execute the code, it seems to be getting stuck at the while loop whilst having printed “initia”

Sesh’o’meter – Using tilt sensor and humidity sensor to display messages based on movement and sweatiness

Introduction:

What can I do with my DHT11 temp and humidity sensor?

I have been looking online for projects involving this sensor, but all the projects I found revolved around using the sensor in automatic garden care devices

I wanted to do something different…

It dawned on me that I could use the sensor to monitor skin humidity…                            aka sweatiness. With this in mind, me and Chris thought about what we could do with this information and settled on trying to produce a funny piece of wearable tech.

Since Me and Chris are both fans of Dub, DnB and other bass heavy types of music, we thought it would be funny to make a device reacted to how hard the wearer was SKANKING.

Chris had selected a tilt sensor which we decided would work well with the DHT11.

Literature Review:

The basic premise of using the DHT sensor to measure skin humidity hasn’t been covered before but I had read generally about the sensor, as well as displaying it’s output on a LCD screen.

The Guide I read was:

http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/

I also used this for the LCD code.

On top of this, I read and re-read the reference section of the arduino website in order to familiarise myself with the programming language.

 

Hypothesis

Following my previous investigations using various displays with the DHT sensor, I felt it would be easy enough to use the LCD in the project. I expected the hardest part to be dealing with two completely seperate input variables and deciding how to use them.

The plan was to create a headband which could measure the movement of the wearer’s head as well the sweatiness. It would then display a funny message on an lcd on the front of the headband.

Experiments

My experiments were based around trying to integrate the two sensors into a cohesive circuit.

I had to find a proper minimum value for the humidity, since it would be next to someones skin. I tested it by holding it next to my skin and waiting for the value to stabilise.

The circuit I built was as follows:

Sesh'o'meter diagram_bb

28555404_1773841882634057_1007076480_o

 

After some successful test code, I went onto develop the code by adding IF ELSE statements and manipulating the input variables into a form that we could use.

This part was actually much easier than I had thought, I got the code working without any bugs pretty much straight away.

Here is a video showing the circuit in action:

*NB.   The reason the display goes blank at some points is that since the humidity sensor is not next to human skin, it’s value can go lower than the minimum I had set in the code.

 

The code I wrote can be found here:

https://create.arduino.cc/editor/AlexRossMartin/3147d8f0-1c25-4ba0-a7f4-53965995475f/preview?embed

 

Unfortunately, I ran out of time to make an enclosure for it, but will be working on one and will upload it to the blog soon!

 

 

Using tilt sensor to determine rate of movement.

Hello,

Welcome to another blog post about my arduino projects. This week, me and chris decided to investigate tilt sensors. The idea is that coupled with the DHT11 temperature and humidity sensor we can produce a device which can detect the wearer’s level of movement and excursion. We would use the DHT11 to detect the sweat levels of the user and the tilt sensor to detect their movement.

Chris has done a blog post about the general workings of the tilt sensor here.

So…

In order to use the tilt sensor to determine level of movement, I decided that if I could take an average of it’s position over a fixed time period, this could give me a rough idea, the closer the average was to 0.5, the better the level of the users movement. Obviously this is only a very rough estimation and can only really be described as detecting whether or not they passed to either side of an equilibrium point an equal number of times.

The sensor would have to be mounted on its side somewhere on the user’s head, such that it read HIGH when they leaned one way and LOW when they leaned the other.

My first go at writing the code for this was as follows:

https://create.arduino.cc/editor/AlexRossMartin/6181e318-0cd0-42b6-a3a9-62d337801bba/preview?embed

 

This sort of worked, it gave me an average value. However, the FOR statement cycled so fast that the value of the average could only be 0 or 1. This would not do.

Also, viewing through the serial monitor, the value was refreshing so fast that it was impossible to read.

I needed to make sure the sample rate of the tilt sensor was reasonable enough to give me a full range of averages. The idea here was to sample every 10 millisecs, to combat the display problem, I decided to print to serial monitor only every 5 seconds and to reset the average at the same time.

 

My next go at the code was this:

 

https://create.arduino.cc/editor/AlexRossMartin/4dfe05ef-4b3d-4c0c-b211-7fe6360db0b0/preview?embed

 

This was a much closer approximation to what I wanted, here’s what it displayed on the serial monitor:

ScreenShot tilt sensor time delay serial mon 01

The values displayed are:

average of the tilt switch

currentmillis (the count value for the sampling)

currentmillis2 (the time value for the display)

the total (at time of printing)

 

when shaken around violently, I hoped the average would be somewhere around 0.5 but it seemed to jump around from around 0.3 to 0.7 when i was shaking it at a constant rate.

I discovered a number of problems, which could be causing this:

even though I was refreshing the display every 5 seconds, sometimes the total was only sampling 49 times. I thought that this was causing the problem but, when I held the sensor so that there was a constant HIGH value it would still average to 1 or 0.98 which is close enough to be acceptable.

Next I tried holding it to give a constant low value, what I found was that it averaged to around 0.6 and the total (which should be 0) was around 32, which meant it was sampling HIGH over half the time.

Obviously something was up, some noise is clearly being generated causing it to read high 50% of the time.

After re-reading chris’ blog post I realised that I had forgotten to set the internal pull-up resistor. I added a line into the setup code to do just that and the average read as 1 or 0 correctly.

After evaluating the successive averages, I found that it was very difficult to get  it close to 0.5 as I needed. I experimented with different sample rates and found that sampling every 500 allowed me to get a reasonable range of averages including 0.5.

With this finished, It was time to build the circuit.

Sesh'o'meter diagram_bb

Once I am sure that the circuit and coding works, I will build the circuit on an arduino nano and replace the brightness potentiometer  with a resistor.

I then needed to test the circuit before trying to write the code to do what I wanted. I took the earlier code used for displaying ouput from the DHT on an LCD and combined it with the new code I had written for the tilt sensor.

Here’s the code:

https://create.arduino.cc/editor/AlexRossMartin/a137a128-1483-4580-915f-b384a2be3cae/preview?embed

Everything worked correctly!

Now I could try to write some code to add more functionality. My goal was to take the inputs from the two sensors and use them to generate a score which would flash up a corresponding message on the LCD screen.

I decided that the easiest way to use the two inputs was to make them comparable and take an average. To begin with the humidity had a range of 0-100 and the tilt sensor average had a range of 0-1 (where 0 and 1 were no movement and 0.5 was max).

First, I needed to adjust the range of the humidity, since although its range is 0 to 100, the actual minimum humidity of a human forehead would be way above 0. I tested this by placing the sensor against my own head, allowing it to stabilize and then taking this as the new minimum value, luckily this ended up being 49, which I rounded to 50, giving me a range of 50 to 100. I subtracted 50 from this to give a range of 0 to 50.

Next I addressed the tilt sensor average by subtracting 0.5, giving it a range of -0.5 to 0.5. Then I took the absolute value, giving a range of 0 to 0.5, with a max of 0.5. I then noticed that I could save myself some work by changing this line:

average = total / 10;

to this:

average = total * 10;

This meant that the range for tilt sensor average was now 0 – 50.

With both having the same range I took a mean average and called this the Party Value (PV). I then produced a series of IF ELSE statements for various PV values and corresponding  funny messages for the display.

Here’s the code I used:

https://create.arduino.cc/editor/AlexRossMartin/3147d8f0-1c25-4ba0-a7f4-53965995475f/preview?embed

 

DHT11 temperature and humidity sensor

This is a DHT11 temperature and humidity sensor.

Function:

To detect the ambient air temperature and relative humidity. It is mainly used in automated gardens to ensure that the conditions are right for the plant.

Range:

°Humidity 20%-90% RH (Relative Humidity)

°Humidity accuracy +-5% RH

°Temp range 0-50°C

°Temp accuracy +-2%°C

How does it work:

Humidity is measured by checking the resistance between two electrodes, these electrodes are placed on a water absorbing material. As the material absorbes more water, it releases electrons which make it easier for current to flow between the electrodes, this gives a lower resistance value which can be interpreted as a greater humidity.

The temperature is measured by a NTC thermistor, meaning the resistance decreases as temperature increases. The thermistor is made from a temperature sensitive semi-conductor, as the temperature increases the semi-conductor releases electrons which allow current to pass more easily.

Circuit:

Connecting the sensor is very simple it requires a 5v supply, ground and a signal wire.

It outputs a digital signal, which should be pulled-up by a 10k ohm resistor, this is usually built into the PCB.

The output can be any of the digital pins and must be set as an input in the IDE.

Code:

Before using the DHT11, you must import the DHTlib library.