Can I safely use this relay with the arduino?

Hello World! :slightly_smiling_face:

About a week ago, my buddy asked me to make him some kind of PLUG&PLAY safety "Overspeed Governor" kind of circuitry, for his elevator (he runs an elevator business). This elevator is not meant to be used for humans, just to lift heavy machinery, however he just wanted to add some additional safety features.

His idea was for me to make like a little plug & play box, that works like a relay switch, but it lets 12v through only if the Z acceleration exceeds a certain treshold. Lets say 1000. Then they would take this 12v SIGNAL output, to activate the breaks.

We have a + 12V input (which supplies the arduino, through the buck converter, and also supplies the SIGNAL, when run through the relay), from their PSU, a GND, again from their PSU, and the previously mentioned SIGNAL output.

List of my components:

  • GY-521 + MPU6050 (gyro and accelerometer - i know it's a bit overkill)

  • RELC-1CH-5V-UNI Relay Board

  • Arduino Nano (A4,A5 are the SCL and SDL pins for i2c)

  • DSN-1504-3A Buck regulator

  • 0,75 mm copper speaker wires (rated 6 amps max)

The arduino's Micro USB connection will stay exposed, so they can update the new code, when they want to calibrate the treshold value, at which the elevator is considered to be free falling.



#include "Wire.h" // This library allows you to communicate with I2C devices.

const int MPU_ADDR = 0x68; // I2C address of the MPU-6050. If AD0 pin is set to HIGH, the I2C address will be 0x69.

int16_t accelerometer_x, accelerometer_y, accelerometer_z; // variables for accelerometer raw data
int16_t gyro_x, gyro_y, gyro_z; // variables for gyro raw data
int16_t temperature; // variables for temperature data

bool panicMode = false;
int speed_treshold = 1000;

char tmp_str[7]; // temporary variable used in convert function

char* convert_int16_to_str(int16_t i) { // converts int16 to string. Moreover, resulting strings will have the same length in the debug monitor.
  sprintf(tmp_str, "%6d", i);
  return tmp_str;
}

void setup() {
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(MPU_ADDR); // Begins a transmission to the I2C slave (GY-521 board)
  Wire.write(0x6B); // PWR_MGMT_1 register
  Wire.write(0); // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);

 // Setting up Relay pin
  pinMode(2, OUTPUT);
}
void loop() {
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) [MPU-6000 and MPU-6050 Register Map and Descriptions Revision 4.2, p.40]
  Wire.endTransmission(false); // the parameter indicates that the Arduino will send a restart. As a result, the connection is kept active.
  Wire.requestFrom(MPU_ADDR, 7*2, true); // request a total of 7*2=14 registers
  
  // "Wire.read()<<8 | Wire.read();" means two registers are read and stored in the same variable
  accelerometer_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x3B (ACCEL_XOUT_H) and 0x3C (ACCEL_XOUT_L)
  accelerometer_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x3D (ACCEL_YOUT_H) and 0x3E (ACCEL_YOUT_L)
  accelerometer_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x3F (ACCEL_ZOUT_H) and 0x40 (ACCEL_ZOUT_L)
  temperature = Wire.read()<<8 | Wire.read(); // reading registers: 0x41 (TEMP_OUT_H) and 0x42 (TEMP_OUT_L)
  gyro_x = Wire.read()<<8 | Wire.read(); // reading registers: 0x43 (GYRO_XOUT_H) and 0x44 (GYRO_XOUT_L)
  gyro_y = Wire.read()<<8 | Wire.read(); // reading registers: 0x45 (GYRO_YOUT_H) and 0x46 (GYRO_YOUT_L)
  gyro_z = Wire.read()<<8 | Wire.read(); // reading registers: 0x47 (GYRO_ZOUT_H) and 0x48 (GYRO_ZOUT_L)
  
  // print out data
  Serial.print("aX = "); Serial.print(convert_int16_to_str(accelerometer_x));
  Serial.print(" | aY = "); Serial.print(convert_int16_to_str(accelerometer_y));
  Serial.print(" | aZ = "); Serial.print(convert_int16_to_str(accelerometer_z));
  // the following equation was taken from the documentation [MPU-6000/MPU-6050 Register Map and Description, p.30]
  Serial.print(" | tmp = "); Serial.print(temperature/340.00+36.53);
  Serial.print(" | gX = "); Serial.print(convert_int16_to_str(gyro_x));
  Serial.print(" | gY = "); Serial.print(convert_int16_to_str(gyro_y));
  Serial.print(" | gZ = "); Serial.print(convert_int16_to_str(gyro_z));
  Serial.println();
  
  // delay
  delay(100);

 // check acceleration
if(panicMode == false){
    if (accelerometer_z >= speed_treshold){
        digital_write(2, HIGH);
        panicMode = true;
        Serial.println("PANIC MODE HAS BEEN ACTIVATED!");
        Serial.println("RESET DEVICE TO DEACTIVATE!");
    }
}
}

What my question is, would this configuration work for his needs, will it last, or is there something i should consider changing about my circuitry or code?

Thank you in advance!

Edit 1: Added links to components' datasheets!

this relay module has optoisolator, so it is no danger to connect direct to arduino

1 Like

Every different load will produce a DIFFERENT gravity acceleration because of it's different mass. I doubt you can calibrate for each type of load.

Seriously? Acceleration due to gravity is the same regardless of mass.

However, there is a contradiction @R3UNITE will have to address:

