i wonder if you need an external power source? i know its only a relay, but i cant find the required current for the relay to make it switch.. maybe worth looking atPower from USB:
Simply plug USB cable, and the Romeo is able to work. Please notice that the
USB can only supply 500 mA current. It should be able to meet the most
requirements for LED lit application. However it is not enough to power DC
motors or servo.
int relayPin = 10;
void setup()
{
pinMode(relayPin, OUTPUT); // Set Pin10 to output mode
}
digitalWrite(relayPin, HIGH);
/*
The circuit:
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
analog 4: ground
analog 5: vcc
*/
// these constants describe the pins. They won't change:
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
const int relaypin = 13; // Output for the relay
void setup() {
// initialize the LED pin as an output:
pinMode(relaypin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(xpin, INPUT);
pinMode(ypin, INPUT);
pinMode(zpin, INPUT);
}
void loop()
{
if(analogRead(xpin)>1000001010)
{ digitalWrite(relaypin, HIGH); }
else if(analogRead(xpin)<0111110110)
{ digitalWrite(relaypin, HIGH); }
else{digitalWrite(relaypin, LOW);}
if(analogRead(ypin)>1000001010)
{ digitalWrite(relaypin, HIGH); }
else if(analogRead(ypin)<0111110110)
{ digitalWrite(relaypin, HIGH); }
else{digitalWrite(relaypin, LOW);}
if (analogRead(zpin)>1000001010)
{ digitalWrite(relaypin, HIGH); }
else if(analogRead(zpin)<0111110110)
{ digitalWrite(relaypin, HIGH); }
else{digitalWrite(relaypin, LOW);}
// delay before next reading:
delay(100);
}
You need to add prefix "B" to all of your binary numbers to tell the compiler that they are binary radix.Helllo Chrisw1990 so i tried replacing the output with an led instead of the relay and found something interesting. The led always is on and never turns off. Last night I adjusted my high and low limit so they were only 10 over the middle point, but no matter what I do the led wont turn off. Here is an updated version of my code:
Rich (BB code):/* The circuit: analog 0: accelerometer self test analog 1: z-axis analog 2: y-axis analog 3: x-axis analog 4: ground analog 5: vcc */ // these constants describe the pins. They won't change: const int groundpin = 18; // analog input pin 4 -- ground const int powerpin = 19; // analog input pin 5 -- voltage const int xpin = A3; // x-axis of the accelerometer const int ypin = A2; // y-axis const int zpin = A1; // z-axis (only on 3-axis models) const int relaypin = 13; // Output for the relay void setup() { // initialize the LED pin as an output: pinMode(relaypin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(xpin, INPUT); pinMode(ypin, INPUT); pinMode(zpin, INPUT); } void loop() { if(analogRead(xpin)>0B1000001010) { digitalWrite(relaypin, HIGH); } else if(analogRead(xpin)<0B0111110110) { digitalWrite(relaypin, HIGH); } else{digitalWrite(relaypin, LOW);} if(analogRead(ypin)>0B1000001010) { digitalWrite(relaypin, HIGH); } else if(analogRead(ypin)<0B0111110110) { digitalWrite(relaypin, HIGH); } else{digitalWrite(relaypin, LOW);} if (analogRead(zpin)>0B1000001010) { digitalWrite(relaypin, HIGH); } else if(analogRead(zpin)<0B0111110110) { digitalWrite(relaypin, HIGH); } else{digitalWrite(relaypin, LOW);} // delay before next reading: delay(100); }