Hi there,
My goal:
I'm using my Uno with a infrared sensor & remote to control a solenoid valve & a servo. I'm making a vinegar & baking soda powered car for a family competition (weird I know). Anyway, the servo releases the baking soda & I'll open the solenoid when the PSI in the bottle gets to a level. The PSI gauge is a manual/visual thing that I'm not going to code or anything fancy.
Where I'm at:
It all works and I'm pretty happy with my little project. There is one annoying problem that I think is down to my terrible copy/paste job with Arduino code.
Problem:
The servo ticks & hums all the time, which isn't really a problem, except that it seems to scramble my IR codes from the remote. I get all sorts of weird numbers from the remote which makes it hard to operate the solenoid. It eventually gets the correct signal and opens the solenoid. If I pull the digital pin from the servo, it stops ticking and the signal become stable again.
Help:
Would someone be able to look at my code and see what might be the problem. Any help or code adjustment I might try would be greatly appreciated.
Materials:
Uno
HXT900 Servo
12v Solenoid
#include <Servo.h>
#include <IRremote.h>
unsigned long Value1 = 0xD3F; // where XXXXXXXX is another button on your remote
unsigned long Value2 = 0x47F; // where XXXXXXXX is on our your remote's values. We will call this Value 1
unsigned long Value3 = 0xE13DDA28; // where XXXXXXXX is another button on your remote
unsigned long Value4 = 0xAD586662; // where XXXXXXXX is another button on your remote
int RECV_PIN = 3;
int solPin = 5;
IRrecv irrecv(RECV_PIN);
decode_results results;
Servo servo1;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(solPin, OUTPUT);
servo1.attach(13); // attach servo to digital pin 9
}
// the loop routine runs over and over again forever:
void loop() {
if(results.value == Value3) {
unsigned int value = results.value;
digitalWrite(solPin, HIGH);
delay(100);
}
if(results.value == Value4) {
unsigned int value = results.value;
digitalWrite(solPin, LOW);
delay(100);
}
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
if(results.value == Value1) {
servo1.write(176);
}
if(results.value == Value2) {
servo1.write(3);
}
}