Step 9: Arduino Code

// Pins
int dir = 2;
int power = 3;
int captor = 4;

// Reed switch
int captorVal = 0;

// Analog pin to read screen DOWN
int screenDown = 0;
int screenDownVal = 0;

// Analog pin to read screen UP
int screenUp = 1;
int screenUpVal = 0;

String screenState; // Projector screen state
String blindState; // Blind state
boolean busy = false;

void setup() {

  // initialize pins
  pinMode(power, OUTPUT);  
  pinMode(dir, OUTPUT);
  pinMode(captor, INPUT);

  // Read reed switch value at setup
  captorVal = digitalRead(captor);

  // Set the blindState on setup
  if ( captorVal == LOW ) {
    blindState = "up";
  } else {
    blindState = "down";

  // Logger

void loop() {

  // Read projector screen values
  screenDownVal = analogRead(screenDown);
  screenUpVal = analogRead(screenUp);

  if ( screenUpVal > 1000 && screenDownVal > 1000 ) {
      Serial.println("Screen module is OFF !");
      screenState = "off";
  } else if ( screenUpVal < 200 && screenDownVal < 200 ) {
      screenState = "stop";
  } else if ( screenUpVal > 1000 && screenDownVal < 200 ) {
      screenState = "up";
  } else if ( screenDownVal > 1000 && screenUpVal < 200 ) {
      screenState = "down";



void refreshBlindMotor() {


  // Screen is going UP and blind is DOWN ( and blind is not busy )
  if ( screenState == "up" && blindState == "down" && busy == false) {
    // UP the blind !
    busy = true;
  // Screen is going DOWN and blind is UP ( and blind is not busy )
  } else if ( screenState == "down" && blindState == "up" && busy == false ) {
    // DOWN the blind !
    busy = true;
  } else if ( screenState == "stop" ) {
    // TODO : stop the blind ?


void blindUp() {

  // Motor ON + UP
  digitalWrite(power, HIGH);
  digitalWrite(dir, HIGH);

  // While reed switch not engaged
  captorVal = digitalRead(captor);
  while (captorVal == HIGH) {
    captorVal = digitalRead(captor);
    Serial.println("Waiting for the blind to reach the far UP position...");

  // We got out of the while loop,
  // We can stop the blind
  blindState = "up";
  busy = false;

  Serial.println("Blind is UP !");


void blindDown() {

  // Motor ON + DOWN
  digitalWrite(power, HIGH);
  digitalWrite(dir, LOW);

  // Time is takes for the blind to go DOWN

  // Stop the blind
  blindState = "down";
  busy = false;

  Serial.println("Blind is DOWN !");


void halt() {

  // Cut power to blind motor
  digitalWrite(power, LOW);

  Serial.println("Blind is STOPPED !");

Well done ! If you are a girl, I am impressed that you got to accomplish all this by yourself. I know many guys -self proclaimed geeks- who would never dare to do what you did !
Thanks for the comment ! <br>I'm Sorry (or not) i'm not a girl, the pics of my gf in the Valentine day's project may have fooled you ! <br>Side note, I never meet a girl who is not from the internet and does electronics ...
I'm still impressed as I haven't gotten started on Arduino myself! <br><br>I have done a few projects with MicroChip's PIC 8 bit conttrollers and your project sparked a few ideas in my head. I've noticed that most people here do stuff on Arduino and such articles are the ones with more views.<br><br>Thanks and keep up the good work.<br>
Very nice, and the most important thing in any project, it works. <br>It might have been easier to have the screen relays turn on relays for the blinds for driving the blinds up and down. Then use switches that measure the thickness of the material on the blind to act as end switches. Or, since you are using Arduino, to count the revolutions of the blind core. <br>Can you show us the installation of the motor in the blinds? Or brand of blind if the motor is factory installed?
The motor is a RC servo modified for continuous rotation, i removed the right original mount from the blind and installed the servo straight to the blind using screws / glue. <br>I shall take a picture of the motor setup if you want, but it is rather hacky :D
So that's why you must have the Arduino. To act as servo signal generator. <br>Have you thought about attaching infrared receiver to the Arduino to get it to read the signal from the screen remote? If you get one of those ultra-small and cheap Arduino clones you could have everything in very small package with very little wiring.
Yes i plan to embed a microcontroller so i can remove the need of my arduino in the project, and throw everything in a little box i can hide. <br> <br>I didn't tough about infrared receiver, that is a good idea, but i wanted to control the whole thing with the RF remote of the screen.
Very nice instructable. I hope you will follow up with the code, I want to use this to operate the gate for my animals. Thanks.
Thank you very much ! I added the code, i took the time to rename some variables and add comments to it, hope it will be useful to you !

About This Instructable


29 favorites


More by Chipsy: Instamorph heart necklace Automatic blind hooked up to existing projector screen
Add instructable to: