I order to create the hovercraft we must have a way to turn on the fan that will blow air into the supporting skirt of the hovercraft. We wanted to see if we could turn on the motor using an IR Receiver and a remote. After many changes to the code we final accomplished the task.
Here is a Picture of the Setup Board:
Here is a Video of the Motor and IR Receiver in Action:
Here is a sample of the code:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv | |
* An IR detector/demodulator must be connected to the input RECV_PIN. | |
* Version 0.1 July, 2009 | |
* Copyright 2009 Ken Shirriff | |
* http://arcfn.com | |
*/ | |
#include <IRremote.h> | |
int RECV_PIN = 12; | |
int LED = 13; | |
const int motorPin=6; | |
IRrecv irrecv(RECV_PIN); | |
decode_results results; | |
void setup() | |
{ | |
Serial.begin(9600); | |
irrecv.enableIRIn(); // Start the receiver | |
pinMode(LED, OUTPUT); | |
pinMode(motorPin, OUTPUT); | |
} | |
void loop() | |
{ | |
if (irrecv.decode(&results)) { | |
Serial.println(results.value); | |
irrecv.resume(); // Receive the next value | |
if (results.value == 3843267751 || results.value == 2891014758 || results.value ==4294967295) | |
{ | |
digitalWrite(motorPin, HIGH); | |
digitalWrite(LED, HIGH); | |
delay(100); | |
} | |
if (results.value == 2907792379 || results.value == 3826490130) | |
{ | |
digitalWrite(motorPin, LOW); | |
digitalWrite(LED, LOW); | |
delay(100); | |
} | |
} | |
} |
No comments:
Post a Comment