Go Down

Topic: garage door opener (Read 2530 times) previous topic - next topic

Code is as pasted below.  It works as it should with the serial monitor.  I am planning to test this now, but if you see a problem let me know :) thanks for the help everyone.

Code: [Select]
int door = 0;
int light = 10;
char go = 'go';
boolean doorUp = false;


void setup()
{
  Serial.begin(9600);
 
  Serial.println("Initializing Garage Opener v1.0");
 
  pinMode(door, OUTPUT);
 
  pinMode(light, OUTPUT);
 
  digitalWrite(light, HIGH);
  delay(500);
  digitalWrite(light, LOW);
 
  Serial.println("Ready to send signal");
  Serial.println("Enter a command to continue");
}

void loop()
{
  char input = Serial.read();
 
  if(input == go)
  {
    Serial.println("Sending signal...");
    digitalWrite(light, HIGH);
    analogWrite(door, 1023);
    delay(200);
    analogWrite(door, 0);
    delay(15000);
   
    if(doorUp == false)
    {
      Serial.println("Door successfully raised");
      doorUp = true;
      return;
    }
    else if (doorUp == true)
    {
      Serial.println("Door successfully closed");
      doorUp = false;
      return;
    }
  }
}

I added the code to make the light go off and also changed the transistor to digital.  it doesn't work...... anyone know why?

cjdelphi

you changed it for a digital one? huh?


can we get a circuit picture? cheers - and any updated code :)

Here are som pics and the new code:

Code: [Select]
int door = 3;
int light = 10;
char go = 'go';
boolean doorUp = false;


void setup()
{
  Serial.begin(9600);
 
  Serial.println("Initializing Garage Opener v1.0");
 
  pinMode(door, OUTPUT);
 
  pinMode(light, OUTPUT);
 
  digitalWrite(light, HIGH);
  delay(500);
  digitalWrite(light, LOW);
 
  Serial.println("Ready to send signal");
  Serial.println("Enter a command to continue");
}

void loop()
{
  char input = Serial.read();
 
  if(input == go)
  {
    Serial.println("Sending signal...");
    digitalWrite(light, HIGH);
    digitalWrite(door, 1023);
    delay(200);
    digitalWrite(door, 0);
    delay(15000);
    digitalWrite(light, LOW);
   
    if(doorUp == false)
    {
      Serial.println("Door successfully raised");
      doorUp = true;
      return;
    }
    else if (doorUp == true)
    {
      Serial.println("Door successfully closed");
      doorUp = false;
      return;
    }
  }
}
 

cjdelphi

the + connection from the remote control is not needed unless you're somehow powering the device?

still looking/reading.

cjdelphi

ok and what's it not doing properly?


Your go declaration for a char is two characters a char is only one char, I'm surpised it compiled with
Code: [Select]
char go = 'go';  Also try changing the
Code: [Select]
digitalWrite(door, 1023);   to
Code: [Select]
digitalWrite(door, HIGH);

PaulS

Quote
Your go declaration for a char is two characters a char is only one char, I'm surpised it compiled with

It's syntactically valid, since some computers support multibyte characters. It's useless on the Arduino which doesn't.

Nothing read from the serial port will ever match that definition of go. No single character read from the serial port will ever match go, even if go is correctly defined as an array, and correctly initialized using double quotes.

The code does work properly, though if there is a better way to accomplish my goal of waiting for a specific message from the user (something like serialEvent) then I'm open to learning to use that.

Like I said the code works, and I think the problem is in the transistor part of the wiring.  If someone knows how to make it work that would be great.

Currently everything works as normal, but the door does not raise.

Just noticed that I forgot to change the
Code: [Select]
analogWrite(door, 1023) to
Code: [Select]
digitalWrite(door, HIGH); and only changed it to
Code: [Select]
digitalWrite(door, 1023);  I will try again soon and let you know :)

Okey dokey we have liftoff! The apparatus works just right.  I added to the code some so here is the working code.
Code: [Select]
int door = 3;
int light = 10;
char go = 'go';
boolean doorUp = false;


void setup()
{
  Serial.begin(9600);
 
  Serial.println("Initializing Garage Opener v1.0");
 
  pinMode(door, OUTPUT);
 
  pinMode(light, OUTPUT);
 
  digitalWrite(light, HIGH);
  delay(500);
  digitalWrite(light, LOW);
 
  Serial.println("Ready to send signal");
  Serial.println("Enter a command to continue");
}

void loop()
{
  char input = Serial.read();
 
  if(input == go)
  {
    Serial.println("Sending signal...");
    digitalWrite(light, HIGH);
    digitalWrite(door, HIGH);
    delay(200);
    digitalWrite(door, LOW);
    delay(1500);
    Serial.println("Progress 10%");
    delay(1500);
    Serial.println("Progress 20%");
    delay(1500);
    Serial.println("Progress 30%");
    delay(1500);
    Serial.println("Progress 40%");
    delay(1500);
    Serial.println("Progress 50%");
    delay(1500);
    Serial.println("Progress 60%");
    delay(1500);
    Serial.println("Progress 70%");
    delay(1500);
    Serial.println("Progress 80%");
    delay(1500);
    Serial.println("Progress 90%");
    delay(1500);
    Serial.println("Progress 100%");
    digitalWrite(light, LOW);
    Serial.println("Success!");
  }
}
 

Thanks for all the help guys I couldn't have done it without your help!

cjdelphi

Meahwhile while you wait for your 5v 1amp relay $3.99......


The Transistor has many uses and it's a real shame to see something that could be done in a few cents become a few dollars....

Graynomad

But he is using a transistor ?? Or are you saying that it's already working but if he used a relay he'd still be waiting :)

Fair comment given that he didn't have the relays to hand. As for the many uses and cents becoming dollars, relays have a lot of uses as well, try switching 240v with that transistor, and for a one-off who cares about an extra $ or two?

@arduinocreativity
You still have that 'go' character constant. As has been noted it probably isn't doing any harm and I guess it's working but why have it?

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

Actually I may still get a relay at some point, but I had a transistor on hand, and so I was glad to be able to use that and get the project done more quickly.

As far as the char problem goes, I found that the program is reading only the last char in the string, and I had a problem when I used both "go" and "info" commands.  As a temporary fix, I'm using single letter commands.  Any help on making it read full strings still wanted :)

PaulS

Quote
Any help on making it read full strings still wanted :)

char arrays (NULL terminated) and strcmp() come to mind.

Go Up