Tag: Arduino

  • Power Management System for Home- A Smart Fan Project

    Power Management System for Home- A Smart Fan Project

    This Power Management System for Home-A Smart Fan Project transforms a standing air conditioning fan into a smart automated version that detects human presence using a passive infrared (PIR) sensor and then sets two distinct time modes using a real-time clock (RTC). The “Auto Sense Mode” and “Remote Active Mode” in particular. The user could utilize the remote control to access the desired speed selection during the “working hour,” also referred to as the “Remote Active Mode.” The fan operates on its own while it is in Auto Sensing mode. The fan knows when to switch to auto mode thanks to the RTC sensor. It may then use the PIR sensor to identify human movements and determine whether someone is in need. During the Auto Sensing mode, the fan controls itself automatically. With the RTC sensor, the fan can tell when it is time for auto mode. And then, using the PIR sensor, it could detect human motion and know when there is somebody around needing cool air ventilation. If the fan senses motion, it would turn itself on and run at a constant speed, which is the speed of two. But if, after some time, it couldn’t detect any motion, it would turn itself off.

    Materials/Components Needed

    1. Pedestal Fan

    Pedestal Fan
    Pedestal Fan

    A standing electric fan designed to circulate air efficiently in a room. It typically has adjustable height, oscillation, and speed settings.


    2. Atmega328P IC

    Atmega328P IC
    Atmega328P IC

    A widely used 8-bit microcontroller from the AVR family, commonly found in Arduino boards. It controls input/output devices, processes data, and runs embedded programs.


    3. 16MHz Crystal Oscillator

    16MHz Crystal Oscillator
    16MHz Crystal Oscillator

    A timing device that provides a stable 16 MHz clock signal to the microcontroller, ensuring accurate processing speed and synchronization of operations.


    4. 1602 LCD Module

    1602 LCD Module
    1602 LCD Module

    A 16×2 character Liquid Crystal Display used to show alphanumeric information, such as sensor readings, status messages, or system outputs.


    5. 10k Potentiometer

    10k Potentiometer
    10k Potentiometer

    A variable resistor used to adjust voltage levels. Commonly used to control the contrast of LCD displays or tune analog signals.

    6. 3-Channel Relay Module

    3-Channel Relay Module
    3-Channel Relay Module

    An electronic module that allows the microcontroller to switch high-voltage devices (like fans, lamps, or motors) on and off safely through low-voltage digital signals.

    Buy Full complete kit for this project on our online store or contact us via WhatsApp

    Circuit/Schematic Diagram

    The project design started with us designing the circuit diagram using the Fritzing circuit IDE. As shown in the picture below.

    Power Management System for Home- A Smart Fan Project
    Circuit Diagram for the project design

    Circuit Diagram Explanation

    Following the circuit diagram, we built the standalone development board around the Atmega328P-U microcontroller. For other projects that used Atmega328P-PU microcontroller, check out: Atmega328P-U projects

    So here, the atmega328P-U microcontroller unit (MCU) is programmed using the FTDI ISP programmer as shown above. We used a DS3231 type of RTC to keep and set our time. We used a PIR sensor to detect the motion also. The connection is set such that the serial clock pin (SCL) and the serial data pin (SDA) of the RTC are connected to the analog pin 5 (A5) and analog pin 4 (A4) of the MCU, respectively. The PIR output is connected to the digital pin 10 of the Atmega328P-U.

    Next that catches our interest is the 16×4 LCD connection. As shown in the circuit diagram, we are using the 4-bit connection mode (4-wire type connection). We wired Register Select (RS) to MCU D3, Enable pin (E) to D4, and the four data pins to digital pins 8 through 5.

    Note: If you are using a power supply that has a DC output above 5V, you have to use a voltage regulator as shown in the circuit diagram to buck it down to 5V since the MCU uses a 5V DC output. But ensure that your 5V meets up to 3A. Otherwise, during relay switching, the LCD screen may scatter and start misbehaving. Also, if you don’t use a 5V DC supply, the whole system will end up getting fried.

    To switch the states of the AC standing fan, we need a 3-channel relay module to change the speed controls automatically.

    Power Management System for Home- A Smart Fan Project
    Speed regulator switch

    Here we disconnected the normal speed selector switch found on the standing fan and extended it with more wires. Then the AC live wire is connected to the common of the relays while the respective speed lines are connected to the other three, as shown in the picture above. The neutral line of the AC is connected to the neutral of the fan induction coil.

    Arduino Source Code

    After the connection has been made, the PIR sensor and the RTC are connected too to the MCU board. The LCD module is connected to its header pin. Next is to program the MCU. Copy the code below into your Arduino IDE.

    #include <Wire.h>
    
    #include <RTClib.h>
    
    #include <EEPROM.h>
    
    #include <IRremote.h>
    
    #include <LiquidCrystal.h>
    LiquidCrystal lcd(3, 4, 8, 7, 6, 5);
    
    RTC_DS3231 rtc;
    
    char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
    
    #define speed1 A0
    #define speed2 A1
    #define speed3 A2
    int RECV_PIN = 2;
    const int PIR = 10;
    unsigned long count = 0;
    int state = LOW;
    int currentState = 0;
    int previousState = 0;
    int sensor_count = 0;
    int timer = 0;
    int ts = 50;
    int tc = ts;
    int sc = 10;
    int fail = 0;
    int ms = 50;
    unsigned long pm = 0;
    const long interval = ms;
    boolean logic;
    
    byte val0 = EEPROM.read(0);
    byte val1 = EEPROM.read(1);
    byte val2 = EEPROM.read(2);
    
    int ontime = val1;
    int offtime = val2;
    int menu = 0;
    int pause = 50;
    int rtcDAY, rtcMONTH, rtcYEAR, rtcHOUR, rtcMIN, rtcSEC;
    int minus = 0;
    int plus = 0;
    int fan = 0;
    String remote;
    String stat = ""; 
    String SPEED = "";
    
    IRrecv irrecv(RECV_PIN);
    decode_results results;
    
    void page(){
        DateTime now = rtc.now();
        lcd.setCursor(0, 0);
        lcd.print("RUKE's SMART FAN");
        lcd.setCursor(0, 1);
        lcd.print(SPEED);
        lcd.setCursor(0, 2);
        lcd.print(stat); 
        lcd.setCursor(0, 3);
        lcd.print(now.day(), DEC);
        lcd.print('/');
        lcd.print(now.month(), DEC);
        lcd.print('/');
        lcd.print(now.year(), DEC);
        lcd.print("  ");
        lcd.print(now.hour(), DEC);
        lcd.print(':');
        lcd.print(now.minute(), DEC);
               }
    void fanOff(){
       //turn the fan off
       analogWrite(speed1, 255);
       analogWrite(speed2, 255);
       analogWrite(speed3, 255);
       SPEED = "     FAN OFF      ";
    }
    void spd1(){
       //turn the fan off
       analogWrite(speed1, 0);
       analogWrite(speed2, 255);
       analogWrite(speed3, 255);
       SPEED = "     speed 1      ";
    }
    void spd2(){
       //turn the fan off
       analogWrite(speed1, 255);
       analogWrite(speed2, 0);
       analogWrite(speed3, 255);
       SPEED = "     speed 2      ";
    }
    void spd3(){
       //turn the fan off
       analogWrite(speed1, 255);
       analogWrite(speed2, 255);
       analogWrite(speed3, 0);
       SPEED = "     speed 2      ";
    }
    void SenSe(){
      unsigned long cm = millis();
    unsigned long rr = cm - pm;
    if(rr > interval){
       if(digitalRead(PIR)==HIGH){
        sensor_count = sensor_count + 1;
           }
    timer = timer + 1;
    pm = cm;
     if(timer >= tc){
      if((sensor_count >= sc) && (tc >= ts)){    
        spd2();
        tc = 0;
        fail = 0;
      }
      else{
        fail = fail + 1;
        tc = ts;
        //interval = ms;
      }
      timer = 0;
      sensor_count = 0;
        }
    }
    if(fail > 20){
      fail = 0;
      fanOff();
      }
    }
    
    void setup() {
      // put your setup code here, to run once:
    Serial.begin(9600);
    lcd.begin(16, 4);
    
    pinMode(speed1, OUTPUT);
    pinMode(speed2, OUTPUT);
    pinMode(speed3, OUTPUT);
    pinMode(PIR,INPUT);
    
    if (! rtc.begin()) {
      lcd.setCursor(0, 0);
        lcd.print("Can't find RTC");
        delay(3000);
        while (1);
      }
    
      if (rtc.lostPower()) {
        lcd.setCursor(0, 0);
        lcd.print("RTC lost power!");
        // following line sets the RTC to the date & time this sketch was compiled
        rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
        
        delay(3000);
      }
    
    // In case the interrupt driver crashes on setup, give a clue
      // to the user what's going on.
      Serial.println("Enabling IRin");
      irrecv.enableIRIn(); // Start the receiver
      Serial.println("Enabled IRin");
    
      fanOff();
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      DateTime now = rtc.now();
      rtcHOUR = now.hour(), DEC;
      if (irrecv.decode(&results)){
      remote = String(results.value, HEX);
        if(remote == "511dbb"){
       menu = 1;
      }
        Serial.println(menu);
        Serial.println(fan);
        Serial.println(remote);
        irrecv.resume(); // Receive the next value
      }
     
      if((rtcHOUR >= ontime) && (rtcHOUR <offtime))//Comparing the current time with the Alarm time
        { 
          stat = "    Auto Mode      ";
          SenSe();
        
        }
        else{
          if(remote == "c101e57b"){
            fanOff();
        }
        if(remote == "9716be3f"){
            spd1();
        }
        if(remote == "3d9ae3f7"){
            spd2();
        }
        if(remote == "6182021b"){
            spd3();
        }
         stat = "  Remote Active     ";
        
         
        }
    if(menu < 1){
    page();
    }
        menu = constrain(menu, 0, 5);
        switch(menu){
      case 1:
        lcd.setCursor(0, 0);
        lcd.print("**Control MENU**  ");
        lcd.setCursor(0, 1);
        lcd.print(">1. FAN ON Time  ");
        lcd.setCursor(0, 2);  
        lcd.print(" 2. FAN OFF Time  ");
        lcd.setCursor(0, 3);  
        lcd.print(" 3. EXIT MENU      ");
          if(remote == "a3c8eddb"){
          menu++;
           if(menu > 3){
          menu = 1; }
              }
          if(remote == "f076c13b"){
          menu--;
           if(menu < 1){
          menu = 3; }
               }
          if(remote == "e5cfbd7f" && menu == 1){
          menu = 4;      
          }   
          break;
      
     case 2:
        lcd.setCursor(0, 0);
        lcd.print("**Control MENU**  ");
        lcd.setCursor(0, 1);
        lcd.print(" 1. FAN ON Time     ");
        lcd.setCursor(0, 2);  
        lcd.print(">2. FAN OFF Time   ");
        lcd.setCursor(0, 3);  
        lcd.print(" 3. EXIT MENU    ");
          if(remote == "a3c8eddb"){
          menu++;
           if(menu > 3){
          menu = 1;}
                }
          if(remote == "f076c13b"){
          menu--;
           if(menu < 1){
          menu = 3; }
              }
          if(remote == "e5cfbd7f" && menu == 2){
          menu = 5;      
          }   
        break;
    
       case 3:
        lcd.setCursor(0, 0);
        lcd.print("**Control MENU**  ");
        lcd.setCursor(0, 1);
        lcd.print(" 1. FAN ON Time");
        lcd.setCursor(0, 2);  
        lcd.print(" 2. FAN OFF Time");
        lcd.setCursor(0, 3);  
        lcd.print(">3. EXIT MENU    ");
          if(remote == "a3c8eddb"){
          menu++;
           if(menu > 3){
          menu = 1;}
            }
          if(remote == "f076c13b"){
          menu--;
           if(menu < 1){
          menu = 3;
          }
                }
        if(remote == "e5cfbd7f" && menu == 3){
          menu = 0; }
        break; 
    
      case 5:
        lcd.clear();
        offtime = constrain(offtime, 0, 23);
        lcd.setCursor(0, 0);
        lcd.print(" SET AC OFF Time:   ");
        lcd.setCursor(0, 2);  
        lcd.print("New Time = ");
        lcd.print(offtime);
        lcd.print(":00      ");
        if(remote == "a3c8eddb"){
          offtime++;
           if(offtime > 23){
          offtime = 0;
          }
              }
        if(remote == "f076c13b"){
        offtime--;
        if(offtime < 0){
          offtime = 23;
          }
           }
        if(remote == "e5cfbd7f" && menu == 5){
          EEPROM.update(2, offtime);
          menu = 2;
        }
        break;
    
      case 4:
        lcd.clear();
        ontime = constrain(ontime, 0, 23);
        lcd.setCursor(0, 0);
        lcd.print(" Set FAN ON Time   ");
        lcd.setCursor(0, 2);  
        lcd.print("New Time = ");
        lcd.print(ontime);
        lcd.print(":00      ");
        if(remote == "a3c8eddb"){
          ontime++;
           if(ontime > 23){
          ontime = 0;}
              }
        if(remote == "f076c13b"){
          ontime--;
           if(ontime < 0){
          ontime = 23;}
              }
        if(remote == "e5cfbd7f" && menu == 4){
          EEPROM.update(1, ontime);
          menu = 1;
        }
        break;
          }
          remote = "";
          delay(50);
        }
    

    Arduino Sketch Explanation

    As shown from above, four libraries are needed in this Power Management System for Home- A Smart Fan Project sketch: the RTC library, the lcd library, the IR receiver library and the EEPROM lib. Although some of these libraries are already in the Arduino IDE.

    You can change the time for the Remote active mode and the Auto mode in the design after successful uploading the code and using your remote controller to adjust it. To design which of the button does your bidding, you have to run the IR receiver test and map out the received IR HEX values. Then you would in turn use these HEX codes, to assign a specific command in the IF statement you coded.

    We used Analog pins for your relay module inputs which in turn controls the AC fan speeds and we defined in the code lines above. The page function greeting message could be altered to any of the programmer’s choice. functions like fanOff(), spd1(), spd2() and spd3() were used to control the state of each relay on the relay module and which in turn regulate the fan speed. As seen in the sketch, function fanOff() turns off all the inputs of the relay module by gving them 8-bit -1 (255) voltage level (which is a HIGH). Since the relay module is active LOW, this would turn off all the inputs.

    function Sense() controls the PIR sensor and its counting mechanism. Virtually, we just increased the delay time to 10 seconds (int sc =10). After 20 seconds in the auto mode, if it doesn’t sense any motion, it automatically turns off.

    A visual of the Power Management System for Home-A Smart Fan Project is given below for more explanation.

    Smart Fan Project

    Conclusion

    And that is it for this post. If you have any questions, just leave a comment in the comment section below. You can also see our other posts or check out our online store if you are a tech enthusiast. Let us know how we can assist you. Any time!

    Thank you.

  • How to Build an SMS Based Metal Detector

    How to Build an SMS Based Metal Detector

    How to Build an SMS Based Metal Detector
    How to Build an SMS Based Metal Detector

    Imagine a system that can detect metals on a person and immediately send you an SMS alert to notify you. Such a system can be pivotal in monitoring areas remotely and quickly responding to potential threats. In this tutorial, we’ll walk you through how to build an SMS-based metal detector using Arduino, a GSM module, and other components that will make your metal detection project both effective and scalable.

    This project, how to build an SMS-based metal detector design and construct a metal detector with SMS alert by incorporating a metal detector sensor to detect metallic objects in close proximity. It would instantly send out an SMS to a predefined personnel’s phone number once a metal or electronic device(s) was detected. The design has features like its portable size, and runs on rechargeable batteries. In designing this project, we had to calculate the feasibility of the needed materials’ cost in order to make sure that we were not undertaking an exorbitant project. This SMS-based metal detector project is about metal detector design with SMS notification. Below is a description of the components used for the implementation of the Metal Detector with SMS Alert system design.

    What is an SMS-Based Metal Detector?

    An SMS-based metal detector is a smart security system designed to detect the presence of metal objects on an individual’s body and send an SMS notification to a specified recipient when metal is detected. The core functionality of the system relies on a metal detection sensor, which senses metal objects and triggers an SMS through the GSM module.

    A traditional handheld metal detector device
    A traditional handheld metal detector device

    This system can be installed at various checkpoints, providing an alert mechanism for security personnel. Whether it’s detecting concealed weapons or other unauthorized metallic items, this tool can significantly enhance security.

    How Does an SMS-Based Metal Detector Work?

    The working principle of this system is simple yet effective. When a metal object comes within the detection range of the sensor, it sends a signal to the Arduino, which is the main controller. The Arduino processes this input and sends a command to the GSM module, which in turn sends an SMS to a pre-configured mobile number, alerting the security personnel.

    This makes it particularly useful for real-time monitoring of restricted areas. Additionally, this system can be customized to operate efficiently in different environments, making it a versatile solution for various security applications.

    MATERIALS/COMPONENTS

    • 3.7V 1800mAh Li-ion Rechargeable Battery
    • 3.7V 1800mAh Casing
    • 3.7 Lipo 1A Battery Charging Board Charger Module Mini USB Interface
    • LM323T Voltage Regulator
    • The 1k resistor
    • 330-ohm resistor
    • LED
    • 1N4148 diode
    • Perforated board (stripped line type)
    • Connecting jumper wire
    • 10nF capacitor
    • GSM Module (SIM900L)
    • 5V Passive Buzzer

    Buy the complete kit for this project on our online store or kindly chat us on WhatsApp

    3.7V 1800mAh Li-ion Rechargeable Battery:

    The Power Unit for the design depended mainly on DC supply from rechargeable batteries, each rated 3.7V 1800mAh. And 3 pieces of 3.7V 1800mAh Li-ion batteries gave us the needed Voltage for GSM module. Also, these were rechargeable batteries so we used Lipo battery charging board.

    how to build an SMS based metal detector project design: The rechargeable battery
    how to build an SMS based metal detector project design: The rechargeable battery

    The 3.7V rechargeable battery can output a current of 1.8A for one hour. It is durable and can be charged very quickly. It is also portable and, as such, was ideal for using as a power source for the project design.

    Read Also How to Make Money as A student with these 10 Free Money-Making Sites

    3.7V 1800mAh Casing:

    The above pictured batteries needed a casing, so we used one 3.6V-3.7V Battery Charging Discharging Control Holder Case.  Li-ion battery with 1S3P PCM.

    LiPo Battery casing
    3.6V-3.7V Battery Charging Discharging Control Holder Case  Li-ion w/1S3P PCM

    This is a plastic DIY Lithium battery box battery holder with pin suitable for 2×18650 (3.7V-7.4V) Lipo battery. The casing is of high quality and can withstand temperatures of about 95°C. It maintains firm hold with the batteries inside it and offers safety from short circuiting and wire burn out. A total of 3 battery were connected in series to give us a 12V approximately 5A output for the GSM module.

    Read Also The Salem Witch Trials (1692-1693)

    3.7 Lipo 1A Battery Charging Board Charger Module Mini USB Interface:

    How to Build an SMS Based Metal Detector: The LiPo battery charging board
    3.7 Lipo Charger board

    The Lipo charging board module uses mature charging chip TP4056, simple peripheral circuits that has good protection performance and high charging accuracy. It comes with full machinery automated processing and has high reliability. Its output charging current can be adjusted by just changing the circuit board fixed resistors, this would in turn change the output current to the 100mA-1000mA. The Input reverse connection has no effect on the chip, but the output (battery end) reverse connection will burn out the chip. When measuring with an Ampere meter, it is best in series connected to the 5V input end. The charging current is best to be 0.37 times of the battery capacity,
    It is very convenient for portability an size conservation.   Below is a summary of its datasheet.

    Datasheet Specificatiuon:

    • Item Name: Lipo battery charging board
    • Item NO. : TP4056
    • Charging Method: linear charge
    • Charging Current: 1A Adjustable
    • Charge Accuracy: 1.5 pct
    • Input Voltage: 4.5V – 5.5V
    • Full Charge Voltage: 4.2V
    • Charging Indicator: Blue light lit charge,red light lit full charge
    • Charging Input Interface: Mini USB
    • Working Temperature: -10 Degree to +85 Degree
    • Reverse: NO
    • Usage: Used for single lipo or multi-section lipo parallel charging, can take power from the USB port.
    • Current Regulation: Can auto regulate current charging.

    LM323T Voltage Regulator:

    LM7805 5V voltage regulator
    LM323T voltage regulator IC and pinout

    The voltage regulator IC, L232T is used to provide a regulated 5V DC output. Input voltage fed into the input pin (pin 1) was 2 volts more than the rated output voltage (in our own case 12V) for proper working of Integrated Circuit (IC). For better results, a filter ripple capacitor of 1uF was connected to the output of the IC L323T to eliminate the noise, produced by transient changes in voltage.

    Read Also How to Install CCTV Surveillance Cameras with Remote Viewing

    Datasheet Specifications:

    • Output Voltage: +5V, up to 3A with peak current of 4.5A
    • Current Output: up to 3.5A
    • Input Voltage: 7V Minimum, 35V Maximum
    • Package : TO-220
    • Pin Spacing Pitch : 2.54mm (0.1in)
    • Hole Diameter : 3.8mm (0.15in)
    • STMicroelectronics Part Number:  L323T

    Metal Detector Unit

    This unit is mainly composed of the resistor, the inductor and the capacitor used to for the EMF pulsating device. In our design resistor-inductor-capacitive (RLC) circuit, we made us of a hand-made 150 coil turns of size wire gauge 30 wound about a diameter of 6cm to form the EMF emitting part of our design.

    The whole SMS based Metal detector design depends on us building an LC high pass filter with the help of a coil and a capacitor. According to the equation of Mutual inductance;

    formula for LC calculation
    formula for LC calculation

    Where,

    L is Inductance in Henry

    μo   is permeability, its 4π*10-7 for Air

    N is number of turns of wire coil

    A is inner Core Area (πr2) in m2

    L is length of the Coil in meters

    Whenever a current passes through a coil, it generates a magnetic field around it. And the change in the magnetic field generates an electric field. Now according to Faraday’s law, because of this Electric field, a voltage develops across the coil which opposes the change in magnetic field and that’s how our coil develops the Inductance, means the generated voltage opposes the increase in the current.

    When we place a metal near the coil, the coil changes its inductance. This change in inductance depends upon the metal type. And  for a ferromagnetic material like iron, it increases. However, it decreases for non-magnetic materials.

    The medium of flow of the magnetic field generated by the inductor is nothing in air. Depending on the core of the coil, the inductance value changes drastically.

    The coil wound here is an air cored one, so when we bring a metal piece near the coil, the metal piece acts as a core for the air cored inductor. Hence,  the inductance of the coil changes or increases considerably. With this sudden increase in inductance of coil the overall reactance or impedance of the LC circuit changes by a considerable amount when compared without the metal piece.

    5cm diameter Coil

    10nF 100VDC Polyester Capacitor

    10nF polyester capacitor used in the design

    10nF polyester capacitor used in the design

    Polyester capacitors offer good stability and a large range of values at a low cost, and they are used for charging and discharging the inductor in the circuit of How to Build an SMS Based Metal Detector project design.

    How to Build an SMS Based Metal Detector: 330Ω Resistor

    33K-ohms precision resistor

    330Ω 1/4W Metal Film Precision Resistor

    Specifications:

    • Resistance: 330 Ohms
    • Wattage Rating: 0.25 Watt
    • Tolerance: 1%
    • Metal Film
    • Lead Free
    • ROHS compliant
    • Diameter of Leads: 0.43mm (0.02in)
    • Length of Leads: ~28mm (1.1in)

    IN4148 DIODE

    zener diode
    IN4148 diode

    The 1N4148 is a standard silicon switching signal diode. This diode, 1N4148 can switch within applications of up to about 100 MHz with a reverse-recovery time of no more than 4 ns. It was fabricated in planar technology, and encapsulated in a hermetically sealed leaded glass DO-35 package.

    SIM900L GSM module:

    How to build an SMS based metal detector: SIM900L GSM shield module
    SIM900L GSM shield module

    SIM900L GSM/GPRS shield is a GSM modem. It allows  what a normal cell phone can do: Make or receive phone calls, connect to internet through GPRS, TCP/IP, and more. It supports quad-band GSM/GPRS network, meaning it works pretty much anywhere in the world. The shield itself was designed to surround the SIM900L chip. We needed this module in this How to Build an SMS Based Metal Detector design so that it can allow us send short massage service (SMS) easily.

    SIM900L GSM shield module part identification
    pin diagram of SIM900L courtesy of lastminuteengineers

    900L Shield LED Status Indicators

    900L Shield LED Status Indicators:
    900L Shield LED Status Indicators

    The LEDs blinking statuses on the SIM900L board has different interpretation. The LEDs on the board is two, namely:

    • PWR: This LED is connected to the shield’s power supply line. If this LED is on, the shield is receiving power.
    • Status: This LED indicates SIM900’s working status. If this LED is on, the chip is in working mode.
    • Netlight: This LED indicates the status of our cellular network. It blinks at various rates to show what state it’s in.
      • off: The SIM900 chip is not running
      • 64ms on, 800ms off: The SIM900L chip is running but not registered to the cellular network yet.
      • 64ms on, 3 seconds off: The SIM900 chip is registered to the cellular network & can send/receive voice and SMS.
      • 64ms on, 300ms off: The GPRS data connection we requested is active.

    How to Build an SMS Based Metal Detector: Powering the SIM900L

    Depending on which state it’s in, the SIM900 can be a relatively power-hungry device. The maximum current draw of the chip is around 2A during transmission burst. It usually won’t pull that much, but may require around 216mA during phone calls or 80mA during network transmissions.

    The power button on the SIM900L GSM module
    The PWRKEY button of the Sim900L

    To use the SIM900L, we hard to turn on the chip. To do this we had to press and hold (for a few seconds) the ON button by the side as shown in the figure above. But we needed to turn on the GSM module every time we power on the design. To do this we had to use the software trigger version of turn on the GSM  module. We first connected the D9 of the SIM900L to D9 of the MCU. Next we soldered the SMD jumper as shown in the figure below:

    GSM module
    the solder jumper to be joined together.

    Interfacing GSM module Sim900L with MCU:

    Using the UART Communication:

    The SIM900 GSM/GPRS shield uses universal asynchronous receiver-transmitter (UART) protocol to communicate with the MCU. The chip supports baud rate from 1200bps to 115200bps with Auto-Baud detection.

    SMS based metal detector
    Two options of connections: software serial and hardware serial select pins
    How to Build an SMS Based Metal Detector: the circuit diagram

    Afer ensuring that the jumper cap is placed on the software serial port select, we connected the MCU according to the circuit diagram shown in figure below.

    How to Build an SMS Based Metal Detector: the circuit diagram
    How to Build an SMS Based Metal Detector: the circuit diagram

    Although the GSM module could also work on 5V DC but we connected the sim900L to an external power of source of not less than 7V 2A supply. The module adjustable voltage regulator makes it possible for it to handle the voltage at this level.

    We used a 2G full sized SIM card and inserted it at the back of the module in its SIM socket. We were careful enough to unlock the latch, push the top part of the assembly, and then lift it up.  We Placed the SIM card into the bottom part of the socket. Then fold the arm back into the body of the socket, and gently push it forward towards the LOCK position.

    The SIM slot
    the SIM slot for SIM900 Module

    Hence, the new circuit diagram would be thus:

    How to Build an SMS Based Metal Detector: the circuit diagram
    the connection of the circuit diagram

    5V Passive Buzzer

    piezo speakers or buzzer
    passive buzzer type used in the design

    Generating pulse from the Microcontroller:

    Circuit diagram of the pulse generator for the metal detector
    circuit diagram of the MCU pulse generator

    We send a pulse from our microcontroller to the RL high pass filter, as such, short spikes will be generated by the coil in every transition. The pulse length of the generated spikes is proportional to the inductance of the coil. So with the help of these spike pulses we can measure the inductance of Coil. But here it is difficult to measure inductance precisely with that spikes because that spikes are of very short duration. We used a capacitor to solve this problem which is charged by the rising pulse or spike. And it required few pulses to charge the capacitor to the point where its voltage can be read by analog pin ADC0. And the microcontroller reads the voltage of this capacitor by using ADC syntax. After reading voltage, capacitor quickly discharged since we made it an output and setting it to LOW. This whole process takes around 200 microseconds to complete. For better result, we repeat measurement and took an average of the results. That’s how we can measure the approximate inductance of Coil. After getting the result we transfer the results to the LED and buzzer to detect the presence of metal.

    Arduino Source Code (Sketch)

    In our program for how to build an SMS-based metal detector project design, to be uploaded into the MCU, we created a function where we can turn on the sim900L using a software trigger. The syntax for the program was:

    Testing Attention (AT) Commands:
    For sending AT commands void SIM900power(){
      pinMode(9, OUTPUT); 
      digitalWrite(9,LOW);
      delay(1000);
      digitalWrite(9,HIGH);
    }
    
    

    Testing Attention (AT) Commands:

    For sending AT commands and communicating with the SIM900 shield, we will use the serial monitor. Below codes are the the syntax that will enable the MCU to communicate with the SIM900 shield on serial monitor window.

    //since we were using the software serial, we added the library
    #include <SoftwareSerial.h>
    
    //Create software serial object to communicate with SIM900
    //SIM900 Tx & Rx is connected to MCU #7 & #8
    SoftwareSerial mySerial(7, 8); 
    
    void setup()
    {
      //Begin serial communication 
      Serial.begin(9600);
      
      //Begin serial communication with MCU and SIM900
      mySerial.begin(9600);
    
      Serial.println("Initializing...");
      delay(1000);
    
    //Handshaking with SIM900
      mySerial.println("AT");   
    updateSerial();
    //Signal quality test, value range is 0-31 , 31 is the best
      mySerial.println("AT+CSQ"); 
      updateSerial();
    //Read SIM information to confirm whether the SIM is plugged
      mySerial.println("AT+CCID"); 
      updateSerial();
    //Check whether it has registered in the network
      mySerial.println("AT+CREG?");
      updateSerial();
    }
    
    
    void loop()
    {
      updateSerial();
    }
    
    
    void updateSerial()
    {
      delay(500);
      while (Serial.available()) 
      {
    //Forward what Serial received to Software Serial Port
        mySerial.write(Serial.read());
      }
      while(mySerial.available()) 
      {
    //Forward what Software Serial received to Serial Port
        Serial.write(mySerial.read());
      }
    }
    
    

    Source Code Explanation

    AT – It is the most basic AT command. It initializes Auto-baud’er.  When this command worked, we saw its characters echo, telling us that it understood us correctly. This paved way for us to use some other commands to query the GSM module and get information like:

    AT+CSQ – meaning check signal strength query; it checks the ‘signal strength’ – the first number is dB strength, it should be higher than around 5. For us, being higher is better. This our length and type of antenna and location played a very vital role in that.

    AT+CCID –  this command gets the SIM card number – it tests that the SIM card is found OK and using it we verified the number written on the card.

    AT+CREG? This command checks if the SIM is on a registered network    Check that you’re registered on the network. The second number should be 1 or 5.  If 1, it showed that our SIM was on a registered home network and 5 indicates roaming network. Any other number than these two numbers showed our SIM was not registered to any network.

    Internally Charging the LiPo Batteries

    The schematic diagram of the SMS based metal detector design
    The schematic diagram of the SMS based metal detector design

    Circuit Diagram Explanation

    The Power Supply for the design consist of two LiPo 4.2V 3800mAH batteries connected in series. In order to recharge these batteries we had to use a single 4.2 1A charger and connected the outputs in parallel the batteries terminals. But the series connection posed a problem so we had to add two switches that would open the series connection when it is time for charging and close it when we are not charging the batteries as shown above.

    The microcontroller uses 5V DC supply and the 8.4V formed by the series connection of the two batteries would only fry it. So we used a step-down converter of a 78xx series family viz; LM323T. It regulated the input voltage to a steady 5V output at 2A current for the Vcc of the MCU.

    The Complete Source Code

    #include <SoftwareSerial.h>
    
    SoftwareSerial mySerial(7, 8);
    
    int Seven = 10;
    #define capPin A1
    #define buz 11
    #define pulsePin A0
    #define led 12
    #define ledRead 6
    #define led2 5
    
    long sumExpect=0; //running sum of 64 sums
    long ignor=0; //number of ignored sums
    long diff=0; //difference between sum and avgsum
    long pTime=0;
    long buzPeriod=0;
    
     
    void setup()
    {
      mySerial.begin(9600);   // Setting the baud rate of GSM Module  
      Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
      pinMode(Seven, INPUT);
      delay(100);
    pinMode(pulsePin, OUTPUT);
    digitalWrite(pulsePin, LOW);
    pinMode(capPin, INPUT);
    pinMode(buz, OUTPUT);
    pinMode(ledRead, INPUT);
    pinMode(led2, OUTPUT);
    digitalWrite(buz, LOW);
    pinMode(led, OUTPUT);
    
    pinMode(9, OUTPUT); 
    //this turns on the sim900 automatcally
      digitalWrite(9,LOW);
      delay(1000);
      digitalWrite(9,HIGH);
      delay(2000);
      digitalWrite(9,LOW);
      //wait for 3sec
      delay(3000);
    }
    
    void SendMessage()
    {
      mySerial.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
      delay(1000);  // Delay of 1000 milli seconds or 1 second
      mySerial.println("AT+CMGS=\"+2347062174135\"\r"); // Replace this with mobile number
      delay(1000);
      mySerial.println("A METAL HAS BEEN DETECTED,SEARCH VERY WELL ");// The SMS text we sent out
      delay(100);
       mySerial.println((char)26);// ASCII code of CTRL+Z
      delay(1000);
    }
    
    
     void RecieveMessage()
    {
      mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
      delay(1000);
     }
     
    
    void applyPulses()
    {
    for (int i=0;i<3;i++)
    {
    digitalWrite(pulsePin,HIGH); //take 3.5 uS
    delayMicroseconds(3);
    digitalWrite(pulsePin,LOW); //take 3.5 uS
    delayMicroseconds(3);
    }
    }
    
    
    void loop(){
    int pinSeven = digitalRead(Seven);
    
    if (Serial.available()>0)  { 
        
        }
        
     if(pinSeven == HIGH){
      
      int minval=1023;
    int maxval=0;
    long unsigned int sum=0;
         
      for (int i=0; i<256; i++)
    {
    //reset the capacitor
    pinMode(capPin,OUTPUT);
    digitalWrite(capPin,LOW);
    delayMicroseconds(20);
    pinMode(capPin,INPUT);
    applyPulses();
    //read the charge of capacitor
    int val = analogRead(capPin); //takes 13x8=104 microseconds
    minval = min(val,minval);
    maxval = max(val,maxval);
    sum+=val;
    long unsigned int cTime=millis();
    char buzState=0;
    if (cTime<pTime+10)
    {
    if (diff>0)
    buzState=1;
    else if(diff<0)
    buzState=2;
    }
    if (cTime>pTime+buzPeriod)
    {
    if (diff>0)
    buzState=1;
    else if (diff<0)
    buzState=2;
    pTime=cTime;
    }
    if (buzPeriod>300)
    buzState=0;
    if (buzState==0)
    {
    digitalWrite(led, LOW);
    noTone(buz);
    }
    else if (buzState==1)
    {
    tone(buz,2000);
    digitalWrite(led, HIGH);
    
    }
    else if (buzState==2)
    {
    tone(buz,500);
    digitalWrite(led, HIGH);
    
    }
    
    }
    //subtract minimum and maximum value to remove spikes
    sum-=minval;
    sum-=maxval;
    if (sumExpect==0)
    sumExpect=sum<<6; //set sumExpect to expected value
    long int avgsum=(sumExpect+32)>>6;
    diff=sum-avgsum;
    if (abs(diff)<avgsum>>10)
    {
    sumExpect=sumExpect+sum-avgsum;
    ignor=0;
    }
    else
    ignor++;
    if (ignor>64)
    {
    sumExpect=sum<<6;
    ignor=0;
    }
    if (diff==0)
    buzPeriod=1000000;
    else
    buzPeriod=avgsum/(2*abs(diff));
    }
    
    if((digitalRead(ledRead) ==HIGH) && (pinSeven == HIGH)){
      SendMessage();
      
    }
    
    
    
     else{
          
      }
    
      if (mySerial.available()>0)
       Serial.write(mySerial.read());
    
    }
    

    Why SMS Alerts are Critical in Metal Detectors?

    SMS alerts offer a significant advantage over traditional metal detectors because they provide real-time notifications, even if you’re not physically present. In high-security environments, receiving an SMS immediately after metal detection allows for quicker action and response. For example, in an airport setting, SMS alerts can notify the security team about unauthorized metal objects, reducing the chances of a security breach.

    Enhancing the SMS-Based Metal Detector

    If you want to take this project to the next level, here are some advanced features you can consider:

    • Integrating IoT: By connecting your system to a cloud platform, you can monitor detections remotely and maintain a database of all alerts.
    • Multiple Sensors: Add more metal detection sensors to cover larger areas.
    • Security Cameras: Integrate a camera to capture images or video whenever metal is detected.

    Practical Applications of an SMS-Based Metal Detector

    • Public Security: Ideal for airports, malls, or other places with high foot traffic.
    • Private Security: Use in homes, offices, or businesses to prevent unauthorized metallic objects from entering.
    • Industrial Use: Detecting metal theft or unauthorized tools in warehouses or factories

    Challenges and How to Overcome Them

    Detection Range Issues

    • Ensure that the sensor’s range is appropriate for your application. If the sensor is too sensitive or not sensitive enough, recalibrate it or consider using a different sensor.

    Power Supply Limitations

    • If you’re using the system in a remote location, consider using a solar panel or a larger battery to provide continuous power.

    False Alarms

    • To reduce false positives, make sure the sensor is properly calibrated and placed in an area where there is minimal metal interference.

    Conclusion

    We have done justice to the design of how to build an SMS-based metal detector project. What do you think? Can you build similar a project design? Let us know in the comment section if you followed this guide to achieve a successful project work. You can contact us and send us pictures and videos of your project design on WhatsApp, Twitter, Telegram, Instagram to and send us pictures or ask questions too.

    Read More

    Frequently Asked Questions (FAQs)

    Can I use this system for detecting other materials besides metal?

    • No, this system is specifically designed to detect metals. Different sensors would be required for other materials.

    How do I troubleshoot when my system doesn’t send SMS alerts?

    • Check the GSM module connections, ensure the SIM card has sufficient balance, and verify the network signal.

    Can I use a different Arduino board besides Arduino Uno?

    • Yes, you can use other Arduino boards like Nano or Mega, but the code and wiring may need minor adjustments.

    How far can the metal detector sense metal objects?

    • The detection range depends on the type of sensor used, typically ranging from a few centimeters to several meters.

    Is it possible to integrate this system with a security camera?

    • Yes, you can connect this system with a security camera by adding a relay module that triggers the camera when metal is detected.
  • How to design Motion Detector Smart Street Lights System.

    How to design Motion Detector Smart Street Lights System.

    The goal of the project on “How to Design Motion Detector Smart Street Lights System is to control the amount of energy used when illuminating the pathways for motorists and pedestrians alike at night. At night, a lot of energy is usually used up to keep the street lights on all night. Most of the time, the illumination on these paths is not necessarily needed as there will be nobody using the roads. This project demonstrates how to design a motion detector smart street light system project so that it is smart enough to notice the movement of objects around it and light up the path so that people can see properly.

    Introduction to Smart Street Lights

    Motion Detector Smart Street Lights System
    Motion Detector Smart Street Lights System

    Smart street lights are an innovative solution designed to enhance urban infrastructure by integrating advanced technologies into traditional street lighting systems. These lights are equipped with sensors, communication modules, and control systems that allow them to operate more efficiently and adapt to real-time conditions. By leveraging technologies such as IoT (Internet of Things), smart street lights can adjust their brightness based on ambient light levels, detect motion, and even communicate with other smart devices. This not only improves energy efficiency but also enhances public safety and reduces maintenance costs.

    Importance of Motion Detection in Street Lighting

    Motion detection is a crucial feature in smart street lighting systems as it significantly contributes to energy conservation and public safety. By using motion sensors, such as Passive Infrared (PIR) sensors, street lights can automatically illuminate when they detect movement, ensuring that areas are well-lit only when necessary. This targeted lighting approach reduces energy consumption by preventing lights from being on continuously, thereby lowering electricity costs and minimizing environmental impact. Additionally, motion-activated lights can deter criminal activities and enhance the safety of pedestrians and drivers by providing adequate illumination only when needed.

    Materials/Components

    This smart street light control system project makes use of the Atmega328P-PU microcontroller, a motion detector sensor like a PIR sensor, and some AC light bulbs to sense the presence of pedestrians and illuminate their paths for them. For this project, we are going to need the following materials:

    • 12v solid state relays………………………………………………………3pcs
    • Atmega328P-PU microcontroller…………………………………….1pcs
    • AC light bulbs 220/240V 200W………………………………………3pcs
    • 12V power adapter………………………………………………………1pcs
    • 5V or 12V 3-channel relay module……………………………………………….1pcs

    You can buy the complete kit from our online store. or chat with us privately on WhatsApp.

    The Circuit Diagram

    To begin, we need to construct our MCU board. Read this previous post of ours to know how to build your own working standalone Arduino board. It would be very wise, however, to make sure that the power supply unit or DC supply adapter outputs enough current to power all the parts that run on DC.

    how to design motion detector smart street lights circuit diagram
    Motion detector smart street lights circuit diagram

    Circuit Diagram Explanation

    From the street light sensor circuit above, the power supply is producing 5V at 1A for the MCU, PIR sensors, and the 5V 3-channel relay module.

    The MCU board is configured to control the 3-channel relay module through input/output (IO) pins 5, 6 and 7 respectively. While the PIR sensors are controlled via IO pins 8, 9 and 10 respectively.

    The LDR sensor for this street light (Light Dependent Resistor), which we used here as optical sensor to differentiate when it is dark and when it is daytime, is connected to analog input pin 0 (A0) but voltage divider theorem (since the LDR is connected in series with a 10kΩ fixed resistor). The whole idea of this connection is to measure the rate of change in analog voltage as the resistance of the LDR changes due to the amount of light on its surface. The type of LDR used in this how to design motion detector smart street light system project has a negative coefficient of resistance; which means that as the amount of light on its flat surface increases, the resistance across it decreases.

    read also Receding Hairline 101: Causes, Solutions, and Tips for Prevention

    Source Code (Arduino Sketch)

    The how to design motion detector smart street light system project would achieve its objective only when it is dark and when there is motion around it that needs to use the illumination it would give out. Hence, we write our program for the smart street project on the Arduino platform again as:

    //Arduino source-code for Motion Detector Smart Street Light System project//
    //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
    int calibrationTime = 10;    
    
    //the time when the sensor outputs a low impulse
    long unsigned int lowIn;        
    //the amount of milliseconds the sensor has to be low 
    //before we assume all motion has stopped
    long unsigned int pause = 200;  
    
    boolean lockLow = true;
    boolean takeLowTime; 
    
    //the digital pin connected to the PIR sensor's output
    int pirPin1 = 10; 
    int pirPin2 = 11;
    int pirPin3 = 12;
    int relay1 = 7;
    int relay2 = 8;
    int relay3 = 9;
    int LDRVcc = 6;
    
    
    void setup() {
    /*we declare the input and output pins of the sensors 
    and actuators connected to d MCU */
    
      pinMode(pirPin1, INPUT);
      pinMode(pirPin2, INPUT);
      pinMode(pirPin3, INPUT);
      pinMode(relay1, OUTPUT);
      pinMode(relay2, OUTPUT);
      pinMode(relay3, OUTPUT);
    pinMode(LDRVcc, OUTPUT);
    
    //we wanted the LDR to kick start when the MCU is up and running, 
    //hence, we energized with one of the IO pins of the MCU.
    //using a HIGH command
     digitalWrite(LDRVcc, HIGH);
    //we start the serial monitor to see the readings of the sensors
     Serial.begin(9600); 
     //give the PIR sensor some time to calibrate
      Serial.print("calibrating sensor ");
    //for the calibration sequence that is displaying, we used a for loop
        for(int i = 0; i < calibrationTime; i++){
          Serial.print(".");
          delay(50);
    }
    }
    
     
     void loop(){
      //We start reading signals from the LDR connected to analog pin 0.
      int lightSense = analogRead(0);
    //we print these readings on the serial monitor
      Serial.println(lightSense);
    //with a delay of 0.5s between each value displayed
      delay(500);
    //Using a simple if-statement we 
      if(lightSense <= 300) {
        if(digitalRead(pirPin1) == HIGH){
    //the led visualizes the sensors output pin state
           digitalWrite(relay1, HIGH);   
           if(lockLow){  
             //makes sure we wait for a transition to LOW before any further output is made:
             lockLow = false;            
            
             }         
             takeLowTime = true;
        }
    
    else if(digitalRead(pirPin1) == LOW){       
           digitalWrite(relay1, LOW);  //the led visualizes the sensors output pin state
    
           if(takeLowTime){
            lowIn = millis();          //save the time of the transition from high to LOW
            takeLowTime = false;       //make sure this is only done at the start of a LOW phase
            }
           //if the sensor is low for more than the given pause, 
           //we assume that no more motion is going to happen
           if(!lockLow && millis() - lowIn > pause){  
               //makes sure this block of code is only executed again after 
               //a new motion sequence has been detected
               lockLow = true;                        
               
               }
           }
    
           if(digitalRead(pirPin2) == HIGH){
           digitalWrite(relay2, HIGH);   //the led visualizes the sensors output pin state
           if(lockLow){  
             //makes sure we wait for a transition to LOW before any further output is made:
             lockLow = false;            
            
             }         
             takeLowTime = true;
    
        }
    else if(digitalRead(pirPin2) == LOW){  
    //the led visualizes the sensors output pin state
           digitalWrite(relay2, LOW);  
           if(takeLowTime){
    //save the time of the transition from high to LOW
            lowIn = millis();      
    //make sure this is only done at the start of a LOW phase    
            takeLowTime = false;               }
           //if the sensor is low for more than the given pause, 
           //we assume that no more motion is going to happen
           if(!lockLow && millis() - lowIn > pause){  
               //makes sure this block of code is only executed again after 
               //a new motion sequence has been detected
               lockLow = true;                        
               
               }
           }
    
    if(digitalRead(pirPin3) == HIGH){
           digitalWrite(relay3, HIGH);   //the led visualizes the sensors output pin state
           if(lockLow){  
             //makes sure we wait for a transition to LOW before any further output is made:
             lockLow = false;            
            Serial.println("---");
            Serial.print("motion detected at ");
             Serial.print(millis()/1000);
             Serial.println(" sec"); 
             delay(50);
             }         
             takeLowTime = true;
    
        }
    
    else if(digitalRead(pirPin3) == LOW){  
    //the led visualizes the sensors output pin state     
           digitalWrite(relay3, LOW);  
    
           if(takeLowTime){
    //save the time of the transition from high to LOW
            lowIn = millis();   
    //make sure this is only done at the start of a LOW phase       
            takeLowTime = false;       
            }
           //if the sensor is low for more than the given pause, 
           //we assume that no more motion is going to happen
           if(!lockLow && millis() - lowIn > pause){  
               //makes sure this block of code is only executed again after 
               //a new motion sequence has been detected
               lockLow = true;                        
               
               }
           }
        delay(50);
      }
       
      
      if (lightSense >= 301 ) {
        digitalWrite(relay1, LOW);
        digitalWrite(relay2, LOW);
        digitalWrite(relay3, LOW);
        if(takeLowTime){
    //save the time of the transition from high to LOW
            lowIn = millis(); 
    //make sure this is only done at the start of a LOW phase         
            takeLowTime = false;       
            }
           //if the sensor is low for more than the given pause, 
           //we assume that no more motion is going to happen
           if(!lockLow && millis() - lowIn > pause){  
               //makes sure this block of code is only executed again after 
               //a new motion sequence has been detected
               lockLow = true;                        
               
    
      }
    
      }
     }
    
    

    Further Explanation of Arduino Sketch:

    We declared all our variables from line 3 through line 21, the calibration time  for the PIR sensors was to 10 seconds according to the datasheet of the product. But the sensor emits a pulse and waits for an obstacle to reflect it by cutting into its line of projection. So we used a long variable unsigned to denote this. In the loop function, we have already noticed that during dark, the LDR displays values that are below 300 and when it experiences sufficient amount across its surface, its values rises way above 300. Using the if-statement we made a comparison as regards to when the latter following lines would be executed. The rest of the algorithm used for the Motion Detector Smart Street Lights System project are explained using comment line. And notice there is a repeated pattern for the three PIRs.

    Connecting the AC Lamps

    The AC bulbs are connected as shown in the circuit diagram. The relays: relay1, relay2 and relay3 acts as the bridge between the DC and the AC voltage. In other words for the AC bulbs to be turned on, the relays must be energized. The relay energizing voltages were rated 5V but 12V solid state relays are recommended to avoid arching between switching poles of the relays and burning out the filaments of the tungsten bulbs.  A better choice would to go for energy saving lamps that uses AC to DC converters.

    The working video is shown in the embed YouTube below.

    The working video of the Motion Detector Smart Street Lights System project

    The video demonstration shows that the model for this project was done on a copy off of a major type A road that has motion sensors attached to the base of each street light system. when movement was sensed, these street light come on and would go off in the absence of motion. The model was portable and made to be easily set up in less time frame.

    Conclusion

    We have done justice to How to design motion detector smart street lights system. What do you think? Can you build similar a project design? Let us know in the comment section if you followed this guide to achieve a successful project work. You can contact us and send us pictures and videos of your project design on WhatsApp, Twitter, Telegram, Instagram to and send us pictures or ask questions too.

    Read More

    FAQs

    Q1: Can this system work outdoors?
    Yes, but the PIR sensor must be weatherproof.

    Q2: Can solar power be used?
    Absolutely. A solar panel + battery makes it perfect for outdoor areas.

    Q3: Does the system detect animals?
    Yes. PIR sensors detect heat signatures from humans and animals.

    Q4: Can this system be expanded?
    Yes — IoT features (ESP32/NodeMCU) can be added to monitor lights remotely

  • How to Use Infrared (IR) receiver module with Arduino Microcontroller

    How to Use Infrared (IR) receiver module with Arduino Microcontroller

    In today’s post, we will be using the infrared (IR) receiver sensor module to detect infrared signals from an old TV remote and use the HEX file generated when we send signals to the IR receiver sensor module to control simple displays like LEDs and perhaps later use it to control an electric fan. In this tutorial, how to use an Infrared (IR) receiver module with Arduino Development Board, we will cover understanding the IR receiver module and how to interface with the Arduino Uno. So let’s jump right into it. The Infrared (IR) receiver module with Arduino

    How to Use Infrared (IR) receiver module with Arduino Microcontroller
    How to Use Infrared (IR) receiver module with Arduino Microcontroller

    How to Use Infrared (IR) receiver module with Arduino: Materials Needed:

    The Circuit Diagram

    The IR receiver module has three terminals shown and named in the figure below:

    Infrared (IR) receiver module with Arduino: The IR sensor
    Infrared (IR) receiver module with Arduino: The IR sensor

    From top-left to bottom-right, the first pin S is the pin we connect to any of the digital pins or analog pins of our choice on the Arduino development board. The second pin is the Vcc pin that is hooked up to the +5V  of the Arduino development board. The third and last pin is the ground, which is connected to the header port labeled GND on the Arduino board.  The connection on breadboard is thus:

    Infrared (IR) receiver module with Arduino: The circuit diagram connection
    Infrared (IR) receiver module with Arduino: The circuit diagram connection

    From the breadboard, the 5V output of the Arduino board is connected to pin 2 of the IR receiver module, both the IR receiver module and Arduino Uno board have a common ground.

    Step-by-Step To Program the Infrared (IR) receiver module with Arduino Project

    Get Your Arduino Board Ready

    Programming the Arduino board
    Programming the Arduino board

    Next, plug in your Arduino communication cable into the USB port of your PC, open your Arduino IDE, click  File, create a new file, and you can name it whatever you want, and save your sketch.

    Download and Import the Necessary Libraries for the Infrared (IR) receiver module with Arduino

    We saved ours with IR_Receiver_Test. You might want to do the same.

    To use the Infrared remote on the Arduino, we need to import a special library, known as the IRremote. Once downloaded from the github page, click on the  sketch tab, include library, and Add ZIP library.

    Infrared (IR) receiver module with Arduino: Importing a library in Arduino IDE
    Infrared (IR) receiver module with Arduino: Importing a library in Arduino IDE

    In the list of libraries, you will find your new added library, IRremote, quickly add then and copy the code below to get your HEX codes.

    The Arduino Source Code

    #include <boarddefs.h>
    #include <IRremote.h>
    #include <IRremoteInt.h>
    #include <ir_Lego_PF_BitStreamEncoder.h>
    
    //state the IR input to the MCU
    #define RECV_PIN A1
    //make it recognised to IR Lib
    IRrecv irrecv(RECV_PIN);
    //ask it it get results and save it
    decode_results results;
    
    void setup() {
      //enable the IR
      irrecv.enableIRIn();
      //begin the serial monitor comm
      Serial.begin(9600);
    }
    
    void loop() {
     if(irrecv.decode(&results)) 
      {
         irrecv.resume();
        //print the remote results in HEX codes
         Serial.println(results.value, HEX);
      }
    

    Source Code Explanation

    Basically, the code is used to generate your HEX codes from pointing and depressing any key on the home remote guide at the IR receiver sensor module. The brief explanation to it is thus: From line 1 to line 4, we included the IR remote libs, Only the IRremote.h header file is enough but it felt good leaving all the others there. Next, we defined the pin on the Arduino where we are connecting the signal pin of the IR of receiver, this we called Recv_Pin and we connected to analog pin 1, A1. Then we make it recognizable to the library. In the setup function, we enabled the IR receiver and begin the serial monitor and set our communication speed between the computer and the Arduino board with Serial.begin(9600) code line. In the loop function, we ask the Arduino to get results and display it on the serial monitor.

    After this, we verify the code and upload it and wait while it finishes uploading.

    Infrared (IR) receiver module with Arduino: Importing a library in Arduino IDE
    Infrared (IR) receiver module with Arduino: uploading the code

    Open your serial monitor, by clicking on tools, serial monitor. Alternatively, you could click on the white search box.

    Opening the serial monitor in Arduino IDE
    Opening the serial monitor in Arduino IDE

    We then start getting the HEX code for each keypad on the TV remote, each key we press when we point at the IR receiver would display its own HEX code.

    How to Use Infrared (IR) receiver module with Arduino
    How to Use Infrared (IR) receiver module with Arduino

    Now we can use this HEX codes to play around with the displays of our LEDs. We connected four LEDs as shown in the breadboard connection below:

    Turning on LEDs using a remote control
    Turning on LEDs using a remote control

    Before we go back to our sourcecode to make some changes, we want to pick three different buttons on the old TV remote we want to use to cause changes to the way the LEDs display. after making this choice, we should save their HEX codes somewhere because we are going to be using it to in our next step.

    Conditional If statements, and for loops

    The if statements we would use here would help us to make comparisons and change the current state of the LEDs to another state when we want them. whereas the for loops would iterate our output LEDs as long as the conditions used in it is true. Otherwise it would stop executing the line of code in it.

    #include <boarddefs.h>
    #include <IRremote.h>
    #include <IRremoteInt.h>
    #include <ir_Lego_PF_BitStreamEncoder.h>
    
    //state the IR input to the MCU
    #define RECV_PIN A1
    //make it recognised to IR Lib
    IRrecv irrecv(RECV_PIN);
    //ask it it get results and save it
    decode_results results;
    
    void setup() {
      //enable the IR
      irrecv.enableIRIn();
      //begin the serial monitor comm
      Serial.begin(9600);
      for(int i = 9; i < 14; i++){
      pinMode(i, OUTPUT);
      
      }
    }
    
    void loop() {
      
        if(irrecv.decode(&results)) 
      {
         irrecv.resume();
        //print the remote results in HEX codes
         Serial.println(results.value, HEX);
      }
      if(results.value == 0x4C){
      for(int i=9; i <14; i++){
        digitalWrite(i, HIGH);
        delay(250);
          }
          for(int i=9; i <14; i++){
        digitalWrite(i, LOW);
        delay(250);
          }
      }
      delay(1000);
    }
    

    Source Code Explanation

    What the sketch does from code line 18 is; make the digital pins from digital pin 9 to digital pin 13 outputs using a for loop. Line 28 through 30 ask the Arduino Microcontroller to get the HEX codes sent from the IR transmitter of the home TV remote and print it out on the Serial monitor screen.

    Line 32 through 42 uses the same if statement and comparism but with two for loops to check for when a specific button on the home TV remote is press and display the LEDs in a certain effect.

    To use more buttons of the TV remote to display different effects, we use this sketch below:

    #include &lt;boarddefs.h>
    #include &lt;IRremote.h>
    #include &lt;IRremoteInt.h>
    #include &lt;ir_Lego_PF_BitStreamEncoder.h>
    
    //state the IR input to the MCU
    #define RECV_PIN A1
    //make it recognised to IR Lib
    IRrecv irrecv(RECV_PIN);
    //ask it it get results and save it
    decode_results results;
    
    void setup() {
      //enable the IR
      irrecv.enableIRIn();
      //begin the serial monitor comm
      Serial.begin(9600);
      for(int i = 9; i &lt; 14; i++){
      pinMode(i, OUTPUT);
      
      }
    }
    
    void loop() {
      
        if(irrecv.decode(&amp;results)) 
      {
         irrecv.resume();
        //print the remote results in HEX codes
         Serial.println(results.value, HEX);
      }
      if(results.value == 0x4C)
      for(int i=9; i &lt;14; i++){
        digitalWrite(i, HIGH);
        delay(250);
          }
          for(int i=9; i &lt;14; i++){
        digitalWrite(i, LOW);
        delay(250);
          }
    
          if(results.value == 0x876){
            digitalWrite(11, HIGH);
            delay(200);
            digitalWrite(10, HIGH);
            digitalWrite(12, HIGH);
            delay(200);
            digitalWrite(13, HIGH);
            digitalWrite(9, HIGH);
            delay(500);
            digitalWrite(13, LOW);
            digitalWrite(9, LOW);
            delay(200);
            digitalWrite(10, LOW);
            digitalWrite(12, LOW);
            delay(200);
            digitalWrite(11, LOW);
                 }
         if(results.value == 0x877){
          digitalWrite(13, HIGH);
          delay(200);
          digitalWrite(13, LOW);
          delay(200);
          digitalWrite(12, HIGH);
          delay(200);
          digitalWrite(12, LOW);
          delay(200);
          digitalWrite(11, HIGH);
          delay(200);
          digitalWrite(11, LOW);
          delay(200);
          digitalWrite(10, HIGH);
          delay(200);
          digitalWrite(10, LOW);
          delay(200);
          digitalWrite(9, HIGH);
          delay(200);
          digitalWrite(9, LOW);
          delay(200);
         }
      
      delay(1000);
    }
    

    The HEX codes should be prefixed with:- 0x for the MCU to recognize your if statements as shown in the source codes above. You can watch the YouTube video of it here; or simply click on the clip below.

    IR receiver module with any TV remote

    Conclusion

    We have successfully designed and constructed the project, How to Use Infrared (IR) receiver module with Arduino. Do you think you can replicate the same thing? Or better make it smarter than our own. Let us know if you did this project. We will like to see a photograph or video. Leave us a comment below.

    Connect with us on Telegram, Instagram, Facebook page or WhatsApp.

    Frequently Asked Questions on How to Use Infrared (IR) receiver module with Arduino

    Basic Understanding

    • What is an IR receiver module?
      • An IR receiver module is an electronic component that detects infrared light signals, commonly used to receive signals from remote controls.  
    • How does it work?
      • The IR receiver converts incoming infrared light into electrical signals that can be processed by an Arduino.  
    • Can I power the IR receiver module directly from the Arduino’s 5V pin?
      • Yes, most IR receiver modules can be powered directly from the Arduino’s 5V pin. However, check the module’s datasheet for specific power requirements.
    • What type of IR remote control can I use?
      • Most standard TV remote controls will work. However, some specialized remote controls might require specific IR receiver modules.

    Coding and Programming

    • What libraries are available for decoding IR signals?
      • The IRremote library is a popular choice for decoding IR signals.
    • How do I decode the received IR signals?
      • The IRremote library provides functions to read and decode IR signals. You’ll typically need to capture the raw data and then decode it using the appropriate protocol (e.g., NEC, RC5).  
    • How do I differentiate between different buttons on the remote?
      • Each button on the remote sends a unique code. You can use the decoded data to identify which button was pressed.
    • How can I handle multiple IR remotes?
      • You can use multiple IR receiver modules and assign different pins to each. However, handling multiple remote controls simultaneously can be complex.
    • Why am I not receiving any IR signals?
      • Check the connections, power supply, and the orientation of the IR receiver. Ensure the remote control is pointing directly at the receiver.
    • Why am I getting inconsistent results?
      • Interference from other electronic devices can affect IR signals. Try shielding the IR receiver or using a different frequency.
    • How can I improve the range of the IR receiver?
      • Using a higher-gain IR receiver or amplifying the received signal can increase the range.
    • Can I use an IR receiver to transmit data?
      • While primarily used for receiving data, IR can also be used for transmission with specific hardware and coding.
    • How can I create my own IR remote control?
      • There are dedicated IR transmitter modules and libraries available for encoding data and transmitting IR signals.
    • What are some common IR protocols?
      • NEC, RC5, and Sony are some of the common IR protocols used in remote controls.
  • How to Make Automatic Remote Controlled AC Fan

    How to Make Automatic Remote Controlled AC Fan

    A step toward the “Internet of Things,” home automation is simple and enjoyable to construct with the correct tools. This home automation project specifically focuses on an automated remote-controlled air conditioning fan. That is, how to create a remote-controlled AC fan that is infrared (IR) regulated and automatically adjusts its temperature.

    This remote-controlled fan makes it easier to operate fan regulators from a distance across the house or workplace. It offers a system that is easy to comprehend and use, dependable, low maintenance, and long-lasting regardless of how it is used.

    automatic remote controlled AC Fan
    automatic remote controlled AC Fan

    Infrared radiation that produces Infrared signals or radiation (IR) are actually beams of light, it is that portion of the electromagnetic spectrum that extends from the long wavelength, or red, end of the visible-light range to the microwave range. Invisible to the eye, it can be detected as a sensation of warmth on the skin. Most of the radiation emitted by a moderately heated surface is infrared; it forms a continuous spectrum. Molecular excitation also produces copious infrared radiation, but in a discrete spectrum of lines or bands. Everything that produces heat, emits infrared like our human body. Infrared has the same properties as visible light, like it can be focused, reflected, and polarized like visible light. IR devices are those photonic components that contain semiconductor materials that are sensitive to IR radiation. They are divided into IR Transmitters (LED) and IR Receivers (IR).

    How It Works

    But first, a brief explanation on the basics of home automation and why this project design. This project aims to automate an AC fan by controlling its speed based on the room temperature. The fan will run at different speeds depending on the temperature detected by the sensor:

    • High Speed: When the temperature is high.
    • Medium Speed: When the temperature is moderate.
    • Low Speed: When the temperature is low.
    • Off: When the temperature is below a certain threshold.

    The fan also can be controlled by the user using a remote control. The infrared transmitter device is decoded by the IR receiver onboard the designed mounted on the Automatic Remote Controlled AC Fan project design.

    Components Needed:

    • Power Supply rated 5V, ≥ 2A or you can build your own here
    • Atmeg328p-pu microcontroller
    • 16MHz crystal oscillator (Newark part number 16C8140)
    • 10nF capacitors
    • A 10KΩ pull-up resistor
    • A reset push button.
    • Dallas temperature sensor DS18B20, maxim part number, 1534C4:
    • A 4.7KΩ pull-up resistor
    • Infrared receiver TSOP1738
    • IR remote controller or any old TV remote( that’s IR Transmitter)
    • 560Ω 5 band resistor
    • 1µF ceramic capacitor
    • Generic Jumper wires: male and female type.
    • 16 × 2 Liquid Crystal Display
    • 10KΩ potentiometer (trimmer)
    • 56OΩ precision resistor
    • LCD connector wires’
    • Header pins
    • 5V 4-channel Relay Module
    • A standing fan

    Buy the complete kit for this project design by contacting us here.

    The Circuit Diagram

    how to make an automatic remote controlled AC Fan
    The complete circuit diagram

    The Circuit Diagram Explanation

    The algorithms programmed into the microcontroller (MCU) chip have two objectives: first; if, say, the room temperature is too hot, it would switch to a speed that would make the room cold and cozy and if it is too cold, it would switch to a speed level that is comfortable or turn off totally. Mostly, if the user feels that he or she doesn’t like the speed of the fan, he or she can pick up a remote control and select the desired speed of choice; giving it a user-enabled option.

    When the part units are assembled together, the above circuit diagram was achieved. To keep the design working properly and achieve the desired goal, the MCU had to run a series of programs. Let’s break the circuit into units and explain each unit.

    Connecting the Temperature Sensor

    DS18B20 circuit diagram connection
    DS18B20 circuit diagram connection

    The temperature sensor DS18B20 is connected as shown in the circuit diagram above. You can choose to connect your data pin of the temperature sensor to any of your microcontroller pin of your choice, whether analog or digital pin. Just be sure to define it in your source code. It is also very important to add the 4.7kΩ pullup resistor. If this connection is omitted, the temperature sensor wouldn’t work and the displayed readings would be confusing like -127°C on the serial monitor window or LCD.

    Connecting the Relay Module Unit

    how to make an automatic remote controlled AC Fan
    the relay module

    The relay module unit is an arrangement of a electromagnetic switches and other discrete linear components that can sense very minimum current input and allow a high voltage to flow across its switch. The module as shown above is designed with an optocoupler which is made up of  LED and phototransistors; signal diodes for relay protection, general purpose NPN transistor and low value resistor.

    The relay module has four relays that works on the following operation: if we consider the first relay, having switch K1, the anode of the  LED in the optocoupler is connected to the +5v Vcc through a resistor R1. Also the Collector of the transistor Q1 is given a +5v having a common emitter connection to baise the coil of the relay. Current would flow through the anode of the LED and it would glow (although this was not seen since it was encased) thereby biasing base of the transistor which would then conduct, allowing current to flow through the Vcc at the collector and since the base of Q1 is already open through R2 to the -5v(ground). This would in turn energize the coils of the K1 and the pole would change from terminal 3((Normally closed, NC) to terminal 1 (Normally Open, NO) of the Relay. The other relays K2, K3 and K4 works on the same operation.

    IR Receiver Unit

    This unit as earlier mentioned is composed of the infrared receiver TSOP1738 that has three terminals with the Pin 3 connected to the HIGH of the PSU (+5 Vcc) supply and the Pin 2 connected to the ground terminal(or LOW) of the PSU while the Pin 1 is the output pin. It is called the data pin (or terminal) Do. To stop  the sensor (TSOP1738) from sending fluctuation signals to the MCU due to IR impulse from random sources, a very low capacitive capacitor isconnected from the data pin to the ground. This is shown below.

    how to make an automatic remote controlled AC Fan
    the IR module

    A Brief Explanation Of Hex Codes

    The Decimal number system is also known as Base Ten, since it’s comprised of ten numerals (symbolized by 0 through 9). Although we can only represent up to the number 9 by a single decimal digit, it’s possible to reference up to ten items by using zero ( 0) as an index to refer to the first ( 1st) item; thus, the numeral 9 would refer to the tenth ( 10th) item. With two digits we can refer to 100 items (zero through 99). In terms of the number of digits, 10 n (where n is the number of digits) equals the maximum number of items we can refer to. Therefore, the decimal equivalent of the largest binary number we can represent in 6 bits ( 111111 ) can be found as the sum of the first six powers of 2; starting with 2 to the power of zero (2 ^0): 20 + 21 + 2 2 + 23 + 24 + 25 = 1 + 2 + 4 + 8 + 16 + 32 = 63.

    Or, by simply using the formula: 2n – 1 = 64 – 1 = 63.

    To convert any binary number to hexadecimal, that is, base 16, simply order the bits into as many four-bit groups as possible, from the least significant position to the most significant position with any remaining group of only 3, 2 or 1 bits at the far left. Then convert each group to a single hex digit of 0 through 9 or A through F . So, to convert our 6-bit number of 111111 (63 decimal) to hex, we simply group the bits as: 111111 which is easily converted to: 3F hex. An 8-bit or 1-byte hexadecimal number can contain a maximum value of 255 decimal. A 10-bit binary number cannot exceed: 11 11111111 or 3FF  or 1023 decimal. But, the maximum number of Cylinders we can reference in 10 bits is 1024, since we begin counting from zero.

    A 32-bit unsigned integer value can be from 0 to 2(32-1). That is, from 0 to 2147483647.  Similarly, 64-bit unsigned integer value can be from 0 to 2(64-1). Now, 32-bit hex value can be from 0 to 0x7f f f f f f f There will be only 8 digits i.e. 7 f f f f f f f because 1 digit corresponds to 4 bit. Hence 8 digits correspond to 8×4 = 32 bits. So, this means the digits which are followed by 0x are hexadecimal. There are two important aspects to the beauty of using Hexadecimal with computers: First, it can represent 16-bit words in only four Hex digits, or 8-bit bytes in just two.

    The LCD Unit

    The liquid crystal display is a display module programmable, economical and can display special characters. A 16×2 LCD means it can display  16 characters per line and there are two of such lines. Each character is displayed in 5×7 pixel matrix. The LCD has two registers namely; Command and Data. The pins and their functions are explained as:

    • Register Select (RS): this pin selects Command register when low and Data register when high.
    • Read/Write (R/W): this pin writes to the register when low and reads from the register when high.
    • Enable (E): this pin sends data to the Data pins when a high to low pulse is given to it.
    • Pin 7 to 14 (D4 to D): these are 8-bit pins that are used to send and and receive data to/from the LCD.
    • Pin 15 ( ): this is the positive (+Vcc) backlight of the LED (LED+) of the LCD. This pin is usually connected with a pullup resistor ( ≤ 1kΩ). this is important to limit current flowing in the LEDs of the LCD.
    • Pin 16 (D16): this is the  negative (ground ) −−Vcc  pin. It is connected to the groud of the DC power supply.
    • The circuit connections is summarised as:
      •  * LCD RS pin to pin 18 (D12)
      •  * LCD Enable pin to pin 17 (D11)
      •  * LCD D4 pin to pin 12 (D5)
      •  * LCD D5 pin to pin 6 (D4)
      •  * LCD D6 pin to pin 5 (D3)
      •  * LCD D7 pin to pin 4 (D2)
      •  * LCD R/W pin to ground (-5V VDD)
      •  * LCD VSS pin to ground (-5V VDD)
      •  * LCD VCC pin to +5V (Vcc)
      •  * 10K resistor:
      •  * ends to +5V and ground
      •  * wiper to LCD VO pin (pin 3)

    The Source-Code

    #include <LiquidCrystal.h>
    //state which pins of the MCU connected 4 LCD
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    #include <OneWire.h>
    #include <DallasTemperature.h>
    #include <IRremote.h>
    //state where the input of the temp sensor is connected
    #define ONE_WIRE_BUS A0
    int led1 = 6;
    int led2 = 7;
    int led3 = 8;
    //set the OneWire lib to comm with other bus
    OneWire oneWire(ONE_WIRE_BUS);
    //transfer the data to Dallas temp Lib
    DallasTemperature sensors(&oneWire);
    //state the IR input to the MCU
    #define RECV_PIN A1
    //make it recognised to IR Lib
    IRrecv irrecv(RECV_PIN);
    //ask it it get results and save it
    decode_results results;
    void setup() {
       //begin the LCD to start displaying
      lcd.begin(20,4);
       //enable the IR
      irrecv.enableIRIn();
      //begin the temp sensor
      sensors.begin();
      //outline the inputs and output pins
    pinMode(led1, OUTPUT);
    pinMode(led2, OUTPUT);
    pinMode(led3, OUTPUT);
    //Serial.begin(9600);
    //Display a welcome note
    lcd.setCursor(0, 0);
    lcd.print("Welcome Chinny!");
    lcd.setCursor(0, 1);
    lcd.print("Smart FAN Project");
    delay(3000);
    lcd.setCursor(0, 1);
    lcd.print("Please Wait.......");
    delay(2000);
    lcd.setCursor(0, 1);
    lcd.print("Smart FAN Ready");
    delay(1000);
    }
    void SPEED1()
    {
           digitalWrite(led1, HIGH);
           digitalWrite(led2,LOW);
           digitalWrite(led3, LOW);
           lcd.setCursor(0, 1);
           lcd.print("FAN AT SPEED 1 ");
          //Serial.println("FAN AT SPEED 1");
     }
    void SPEED2()
    {
          digitalWrite(led1, LOW);
          digitalWrite(led2,HIGH);
          digitalWrite(led3, LOW);
          lcd.setCursor(0, 1);
          lcd.print("FAN AT SPEED 2 ");
          //Serial.println("FAN AT SPEED 2");
     }
     void SPEED3()
     {
          digitalWrite(led1, LOW);
          digitalWrite(led2,LOW);
          digitalWrite(led3, HIGH);
          lcd.setCursor(0, 1);
          lcd.print("FAN AT SPEED 3 ");
         // Serial.println("FAN AT SPEED 3");
     }
     void fan_off()
     {
          digitalWrite(led1, LOW);
          digitalWrite(led2,LOW);
          digitalWrite(led3, LOW);
          lcd.setCursor(0, 1);
          lcd.print("FAN TURNED OFF! ");
          //Serial.println("FAN TURNED OFF");
     }
    void tempSensor() {
      if(irrecv.decode(&results)) 
      {
         irrecv.resume();
        //print the remote results in HEX codes
         //Serial.println(results.value, HEX);
      }
      sensors.requestTemperatures();
      float roomTemp = sensors.getTempCByIndex(0);
      lcd.setCursor(0, 0);
      lcd.print("ROOM TEMP:");
      lcd.setCursor(10, 0);
      lcd.print(roomTemp);
      lcd.setCursor(14, 0);
      lcd.print("'C");
      if( roomTemp < 20.00 )
        {
          fan_off();
        }
       else if(roomTemp >= 20.01 && roomTemp <= 30.00)
        {
          SPEED1();
        }
       else if(roomTemp >= 30.01 && roomTemp <= 35.00)
        {
          SPEED2();
        }
       else
        {
          SPEED3();
        }
    }
    void remote()
    {
         if(results.value == 0x1266897) 
         {
          SPEED1();
         }
         else if(results.value == 0x1269867)
         {
          SPEED2();
         }
         else if(results.value == 0x126E817)
         {
          SPEED3();
         }
         else if(results.value == 0x12618E7)
         {
         fan_off();
         }
         else if(results.value == 0x126926D)
         {
          tempSensor();
         }
    }
    void loop() {
      sensors.requestTemperatures();
      float roomTemp = sensors.getTempCByIndex(0);
      lcd.setCursor(0, 0);
      lcd.print("ROOM TEMP:");
      lcd.setCursor(10, 0);
      lcd.print(roomTemp);
      lcd.setCursor(14, 0);
      lcd.print("'C");
      // Serial.print("ROOM TEMP: ");
      // Serial.print("  ");
      //Serial.println(roomTemp);
    if(irrecv.decode(&results)) 
      {
         irrecv.resume();
        //print the remote results in HEX codes
         //Serial.println(results.value, HEX);
      }
         if(results.value == 0x126926D)
         { 
            while((results.value == 0x126926D) ||((results.value != 0x1266897) && (results.value != 0x1269867) && (results.value != 0x126E817) && (results.value != 0x12618E7) && (results.value != 0x126926D)))
            tempSensor(); 
          }
           remote();
     delay(50);
    }
    

    Explanation of Arduino Code

    The program for how to make an automatic remote controlled AC Fan project records and stores the IR signals as HEX Values and it used only Hexadecimal to display the actual Binary bytes of a Memory Dump rather than a huge number of ones and zeros! The second aspect is closely related: Whenever it is necessary to convert the Hex representation back into the actual Binary bits, the process is simple enough to be done. For example, FAD7 hex is 1111101011010111 (F=1111, A=1010, D=1101, 7=0111) in Binary.

    Once the IR receiver was configured correctly as drawn in the circuit, and  was powered; using an old home TV remote as IR transmitter, specific button’s HEX codes were selected and mapped as commands into the MCU to control the fan speed controls.

    For example, for Speed  1, 0x1266897 is used. But by inputting it in the if statement, it makes the MCU to know which remote button controls what speed and which function.

    Conclusion

    We have successfully designed and constructed the project, how to make an automatic remote controlled AC Fan. And we have been able to use a home TV remote to control an alternating current (AC) standing fan. Do you think you can replicate the same project design? Or better make it smarter than ours? Let us know in the comment section below if you did this project. We will like to see a photograph or video too!

    Connect with us on Telegram, Instagram, Facebook page or WhatsApp.

    The video below shows the workings of the project design. Watch, like, and subscribe. Thanks you.

    FAQs

    Q1: Can I use a different temperature sensor? A1: Yes, you can use other temperature sensors like the DHT22 or LM35. You’ll need to adjust the code accordingly.

    Q2: Is it safe to control an AC fan with Arduino? A2: Yes, as long as you use a relay module to handle the high voltage and follow proper safety precautions.

    Q3: Can I add more speeds to the fan control? A3: Yes, you can modify the code to include more speed levels by adding additional relays and corresponding control logic.

    Q4: What type of IR remote can I use? A4: You can use any standard IR remote, such as an old TV remote. You’ll need to record the remote’s button codes for programming.

    Q5: Can I integrate this project with a smart home system? A5: Yes, with additional components like a WiFi module or Bluetooth, you can integrate the fan control into a broader smart home ecosystem.