Fan controlled by a temperature sensor

Preparing For This Tutorial:

Equipment needed:

  • Intelligent EV3 brick with SD card including Python environment.

  • Medium servomotor (quicker) for driving the fan.

  • Large servomotor (stronger) for driving the valve.

  • Two touch sensors for checking the valve position.

  • Temperature sensor. If your school has no access to temperature sensor, ultrasonic sensor may be used as a substitution.

  • Cables.

  • Set of bricks, including propellers.

DSC09959.JPG

DSC09970.JPG

Above pictures show possible implementation, but you are encouraged to construct the robot according to your own vision.

Time constraints:

  • You should complete the whole task within two 45-minutes lessons.

Exercise

Construct and program a machine consisting of a fan, valve, two touch sensors and one temperature sensor. In case of lack of a temperature sensor, an ultrasonic sensor may be used instead. The behavior of fan, brick and valve should depend on the temperature interval as follows:

  • T < 20°C. The fan is motionless, safety valve is closed, brick is silent and LEDs shine green.

  • 20°C <= T < 30°C. Valve is still closed, brick is silent, LEDs shine orange. The angular speed of the fan rises by 1% with every 0,1°C over 20°C.

  • T >= 30°C. The fan spins around with maximum power. Safety valve opens. LEDs blink red. Sound alarm is emitted.

All of it should work as long as no brick button is pressed. After pressing any button, both motors should stop and LEDs color should be set green. The brick should verbally confirm that the program is terminated.

If an ultrasonic sensor is used as a replacement, it should measure the distance d of the “enemy”. Try to use the general object Sensor() in the program instead of UltrasonicSensor(). The behavior of the machine should be defined by analogy, treating the smaller distance as the higher temperature, ie:

  • d > 30 cm. The fan is motionless, safety valve is closed, brick is silent and LEDs shine green.

  • 30 cm >= d > 20 cm. Valve is still closed, brick is silent, LEDs shine orange. The angular speed of the fan rises by 1% with every 1 mm below 30 cm.

  • d <= 20 cm. The fan spins around with maximum power. Safety valve opens. LEDs blink red. Sound alarm is emitted.

Theory

Objects like TouchSensor(), ColorSensor() and so on, have a common ancestor called Sensor(). If your robot is equipped with nonstandard sensors, which are not included at the official list of EV3 sensors, you may try to use the general object Sensor(). It has a method value(), which returns the reading of measurement of the value appropriate to the mode that the sensor is set to. If the sensor is working in its standard mode, no other methods are needed to read its measurements.

In standard mode, the temperature sensor returns an integer value between -550 to 1280 which corresponds to the temperature between -55°C to +128°C. It means that 1 unit of sensor is equal 0,1°C. For example the sensor value 200 mean 20°C

Our robot is supposed to behave according to the reading of the temperature sensor as long as its program is not interrupted by pressing any brick button. The best way is to put the entire program in a loop checking if any button is pressed. So the program construction should be like this:

#!/usr/bin/env python3

btn = Button()

tempSensor = Sensor(‘in1’)

#...

while not btn.any{}:

  temp = tempSensor.value()

  if temp < 200:

    #...

The robot should be aware all the time, whether the valve is open or closed, even just after running the program. For this purpose two touch sensors should be located in the vicinity of the valve. One sensor should be touched when the valve is closed and the second – when the valve is open. If the valve is to be closed, the motor should run forward as long as the first sensor is touched. If the valve is to be open, the motor should run backward until the second sensor is touched.

It is advisable that the robot should greet at the beginning of the program and say goodbye at the end, so that we assure that the entire program has been executed. The best way is to use the function Sound.speak(‘text to say’).

For other details see the documentation or ask the teacher.

Short help on programming

Commands/functions needed for the exercise

#!/usr/bin/env python3

#Import library

from ev3dev.ev3 import *

#create a new instance of the class and assigns object to the local variable motor_fan = MediumMotor('outA')

motor_valve = LargeMotor('outC')

btn = Button()

ts1 = TouchSensor('in3')

ts2 = TouchSensor('in4')

temps = Sensor('in1')

#Function (class MediumMotor and LargeMotor) to run or stop the motor

stop(stop_action='brake')

run_forever(speed_sp=100)

#Example of use LEDs and sound.

Leds.set_color(Leds.LEFT, Leds.ORANGE)

Sound.speak('Hello')