The IoL City Station has two levels and needs a way to transport people between the platforms. Let’s build an elevator!
The basic idea is to use a motor to lift the elevator and a sensor to figure out when to stop it automatically. Because I had a spare ultrasonic distance sensor, that’s what I’m going to use. This does make it more complicated, but it’s a fun way to see how this sensor works. Another approach could have been to use infrared sensors on each level, but I’ve already used those sensors in previous projects so that’s boring.
Finally, I want to start connecting all of these projects to a web interface. There will be some extra code to setup the web server and connect the circuit file. I will only lightly explain this, since a web search will probably provide more comprehensive instructions.
- Move elevator between two floors
- Elevator should automatically stop at destination
- Control elevator from a web interface
- Ultrasonic sensor for elevator positioning
- Elevator motor mechanics.
- Elevator tower and coach construction
- Motor shield configuration
- Web API coding
- Raspberry Pi (or any NodeJS host)
- Arduino (I used an Uno clone but any will do)
- Adafruit motor shield v1 clone
- Ultrasonic Distance Measuring Sensor – HC – SR04
- 5v DC motor
First the motor shield will need to be installed. This shield does not make use of the digital pin 2, so I will use this for the ultrasonic sensor. I had to remove the header pin that would normally connect there so I could connect the sensor wire.
Install the motor shield and then connect the motor to the M4 connectors.
I’ve used an external 12v power supply that is plugged into the Arduino. This avoids too much power draw from the Raspberry Pi USB host.
Initialize the board, the motor and ultrasonic sensor. The motor shield will need a special bit of code to get the configurations in there. The Johnny-five motor documentation is great at explaining what options are available and any special code needed to support your motor shield.
To use the ultrasonic sensor, the Arduino must be running PingFirmata as opposed to StandardFirmata used in previous projects. Again, the Johnny-five proximity documentation is excellent at explaining how to install this and what options are available with the various proximity sensors that are supported.
- Create web server for API and web sockets.
- Initialize board and devices.
- Create elevator functions for up/down/toggle/brake
- Export commands for API usage
- Listen to sensor to stop the elevator at the correct position and prevent accidents
- A smoothing algorithm will be used to reduce sporadic measurements
Now save and run your file.
npm install johnny-five events primus primus-emitter express http path --save
You should now see the REPL on your screen and control the elevator by typing in any of the defined functions or device objects.
root@thethingbox:~/IoL# node server.js 120509902 Device(s) /dev/ttyUSB0,/dev/ttyACM0 120509983 Connected /dev/ttyUSB0 120513609 Repl Initialized >> elevatorToggle() Elevator Toggled Elevator going down! undefined >> elevatorStop() elevator stopping Elevator Stopped Non-braking motor type
You can now also control the elevator by simply putting the following in any web browser, where the IP address is that of your NodeJS host.
The bottom and top distances within the code will need to be adjusted to match the elevator.
The frame was made primarily from technic beams. It was much easier to achieve height with less bricks this way.
I used two lengths of train track to run the elevator coach on. This kept things aligned as it moved. The elevator coach has a pulley to change the power ratio so its easier on the motor.
The small DC motor was non Lego, so I stuck an eraser head on the motor pin to drive a gearbox with a rubber band. The gear box consists of a worm screw, gear and axle. The worm screw drastically changes the gear ratio and also prevents the elevator from moving if no power is applied.