SMART BLINDS 11: functioning logic & User Modes.

In this blog we will be going through our code so far, and explaining the choices and variables that will affect the output of the code.


1 x Arduino Uno

1 x l298n stepper motor driver

1 x  Stepper motor (17HD34008-22B)

1 x 9V battery

1 x LCD

1 x PIR sensor

2 x Momentary buttons

2 x Thermisters

1 x LDR

1 x Variable Resistor

Jumper cables.



Real World:



Above is the Variables and Initialisation for our Libraries.

  • “OneWire” is responsible for data readings from our Temp sensors. Using OneWire also allows us to run 2 Temp sensors off of the same pin on the Arduino.
  • “DallasTemperature” allows for the conversion of raw data from the Temp Sensors, and outputs in degrees C or F.
  • “LiquidCrystal” Runs our 2 x 16 LCD display.


  • Next we start to assign values to our Temp sensor pin A5. Then pas the OneWire values to DallasTemperature for conversion so it knows where to look.
  • We assign DeviceAdresses to each of the Temp sensors, each has its own unique interal callsign. We found these by writing a program stated in an earlier blog.
  • Next is to tell our arduino which pins to output for the LCD display.
  • Finally we get to the integers, floats and boolean variables that make our logic run. The most imprtant is probably “BlindOpen” this is the boolean that will tell the arduino whether or not the blinds are open / clossed.


Below is the Setup:

Here we assign the resolution of our temp sensors to 10 bit. We begin our LCD, print our messages to the LCD. And finally define our button interupts to pins 2 & 3. (The only 2 pins on the arduino that can run the interrupt function).setup.jpg


This is the most important part of the code. We have used many different functions (which i will go through in a second) and simply call on them when needed. This way of doing it can save valuable memory space as you don’t have to re-write the same code every time you want to use it. LOOP

Getting Rid of Delay:
There used to be a delay in the loop that would refresh the temps every 6000 millis, however we got rid of this as it hung up the code and made the inputs buggy. Instead we measure time past with current time and if it is over 6000 milliseconds then it will refresh the temps. This frees up the code to do other things and allows multi-tasking.

  • It is worth noting that there are 2 discrete “Modes” functioning in this Code. The first of which is:

Savings Mode: This is the simplest of the 2 modes and allows the decisions that will result in the most energy savings for your house. However it does not take into account whether or not the user is in the Room or if it is Night or day. This mode would be useful if you knew you were going to be out all day. or perhaps went on holiday.Savignsmode

Smart Mode: This mode takes into account 5 different variables in order to make an informed guess as to whether or not the blinds should be open or closed. We measure Inside, Outside and the user desired Temperatures. Then cross reference that with if the user is in the room and if the time of day is say or night. WE feel that this gives us enough information to get the blinds to be fully automated.Smart mode



Next we have our interrupt code. The top on cycles through the mods and the other adjusts the user temp. This allows of full functionality of the arduino without a connected PC. We were going to use a Keypad but it started outputting characters not in the english language and even when we weren’t touching the pad!! so we opted to simplify the input methods. Also this allowed us to free up 12% of the arduino memory, which is important as we would have run out otherwise.


Below is the code that determins if the arduino needs to be set up. If Setup has not been run before the arduino will ask the user which mode they want to be in. else it will output the mode it is currently set to in the serial monitor.


Next up we have the USP of our blinds. We measure if the user is in the room or not and then what time of day it is. This allows us to keep the user privacy at night and let in light during the day, but ONLY when there is a user in the room, otherwise it will do whats best for the energy savings.PIRNIGHTDAY

Below we have the code that outputs the Temperatures to the LCD screen, this is important as it allows the user to monitor what is going on with temps and then make an informed decision based on that. Also we have ‘AssignTemp’ here we take the readigns from the tempreature sensors and assign them to variable integers. This allows us to compare them and output decisions. without this code we could not do this as the temp sensors output in weird ways. Next is ‘SetTemp’ this allows the user to input the tempreature they want the room to be. we use the serial monitor for this. If the user inputs nothing this function will not let the arduino do anything until there is a value assigned to this variable.LCDprint ASSIGNTEMP Settemp

Last but not least we have the functions that actually measure and write the temperatures from the sensors. We included an error message when the sensor reads -127 degrees C as this normally means that the wires are not plugged in correct. ‘Call temp’ uses simple comands to output the Temps to the Serial monitor.

Serial monitor:

Here i put my hand on the inside temp sensor to simulate a warm house and in the 2nd set of temps i put my hand over the LDR to simulate night. You can see the outputs change dependent on the variables.


Video Demonstration:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s