Elevator
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.
The additional complication is that using motors is hard on microcontrollers, due to the heavy power load and interference it causes. I’ve decided to use an Adafruit motor shield v1 clone.
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.
Goal:
- Move elevator between two floors
- Elevator should automatically stop at destination
- Control elevator from a web interface
Challenges:
- Ultrasonic sensor for elevator positioning
- Elevator motor mechanics.
- Elevator tower and coach construction
- Motor shield configuration
- Web API coding
Components:
- 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
Circuit:
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.
Code:
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-fivemotor 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-fiveproximity documentation is excellent at explaining how to install this and what options are available with the various proximity sensors that are supported.
Basic Flow
- 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
Filename
server.js
elevator.js
Now save and run your file.
npm init
npm install johnny-five events primus primus-emitter express http path --save
node server.js
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.
http://<em>192.168.0.4</em>:8080/command/elevator_toggle
The bottom and top distances within the code will need to be adjusted to match the elevator.
Construction:
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.
the original post is from http://www.internetoflego.com/elevator-web-api-motor-and-ultrasonic/
Leave a Reply
You must be logged in to post a comment.