A Working Prototype

After a very long time experimenting with different ‘if’ statements and trying to figure out the best solution to the problem of the sensor and motor being very slow and jittery, I finally came to an outcome decision which I am happy with. I started off by creating different ‘if’ statements for a range of distances, this was still giving out very random results and crashing quite often. I then tried an ‘if else’ statement, to declare that if nothing is detected in the first range, then check the second range, and if nothing is detected in the second range then it must be in the third range. This still did not give out reliable results. So I went back to doing normal ‘if’ statements and tweaked my code, after many different attempts I found a code that worked; In my loop, I created three ‘if’ statements, for a different output speeds for the motor, depending on how close or far away someone is, in a range of 0-400cm.

Screen Shot 2015-01-23 at 12.19.13

The first statement has an output speed of 25 when someone is within 200-400cm away. The second statement has an output speed of 150 when someone is within 100-200cm away. And when someone is as close as 100cm or less, the output speed is 200. The video below is an example of the two extremes, firstly when my hand is close, the motor spins fast, and when I move my hand away it jumps to the slowest speed as the background was between 200-400cm away.

The next video shows the three stages of speeds – starting with the fastest close up, then the middle speed and finally the slowest speed. It is a bit unreliable as the ping sensor sometimes throws out some random information, as I can see in the serial monitor, but overall it works and gives the effect I was hoping for – that if someone is closer it spins faster and if someone is far away or no one is there it spins very slowly.

This is my working prototype, so my next stage is to construct my installation and test it in the public space.

Advertisements

Arduino Motor shield – Motor Finally turning!

The Arduino motor shield arrives, in size it is the same as the Arduino uno and just sits on top of the Uno:

IMG_0043

This is what the motor shield looks like when on top of the Arduino Uno. A motor shield is good as it allows you to control the speed and direction of the motor easily. It is even better for me as it will allow me to power a motor with a separate power supply of up to 12v, which is perfect as my stepper motor is 12V.

I put the motor shield on top of the Arduino Uno and wired up the elements I needed. Below is an image of how I wired up my stepper motor to the Arduino.

IMG_0041 2

I found an example code online to make the motor turn clockwise for a rotation, then anticlockwise:

 

So I used this code but then made my own adjustments to it to have a longer and faster rotation. I added the black wire onto the motor so it made it easier to see it turning in the videos.

 

So as you can see from the code in this video, I changed the steps per revolution from 48 to 200, this made the revolution last longer. I also changed the stepper speed from 30 to 50, making it turn faster. This is all part of my experimentation to see how fast I want the fastest speed to be of my final outcome. My next challenge is to add in the Ping Sensor and merge the codes of the two to get them both working off the same board.

Challenges along the way

Since starting to put together the electrical elements and the code for the Arduino, I have had numerous challenges that have held me back. Starting off with the Stepper motor:

I needed to use a stepper motor as I needed a 360 degree continuous rotation, rather than a servo motor which is not a continuous rotation. I also needed a stepper motor powerful enough to pull magnets with, so I went for the bi-polar 12V motor. The problem with this is that the Arduino can only handle 5V, so all my attempts to make the motor work through the Arduino were unsuccessful as there wasn’t enough power. So I tried adding more power using a 9V battery. I went back to basics and used an LED to test that the circuit I was using with the battery was working:

(Stupidly didn’t get the battery in shot but it was attached to the yellow and orange wires to the right of the shot.)

I then tried switching in the stepper motor instead of the LED, but I could not get the wiring right to power it, and it had not been documented anywhere online to help me. After a lot of research it was clear that most stepper motor examples used some sort of motor shield or driver. So I have ordered in a shield and a driver to try both of them out. I would say that one of my main difficulties has been trying to find help online, as I am a first-time user for Arduino I was hoping to find tutorials and simple diagrams for wiring, however for the electronics I was hoping to use there were not that many. I understand a lot of the code from my knowledge of the Processing language, but it is the wiring which I needed to understand. Because there are many different types of stepper motors, it is hard to find help specific to each motor. However I am hoping that once I get to use the motor shield, it will be basic to understand and follow instructions to get the motor spinning. I will then be able to progress with my idea and incorporate the input from the sensor.

 

Ferrofluid and magnets arrived – it works!

For my final outcome I ordered some Ferrofluid and 2, small, strong Neodymium magnets. It came with a petri dish and pipette. This is a quick post showing it working.

 

I put the petri dish on top of my glass desk and used the magnet from underneath the glass. The thickness of the glass meant the magnet didn’t get too close to the fluid and made the perfect spike form. If the magnet gets too close to the fluid it does not create the spikes as they have such a strong attraction. I will need to bear this in mind for when I put my final outcome together as there will need to be a small distance between the magnet and the liquid for the spikes to be able to form.

My next step is to get the stepper motor I ordered working, and then I will be able to link the input of the Ping sensor to create the speed change in the motor.

First Attempt at making the motor work

I have been playing around with servo motors and trying to get them to turn with the Arduino using the Servo Knob code example. I also made the Ping sensor work using the Ping code example, so all I need to do is combine the two codes – taking the important elements I need from each code and put them together.

  • const int pingPin = 7;
  • #include <Servo.h>;
  • myservo.attach(9);

These are some of the main aspects of code which I need to include for the Ping sensor and the servo motor to be recognised and included in the sketch.

The video above shows the motor turning depending on how close or far away my hand was. The Ping sensor flashes and the faster the flash the closer it is to an object.

The servo motor only has a 180 degree turning cycle, so when it completes its half rotation clockwise it turns back anti clockwise. For my final outcome I am wanting the motor to be a full rotation motor, so I am going to have to invest in a stepper motor which is a full 360 degree rotation. I will also have be using the SpeedControl example rather than Knob as I am wanting the motor to turn faster or slower depending on the input from the Ping sensor. This is what my next task is going to be.