Being creative when using technology to achieve a specific function

When starting to get familiar with mechatronics and the different sensors, motors, actuators, etc. that your arsenal consists of, you might be thinking to start doing your own personal projects. At this point, you might have an idea of an specific function you want to achieve, but not an idea of how you’re going to enable this specific function. In the following section we will discuss how ‘thinking out of the box’ could enable a lot of cool interactions by using technology in smart ways.

Sensing if a door is closed/open

Let’s assume you have started a home-project in which you want to keep track of the different doors in your home, and whether or not the doors are closed or open. Assuming that your setup consists of an micro controller that has a connection to your phone, the next step would be to find a way to sense the door’s state.

Together we can think of some solutions and then proceedingly get more and more crazy with our ideas!

A simple Push-button

Alright, this might be one of the simplest ways of checking if the door is open or closed. Using standard push-button installed in the doorframe, one could sense if the door is closed when the button is pushed, and open when the button is released.

The simple push-button example

A distance sensor

We’re getting a bit more complicated with an distance sensor, but we’re still within the relm of simple mechatronic prototyping. As with the push button, we can assume that the distance sensor is installed by the door frame, or at least close enough to measure when the door is closed or open. The trigger for a closed door could be that an object in front of the sensor would be less than 5mm away, assuming that the door would then otherwise be open. However, using this principle, we’ve enabled certain measureing uncertainties, such as unintended objects (could be a person entering the door) triggering the sensor.

Now using the distance sensor

A sound sensor

Now at this point it’s starting to get ridiculous, yet still plausible. Assuming that one would want to register if a door is closed by using sound, that would be in theory be possible in many different ways, ranging from a simple sensor that reacts to the loudness of the door slamming closed, to an advanced AI that uses sounds to learn what a closing door sounds like. Of course, this choice of functions add another level of uncertainties, but it might just be the solution you were looking for!

Now using a sound sensor

A water level sensor

Yes, this suggestion does just seem plain stupid, but again, there might be a prototype that needs exactly this function. If a glass of water with a water level sensor inside was placed in the door opening, then the micro controller will be able to tell when the door is closed depending on if the glass has been knocked over by the closing door. The amount of problems and uncertainties in this example are too many to be discussed in this section and we do not recommend to try out this exact scenario.

The final example using a water level sensor

Technology can work in mysterious ways

As seen in the previous examples, we can use technology in numerous different ways and for different applications. Some times you get surprised with how the individual components can be used, and as such, it can be useful to have examples as the ones above. We could have continued introducing ways to register the door status by introducing a new type of sensor and figuring out how to trigger said sensor with the door (like we did we the water level sensor).

Looks can also be deceiving in which motors and actuators can functions as sensors themselves! Taking the Spike Prime motor as an example, the motor has a built in reader that can return the motors relative position (0-360°). As such, one could use the motors as turn knobs, such as the ones you would use to turn the volume up and down on an old radio.

The motor position of a LEGO motor

The code below is an example of how you would get the motor position on a Spike Prime.

from spike import Motor
from spike.control import wait_for_seconds, wait_until, Timer

# Define Motor
motor = Motor('A')

# Initialize loop
while True:
    # Read Motor location
    print(motor.get_position())
    wait_for_seconds(1)

If you were to exchange get.position() with get_degrees_counted(), you would get the continuous degrees in the direction the motor is spun.

This is also possible with a simple DC motor hooked up to a microcontroller, as shown in the video below. In this setup, the microcontroller reads the voltage that is generated by the motor when turned in a direction. One direction will return a negative voltage, the other a positive voltage.

The code used in the end of the video can be found here:

TODO: A1 is what?
void setup() {
    pinMode(A1, INPUT);
    Serial.begin(9600);
}

int playerPosition = 20;
void loop() {
  int moveAmount = (analogRead(A1)/2) - 256;
  playerPosition += moveAmount;

  String n = "|                                                  |";
  n.setCharAt(playerPosition, '0');
  Serial.println(n);

  delay(50);
}

For this challenge we want you to apply what you just learned by reading this page. Imagine you have a cookie jar filled with cookies. When you are not at home someone might want to steal your cookies, which would make you sad... To prevent this you need to come up with a smart way of deterring any cookie defilers that might come across your jar! For this challenge we want you to add two parts to your security system:

  1. A way of registering if the jar have been opened or not
  2. A way of communicating that you don't want the cookie poacher to steal your cookies, should the jar be opened

There is many ways this problem can be solved. Try thinking of your own idea of securing your cookies, and create your idea as a circuit prototype on a breadboard, to see if it works.

Example of how the cookie jar can be secured ;)