If it is free falling then there will be no acceleration within the lift, that's kind of what free fall means. You need to look for zero acceleration (or below some value), not above some value.

This is me in freefall

2 Likes

Damn, didn't think of that! So I should first determine wheter the lift should be moving or not, and if it SHOULD, then i should measure if the acceleration is close to OR absolute zero, and if it is, the elevator is in freefall, right?

Edit:
Must've been a nice experience! :smiley:

I don't think it matters if it's moving or not. If you measure the acceleration in the lift while it is stationary it will be 9.8m/s^2. When it's going up it will be more, down less, falling less still. I doubt it will ever be zero because of air resistance and other friction.

Based on that, i should make the treshold in the other direction. So like -1000 for eg. ?

Nope. What we call gravity is a function of mass, anywhere we have found in the universe. Earth's gravity is not the same all over the globe because the mass is not the same in every part.
A plumb bob on a long string hung from a very tall building will be closer to the building at the bottom than the top because of the mass of the building.
The acceleration of the earth gravity will have the gravity of the machinery added to it.

When discussing the acceleration due to gravity on a large body, such as the earth, and the strength of that acceleration on relatively small masses, such as humans or trains or even ships, or lift cars, then the mass of the large body, earth, is overwhelmingly dominant. The difference caused by the relatively small difference in mass between different human made objects is negligible.

If what you said was the case the acceleration on 2 separate 1 kg masses would be different if they were combined into a single 2 kg mass, clearly this is not the case.

Also a feather and a large lump of something would fall at different rates in a vacuum.

I don't know at what scale the effect you are talking of becomes relevant, probably mountains.

1 Like

Yep, i understand that, and this is precisely why i chose this one. The datasheet says it uses around 15-20 mA to maintain the connection, and i suppose it should be fine to connect directly to the Nano, since it can handle up to 40mA on a single data pin, according to the Arduino Nano's datasheet.

image

The MPU6050's consumption is max 10mA. So i think the arduino's 5v power rail should handle that along with the relay (which has unknown consumption).

The buck converter's max output current is rated 3 amperes. So I guess it should be fine.

IT is relevant to the GPS system because the satellites vary orbit speed based on varying earth gravity. That is why there are 5 stations in the US to make real-time adjustments of the internal time clocks of each satellite as it moves across the US.
I am not saying the earth gravity is not significant, but the down ward vector of the earth gravity will be affected by the gravity of an adjacent large mass.

The OP should test the conclusion.

The elevator's normal, optimal speed is around 30 cm/second. Anything that exceeds that speed, is considered unsafe and should activate the brakes.

IF the elevator is hydraulic, the motion is anything but smooth.

Of course, but they have atomic clocks capable of distinguishing the tiny amounts of time dilation that result from the differences. As far as I can tell from what @R3UNITE is proposing there won't be any atomic clocks in his/her project, nor any other devices capable of making such a distinction.

Apart from that, an accelerometer measures the acceleration it experiences, not the acceleration other objects nearby might be experiencing.

You just moved the goalposts!

You cannot use an accelerometer to measure the speed the elevator is moving.

No I didn't! I clarified what we are talking about. You said:

I said it makes no difference. I still say it makes no difference in the context of what the OP is doing. I agree it makes a difference when talking about humongous masses, but not the kind of masses the OP is dealing with. We are not talking about a GPS system, we are not talking about the kinds of masses that would make any measurable difference for what the OP is doing. As you have not conceded that it makes no difference I am assuming you still think it does.

Anyway, we are off topic. Probably getting close to splitting this. @R3UNITE this is your topic, do you want this discussion split to a different topic or are you happy with it being here?

[EDIT Sorry, Paul and Paul mixed up, sorry for the confusion]

I would like to invert the logic for braking. In the "normal" situation, when the speed is okey, the relay should be activated allowing motion! In case a relay signal
wire is broken the brakes will be applied. Use NO point on the relay.

You surprise me by that statement. Creating, programming and using the controlling computer on heavy fork lift trucks using hydraulics I don't recognise jerky movements during my 14 years there.

1 Like

It may be possible to simplify it.

What can you tell us about the SIGNAL connection to the breaks? We know it needs 12V but how much current is drawn?

The Nano could power itself and the accelerometer board directly from the 12V input of connected to its Vin pin, so the buck converter would not be needed. But it cannot also power the coil of a 5V relay! If you switch to using a 12V relay board, the relay's coil would be powered directly from the 12V source, and then you no longer need the buck converter.

Another option could be a p-channel MOSFET, one that can handle the current needed by the SIGNAL connection to the breaks. You would need to drive the MOSFET's gate with a small n-channel MOSFET and a pull-up resistor to 12V. This would need almost no current to control the SIGNAL output (MOSFETs are voltage controlled) and so, again, the buck converter would not be needed.

1 Like

For an elevator it is easy to make a guesstimate of the speed. Just integrating the acceleration with some small "leakage" - the estimated value should decay to zero to correct integrations errors. Unlike other positioning problems the elevator cannot go in one direction for long and OP does not care about the absolute position - just speed.

1 Like

Perry, you are getting confused between Pauls?

I was accusing @R3UNITE of moving the goalposts, having originally said the breaks would be engaged by a threshold of acceleration (which can be done with an accelerometer) to a threshold of speed (which an accelerometer cannot do).

I agree with @PerryBebbington regarding the acceleration on earth's surface, the masses of other objects involved here will make no measurable difference, they will fall at 9.8m/s².