Hello, I've just started with arduino a couple of weeks ago and got stuck trying to write the code for a automatic bed.
The reason we want it on a remote is cause the person using the bed has a bad back and the cored controller falls on the flour constantly, this making his problem even worse trying to pick it up >:(
we want replicate the 6 functions that or on the currant controller, this being;
head up/head down
feet up /feet down
both up /both down
the way the electronics work is with 4 relays and 2 motors.
each motor has a up and a down relay.
The part i'm stuck at in particular is that i can't get the motor to run as long as im holding down the button on the remote and stopping the moment i release the button.
Here is where im at in the sketch, this is going from a pushbutton to remote control (but got stuck on the first on)(did not put both up/both down in the sketch yet)
#include <IRremote.h>
int RECV_PIN = 3;//The definition of the infrared receiver pin 5
IRrecv irrecv(RECV_PIN);
decode_results results;
define HEADUPIOPIN 13
define FEETUPIOPIN 12
define HEADDOWNIOPIN 11
define FEETDOWNIOPIN 10
int headUp = HEADUPIOPIN;
int feetUp = FEETUPIOPIN;
int headDown = HEADDOWNIOPIN;
int feetDown = FEETDOWNIOPIN;
const int headUpBtn = 4;
const int feetUpBtn = 5;
const int headDownBtn = 6;
const int feetDownBtn = 7;
int buttonState = 0;
int buttonState2 = 0;
void setup() {
pinMode(headUp, OUTPUT);
pinMode(feetUp, OUTPUT);
pinMode(headDown, OUTPUT);
pinMode(feetDown, OUTPUT);
pinMode(headUpBtn, INPUT);
pinMode(feetUpBtn, INPUT);
pinMode(headDownBtn, INPUT);
pinMode(feetDownBtn, INPUT);
irrecv.enableIRIn();
}
void loop() {
if (irrecv.decode(&results)) {
if (results.value == 0xC101E57B) //0
{
digitalWrite(headUp, LOW); //drive the relay is closed off
}
if (results.value == 0x9716BE3F) //1
{
digitalWrite(headUp, HIGH); //drive relay closure conduction
}
irrecv.resume(); // Receiving the next value
}
buttonState = digitalRead(feetUpBtn);
if (buttonState == HIGH)
{
digitalWrite(feetUp, LOW);
}
else
{
digitalWrite(feetUp, HIGH);
}
buttonState = digitalRead(headDownBtn);
if (buttonState == HIGH)
{
digitalWrite(headDown, LOW);
}
else
{
digitalWrite(headDown, HIGH);
}
buttonState = digitalRead(feetDownBtn);
if (buttonState == HIGH)
{
digitalWrite(feetDown, LOW);
}
else
{
digitalWrite(feetDown, HIGH);
}
}