Skip to content
Snippets Groups Projects
Output Devices.md 4.67 KiB
Newer Older
Mitalee Parikh's avatar
Mitalee Parikh committed
# Output Devices

This week I used an arduino Uno to make a forever spin top spin at different speeds and directions.  

I used the Zeotrope tutorial from the Arduino starter kit as it had a similar function.  

These are the components I need to control the motor:  

*   DC motor - only motor I have available now
*   H-bridge - IC to control the direction change of the motor
*   Potentiometer - to control speed manual input
*   Switches - 1 for on/off, 1 for direction change
*   Resistors - 10k ohm in series with switches
*   Battery 9V - power with connector
*   Arduino Uno + Breadboard + Jumper Wires  


Mitalee Parikh's avatar
Mitalee Parikh committed
![](./images/output/shopping.jpg)  
Mitalee Parikh's avatar
Mitalee Parikh committed

I refered to this schematic in the Arduino Projects book:

Mitalee Parikh's avatar
Mitalee Parikh committed
![](./images/output/schematic.jpg)  
Mitalee Parikh's avatar
Mitalee Parikh committed

To understand the circuit I arranged everything and marked the functions and connections of each part. And checked the [datasheet
for H-bridge L298N.](https://www.st.com/resource/en/datasheet/l298.pdf)


Mitalee Parikh's avatar
Mitalee Parikh committed
![](./images/output/setup.jpg)  
Mitalee Parikh's avatar
Mitalee Parikh committed

From the above setup, we can see that the pins used are:  

##### Digital Pins :  

*  4 for on/off
*   5 for direction change
*   2 for motor control
*   3 for motor control  

##### Analog Pins :  

*   A0 for speed control  


Based on this I defined the constants in the sketch in Arduino IDE.

Then, defined the variables, defined inputs and outputs, setup code, and the loop. Each part is explained briefly in the
Mitalee Parikh's avatar
Mitalee Parikh committed
sketch.![](./images/output/IDE.jpg)  
Mitalee Parikh's avatar
Mitalee Parikh committed


I uploaded the sketch without any errors, but still the motor did not run. I checked all connections and finally had to change my 9
battery.

<iframe width="688" height="387" src="https://www.youtube.com/embed/jXlCYYzOJkE" frameborder="0" allow="accelerometer; autoplay; e
  crypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>  


Next, I fabricated a circular base to make the top spin on top from some tape and board I had at home. The pink top was milled by m
on a Roland 4-axis milling machine some years back. If in the lab, I would like to make this setup more refined using the machines.

Mitalee Parikh's avatar
Mitalee Parikh committed
![](./images/output/top.jpg)  
Mitalee Parikh's avatar
Mitalee Parikh committed

Finally I put everything together and this is the setup for a forever spinning top.

<iframe width="688" height="387" src="https://www.youtube.com/embed/bE3cYQz22Pw" frameborder="0" allow="accelerometer; autoplay;
encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>  


#### Code

Mitalee Parikh's avatar
Mitalee Parikh committed
[Sketch](./images/output/foreverspin__dcmotor_potentiometer_hbridge_.zip)
Mitalee Parikh's avatar
Mitalee Parikh committed

#### Tutorials

[Arduino Zoetrope Project](https://programminginarduino.wordpress.com/2016/03/05/project-11/)

### Adding an input sensor

In my arduino kit I had 2 sensors, a temperature sensor and a tilt sensor, I used the latter to make the top spin.

A tilt sensor has a tiny ball inside that connects the legs to complete the circuit, on tilting, the ball loses contact with one
leg and breaks the circuit.


First I made a simple tilt sensor test with led outputs to understand how it works. This was fairly simple. I used [this t
torial](https://www.electronicshub.org/arduino-tilt-sensor/) to make leds light on tilting.  


Mitalee Parikh's avatar
Mitalee Parikh committed
![](./images/output/onlytilt.jpg)  
Mitalee Parikh's avatar
Mitalee Parikh committed

Next, I simplified the DC motor circuit from before by removing the H-brige, the potentiometer and the 2 switches, as I didn't
need to change direction or speed.


I referred <a href"https:="" www.tutorialspoint.com="" arduino="" arduino_dc_motor.htm"="">this tutorial</a> for different ways to u
e the dc motor. And then did something similar to [this.](https://www.dummies.com/computers/arduino/how-to-spin-a-dc-motor-with-the-arduino/)

After I got that to work, I combined both sketches to make the tilt sensor the input and the motor the output.

Mitalee Parikh's avatar
Mitalee Parikh committed
![](./images/output/sketch.jpg)  
Mitalee Parikh's avatar
Mitalee Parikh committed

I assembled all components, combining both the circuits

Mitalee Parikh's avatar
Mitalee Parikh committed
![](./images/output/setup2.jpg)  
Mitalee Parikh's avatar
Mitalee Parikh committed

I made some changes to the base, as it was wobbly, and then assembled eveything.

Mitalee Parikh's avatar
Mitalee Parikh committed
![](./images/output/1.jpg)  
![](./images/output/2.jpg)  
![](./images/output/3.jpg)  
Mitalee Parikh's avatar
Mitalee Parikh committed

This is the whole setup.

Mitalee Parikh's avatar
Mitalee Parikh committed
![](./images/output/4.jpg)  
Mitalee Parikh's avatar
Mitalee Parikh committed

This is a video of it in action

<iframe width="688" height="387" src="https://www.youtube.com/embed/FJzphqxnXO8" frameborder="0" allow="accelerometer; autoplay;
    encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>  

I would like to make the base more refined and add the breadboard and arduino inside, and connect to a battery instead of powering i
   from the arduino. To make the top spinner.

#### Code

Mitalee Parikh's avatar
Mitalee Parikh committed
[Only DC motor - sketch](./images/output/foreverspin__dcmotor_potentiometer_hbridge_.zip)  
[Only tilt sensor - sketch](./images/output/foreverspin__dcmotor_potentiometer_hbridge_.zip)  
[Tilt sensor + DC motor - sketch](./images/output/foreverspin__dcmotor_potentiometer_hbridge_.zip)