Smart fan

Get fun with this STEAM activity, stay cool building a smart fan with our Maker Control Kit and additional components added in summer offer, motor, PIR sensor and temperature sensor

DIFFICULTY: Begginer.

DURATION:  30 min.

MATERIALS:

¿What is a PIR sensor?

PIR sensor detects movement.

We will use it so that our fan only works when you are in front and the temperature is high enough, this way it will be more efficient and you will not drain the batteries if you are not enjoying it.

CONNECTIONS:

  • DIO Pin 3 – Sensor PIR
  • DIO Pin5 – Botón
  • DIO Pin9 – Motor
  • DIO Pin12 – LED
  • A0 – Temperature Sensor

1. ASSEMBLY:

Download ur template and follow video steps. ¡¡Remember you can custmize your fan!!

2. PROGRAM:

Download program files for mBlock 5 and Arduino IDE 

Upload it to 4in1 Arduino based board ¡And will be done! If you need help, see our first steps guide

Below we show you the code that makes your fan work. Check the comments to understand what each part does and play by modifying the parameters. Explore and learn!

Or copy the blocks code below:


We recommend loading and uploading the code so that your fan works autonomously, although it will also work “live” while connected to the PC.
You can connect it autonomously and it will show you information about the temperature through the serial port. In order to view it, you must use the Arduino IDE port monitor since mBlock does not have this functionality.

Open Arduino IDE and paste program code below:

 int activo;
  float temperatura;
  float temporal;
  int i;
  int  movimiento;

void setup() {

  pinMode(5,INPUT);   // Botón
  pinMode(11,OUTPUT); // LED
  pinMode(3,INPUT);   // PIR
  pinMode(9,OUTPUT);  // Motor
  pinMode(A0+0,INPUT); // Sensor temperatura
  Serial.begin(115200);

  // Inicializamos variables

  activo = 0;
  temperatura = 0;
  i = 0;
  movimiento = 0;
  temporal = 0;

}

// Funcion para leer temperatura y sacar datos por puerto serie
void readtemp_N (double iteracion){

  // Leemos temperatura. Hacemos 100 lecturas del sensor, promediamos y sacamos valor de temperatura más estable
  if(iteracion < 100){ temporal += analogRead(A0+0); i += 1; }else{ temporal = temporal / i; temporal = (temporal * 5) / 1024; temporal = ((temporal - 0.57)) * 100; temperatura = ((temperatura + temporal)) / 2; temporal = 0; i = 0; if((activo == 1) && (movimiento > 0)){
          Serial.println(String("Sistema encendido - Movimiento detectado - ") + String(String(temperatura) + String(" grados")));
      }else{
          if(activo == 1){
              Serial.println(String("Sistema encendido - No movimiento - ") + String(String(temperatura) + String(" grados")));
          }else{
              Serial.println(String("Sistema desactivado - ") + String(String(temperatura) + String(" grados")));
          }
      }
  }
}

void loop() {
      // función con bloques para leer temperatura
      readtemp_N(i);

      // Sistema activo
      if(activo == 1){
          // Vigilamos botón, si se pulsa desactivamos sistema y apagamos led indicador
          if(digitalRead(5)){
              delay(200);
              activo = 0;
              digitalWrite(11,0);

          }
          if(temperatura > 20){
              // Si temperatura mayor de 20º y detectamos movimiento se debe enceder motor. Definimos un cuenta atras que se
              // inicializa cada vez que se detecta movimiento y mantiene el motor en marcha unos segundos tras no detectar movimiento
              if(digitalRead(3)){
                  movimiento = 300;
              }else{
                  movimiento += -1;
              }
              if(movimiento > 0){
                  digitalWrite(9,1);
              }else{
                  digitalWrite(9,0);
              }

          }else{
              // Temperatura menor de 20º. Paramos motor
              digitalWrite(9,0);
          }
      }else{
          // Sistema inactivo, Apagamos motor y vigilamos botÓn.
          digitalWrite(9,0);
          if(digitalRead(5)){
              delay(200);
              activo = 1;
              digitalWrite(11,1);
          }
      }
}

Upload code and ¡enjoy your fan!

You can see the temperature indicated by the sensor through the Arduino IDE serial monitor (tools), at the speed of 115200 baud.

ACTIVITY RESULT:

0 0

0