Pages: 1 [2] 3   Go Down
Author Topic: garage door opener  (Read 2323 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley thanks for the help everyone.

Code:
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;
    }
  }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Faraday Member
**
Karma: 30
Posts: 2507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you changed it for a digital one? huh?


can we get a circuit picture? cheers - and any updated code smiley
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here are som pics and the new code:

Code:
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;
    }
  }
}
 

* attachments.zip (565.68 KB - downloaded 14 times.)
Logged

Offline Offline
Faraday Member
**
Karma: 30
Posts: 2507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

still looking/reading.
Logged

Offline Offline
Faraday Member
**
Karma: 30
Posts: 2507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok and what's it not doing properly?

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okey dokey we have liftoff! The apparatus works just right.  I added to the code some so here is the working code.
Code:
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!
Logged

Offline Offline
Faraday Member
**
Karma: 30
Posts: 2507
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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....
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 129
Posts: 8606
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

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
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 :)
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 644
Posts: 50524
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Any help on making it read full strings still wanted smiley
char arrays (NULL terminated) and strcmp() come to mind.
Logged

Pages: 1 [2] 3   Go Up
Jump to: