3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Mushroom Environment Control - Arduino Powered

Step 7The Code

The Code
This was the first time I have coded in C in a long time (and my first real Arduino project). I am sure that there are many changes that could be made to streamline it, but it does the job and what's required of the Arduino board isn't really that intensive for this project.
...please note the original lcd4bit library has a lot of unnecessary delays in it which slows the code down A LOT, these should be removed (look in the cpp library file for clues). 

In brief the code (in order of how it appears in the attached code) does:
PRE-MAIN LOOP
- #defines M and C values for the linear and log equations required to translate the bit values for the inputs. i.e. y=mx+c and y= Mlog(x)+C
-#defines sizes for averaging array, sampling times, histerisis levels, Pins, EEProm storage size.
-defines variables, trigger values etc.
MAIN LOOP
-Read in sensor values every "SENSOR_INTERVAL" milliseconds.
-Puts the new values in an array and averages this array.
-Performs calculations on the averages to give a 'proper' value i.e. centigrade (apologies to my american cousins but I am metric), ppm (co2), Relative Humidity.
-Prints updates of new temp, humidity and Co2 levels to LCD shield.
-Stores values to eeprom every "EE_PROM_INTERVAL" milliseconds.
-Trigger relays if bellow/above trigger, every "INTERVAL" milliseconds.
-Keypad code that implements a rudimentary menu system allowing triggering values to be changed and EEPROM values to be dumped to serial.
-Funtions to help with averaging and key selection.

I have tried to give an explanation within the code as to what each section does, by all means go in and take a look. If you are more inclined to shy away from reading the code, please note the main things to note are the #define statements for manipulating intervals for reading,triggering and averaging and the #define statements for calibrating M and C values.
These are all situated at the top of the code so take a look and have fun fiddling.

Please note that the code uses the EEprom library for reading writing eeprom values, the lcd4bit library (modified, delays are removed and the pinouts changed) for the lcd shield, and stdlib for converting int into char for writing to the LCD display.







« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
12
Followers
1
Author:anthony_p1234
I pass the time by involving myself in small projects and watching youtube political discussions. I am a jack of all trades and master of none, and am good up until I have to house a project in a box,...
more »