This week I wanted to try my own project.   I wanted it to be something I could turn into a finished product.  In our last science class, the boys were studying the water cycle, how to filter it, and how to get where you need it.  We built a model of a spinning sprinkler.  The spinning creates an eddy that forces the water up the straws and out the openings at the top.  It was quite fun to build and play with even though the water sprays well beyond the bowl and even the counter.  Luckily the family dog was happy to help with the cleanup.  


My son wanted to use the Arduino to spin the dowl rod.  Since that's really just a matter of providing electricity to a motor, we thought we'd add something for the Arduino to actually process: a temperature sensor.  The idea is for the Arduino board to gather input from the sensor when the temperature is hot enough for the need of a little cooling off, the board tells the motor to turn on, which spins the dowel rod and sprays the bystander with nice refreshing water. Easy Peasey.  *cue foreshadowing music


I thought I'd start this week with just getting the motor to spin in response to the temperature sensor.

Goal:

Get the motor to turn on when the temperature reaches an assigned value.


Materials:

1 TMP 36 Temperature Sensor
1 DC motor
1 330 ohm resistor
1 transistor
1 diode 1N4148
11 jumper wires



Procedure:
1. Assemble the circuit
















2. Write the code

I thought I'd just post the code rather than screenshot it this time to see if it's easier to read:
float temp;

int tempPin = A0; //arduino pin used for temperature sensor

int tempMin = 0; // the temperature to start 

int tempMax = 90;

int motor = 9; // the pin where motor is connected

int motorSpeed = 0;

void setup() {

pinMode(motor, OUTPUT);

pinMode(tempPin, INPUT);

Serial.begin(9600);

}

void loop() {

temp = analogRead(tempPin);

temp = (temp *5.0*100.0)/1024.0; //calculate the temperature in Celsius

Serial.println(temp);

delay(1000); // delay in between reads for stability

if(temp < tempMin) { // if temp is lower than minimum temp

motorSpeed = 0; // motor is not spinning

digitalWrite(motor, LOW);

}

if((temp >= tempMin) && (temp <= tempMax)) //if temperature is higher than the minimum range

{

motorSpeed = map(temp, tempMin, tempMax, 32, 255); // the actual speed of motor

analogWrite(motor, motorSpeed); // spin the motor at the motorSpeed speed

}

}

3. Upload and test it all
I was too industrious.  I tried to do the motor and sensor all in the same initial build.  I should have done each separately and tested them before combining them.  I broke maker rule of doing only one thing different.  Note for future builds, start with the control and add one variable at a time so you know where the problem is.




There's also a beta test video that I'll add later, where I insisted on still trying both ideas together.  I have convinced myself to indeed listen to reason and try the concepts separately.






Exploration

Circuit and Code Play

Once I get the motor to respond to the sensor, I'd like to try different temperatures.

Extension Challenge

I'm wondering if the motor speed can increase as the temperature increases.  I'd like to also try using the 9V battery adaptor for power.

Applications & Extentsions:

If we get the prototype working, we thought it would be fun to make a life-size sprinkler that would be as artistic as it is fun. As you can see from the alpha test video, there is much debugging that needs to be done.  But it will be worth it when we get to the finish line.

.....wait.....is there ever really a finish line for a maker.....

Comments

Popular posts from this blog

Multiple LEDs: Project 4