ATtiny85 IR Remote Control for Room Automation
Table of Contents
ATtiny85 IR Remote Control:
ATtiny85 IR Remote Control for Room Automation- In this article, you will learn how to control your room appliances using the ATtiny85 microcontroller, a 4-channel Relay module, IR Sensor, and an IR Remote controller. Make sure you also have the Arduino board because you will need it for finding the IR remote button codes and for uploading the program into the ATtiny85 microcontroller. Instead of using the ATtiny85 microcontroller, you can also use Arduino, ESP32 WiFi + Bluetooth module, Nodemcu ESP8266 WiFi module, Raspberry Pi Pico, and so on.
The ATtiny85 microcontroller has several advantages-
- Size and cost: The ATtiny85 is a very small microcontroller, which makes it ideal for use in small and cost-sensitive projects where space and budget are a concern. In comparison, Arduino boards are relatively large and more expensive.
- Low power consumption: The ATtiny85 has a very low power consumption, which makes it ideal for use in battery-powered devices that need to run for a long time. Arduino boards, on the other hand, consume more power and may not be suitable for low-power applications.
- Customizability: The ATtiny85 allows for greater customization than an Arduino board. Users can program it directly in C or assembly language, which gives them complete control over the microcontroller’s behavior. In contrast, Arduino boards are programmed in a simplified version of C, and users have limited control over the underlying hardware.
- Flexibility: The ATtiny85 can be used in a wide range of applications, including robotics, home automation, and wearables. Arduino boards are primarily designed for prototyping and educational purposes, although they can also be used in more advanced projects.
- Availability: The ATtiny85 is widely available and can be purchased from many electronics suppliers. Arduino boards are also widely available, but they are often more expensive and may be less suited for certain applications.
By looking at its size, you might have an idea that it has fewer IO pins. So, you just can’t control your entire home appliances. If you are thinking about the IO extender then why to use the ATtiny85 in the first place? Why not to use Arduino Uno or Arduino Mega then?
What I want to say is, if you want to control certain loads like a TV, an AC, a Refrigerator, a bulb, etc. Then you should use the ATtiny85 microcontroller when you are sure about the loads you want to control are equal to or less than 4.
I already have a getting started article on the ATtiny85 microcontroller in which I have already explained the technical specifications, how to burn a bootloader, and how to get started with an LED. So, I highly recommend you guys must read my getting started article on the ATtiny85. So, without any further delay let’s get started!!!
Amazon Links:
Arduino Nano USB C type (Recommended)
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
ATtiny85 Pinout:
Vcc: This pin is the power supply pin, and it should be connected to a power source between 2.7V and 5.5V. It supplies power to the microcontroller and any connected components.
PB3 (also known as “Pin 2”): This pin is a general-purpose input/output (I/O) pin. It can be used to read digital inputs or control digital outputs, such as LEDs or other electronic components. PB3 can be configured as an input or an output in software.
PB4 (also known as “Pin 3” or “PWM”): This pin is a Pulse Width Modulation (PWM) output pin. PWM is a technique that is used to control the amount of power supplied to a component, such as an LED or a motor. By rapidly switching the output on and off, the average power can be controlled, which can be used to control the brightness of an LED or the speed of a motor.
PB0 (also known as “Pin 5” or “MOSI”): This pin is used for Serial Peripheral Interface (SPI) communication. SPI is a synchronous serial communication protocol that is used to communicate with other devices, such as sensors or displays. PB0 is the MOSI (Master Output, Slave Input) pin, which is used to send data from the ATtiny85 to the connected device.
PB1 (also known as “Pin 6” or “MISO”): This pin is also used for SPI communication. PB1 is the MISO (Master Input, Slave Output) pin, which is used to receive data from the connected device.
PB2 (also known as “Pin 7” or “SCK”): This pin is also used for SPI communication. PB2 is the SCK (Serial Clock) pin, which is used to synchronize the data transfer between the ATtiny85 and the connected device.
RESET (also known as “Pin 1” or “RST”): This pin is used to reset the microcontroller. When the RESET pin is brought low, the microcontroller will be reset and its program will start from the beginning.
GND: This pin is the ground pin, and it should be connected to the ground of the circuit. It is used as a reference point for the voltage in the circuit and completes the circuit for the electrical current.
ATtiny85 IR Remote Control Circuit Diagram:
Connect the voltage and GND pins of the IR sensor to the 5V and GND pins. Connect the S pin of the IR Sensor to the ATtiny85 Pin 5. To avoid an confusion make sure you study the ATtiny85 Pinout diagrams given above.
I have connected all the 4 relays to the ATtiny85 pins 6, 7, 2, and 3 respectively. This sequence is not important, you can use any of these 4 pins to control any relay.
You can use AAA batteries to power up your project, or you can use any 5V regulated power supply. In my case, I am using my designed 5V and 3A power supply.
As you can see I have connected the 5v and GND wires to the VCC and GND pins on the ATtiny85 microcontroller. I have a very detailed video on how to design a 5V and 3A power supply in Altium designer. So, that’s all about the connections and now let’s install the required library.
ATtiny85 IRremote Library:
Make sure you have the latest version of the Arduino IDE installed on your computer or laptop. Anyway, we are going to install the IRremote library for this, go to the Sketch Menu > then to Include Library > and click on the Manage libraries.
Write the library name “IRremote” in the search box and install it. As you can see I have already installed this library.
ATtiny85 IR Remote Control Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#include "IRremote.h" /*-----( Declare Constants )-----*/ #define receiver PB0 int device1 = PB1; int device2 = PB2; int device3 = PB3; int device4 = PB4; /*-----( Declare objects )-----*/ IRrecv irrecv(receiver); // create instance of 'irrecv' decode_results results; // create instance of 'decode_results' /*-----( Declare Variables )-----*/ void setup() /*----( SETUP: RUNS ONCE )----*/ { irrecv.enableIRIn(); // Start the receiver pinMode(device1, OUTPUT); pinMode(device2, OUTPUT); pinMode(device3, OUTPUT); pinMode(device4, OUTPUT); digitalWrite(device1, LOW); digitalWrite(device2, LOW); digitalWrite(device3, LOW); digitalWrite(device4, LOW); }/*--(end setup )---*/ void loop() /*----( LOOP: RUNS CONSTANTLY )----*/ { if (irrecv.decode(&results)) // have we received an IR signal? { //translateIR(); if (results.value==0x9716BE3F) { digitalWrite(device1, !digitalRead(device1)); } else if (results.value==0x3D9AE3F7) { digitalWrite(device2, !digitalRead(device2)); } else if (results.value==0x6182021B) { digitalWrite(device3, !digitalRead(device3)); } else if (results.value==0x8C22657B) { digitalWrite(device4, !digitalRead(device4)); } irrecv.resume(); // receive the next value } } |
This is a small program that reads the IR remote control button codes and then controls the desired loads. As you can see, I am using only one library.
The IR sensor S pin is connected to the PB0 and the 4 relays are connected to the PB1, PB2, PB3, and PB4. These pins which are used to control 4 relays are named as Device1, Device2, Device3, and Device4.
Then in the setup() function we simply activate the ir sensor and set all the relays as the output devices using the pinMode() function. By default, all the relays will be in the OFF state.
Then in the loop() function, we check if an IR signal is received. Then using if conditions we check the codes. If the code is valid then the desired device or load is turned ON or turned OFF depending on its previous state. Now, you might be thinking how a got those button codes? Well I have been using IR remote control with Arduino and other controller boards, so I simply copied those codes from my previous projects. Read my articles on IR Remote control-based Fan Speed control system and ESP32 and IR Remote based home automation if you want to learn how to find the IR Remote control buttons codes.
You can also use the following code for finding the codes of any IR remote controller. All you need simply upload this program to your Arduino board and connect the IR sensor signal pin to the Arduino pin11 and of course connect the voltage and GND pins to the Arduino 5V and GND pins. Open the serial monitor and set the desired baud rate. And start pressing the buttons, you will see the button codes.
Find the IR Remote Control button codes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
#include <IRremote.h> int RECV_PIN = 11; IRrecv irrecv(RECV_PIN); decode_results results; void setup() { Serial.begin(9600); irrecv.enableIRIn(); // Start the receiver } void loop() { if (irrecv.decode(&results)) { Serial.println(results.value, HEX); irrecv.resume(); // Receive the next value } delay(100); } |
Now, the final step is to upload this program. As you know, the ATtiny85 has no USB support so we will need to use an Arduino board to upload the program. So, next I am going to explain how to connect your ATtiny85 with the Arduino Uno. First, you will need to burn the bootloader onto the ATtiny85 microcontroller for this you can ready my getting started article on the ATtiny85.
Altium Designer, Altium 365, & Octopart:
Altium Designer is the world’s most trusted PCB design system. Altium Designer enables engineers to effortlessly connect with every facet of the electronics design process. Over 35 years of innovation and development focused on a truly unified design environment makes it the most widely used PCB design solution. With Altium Designer you can create PCB designs with an intuitive and powerful interface that connects you to every aspect of the electronics design process. Route it your way through any angle, tune for the delay, Push, Slide, and Walkaround faster than ever.
Easily work together with your mechanical team and forget about the days of swapping design files. Every design change stays in sync between Altium Designer and SOLIDWORKS, PTC Creo, Autodesk Inventor, Autodesk Fusion 360, or Siemens NX*.
Interact and collaborate with mechanical designers like never before in a photo-realistic, 3D design environment.
One of the best things about Altium Designer is that you can share your designs with your team members using Altium 365. They can check your design, leave comments, and if there are any issues, they can fix them from anywhere in the world. Altium Designer also uses the world’s fastest components search engine, Octopart, so you won’t have any difficulty in searching for components.
Altium Designer, Altium 365, and Octopart—unleashes the full potential of electronics design by seamlessly integrating design tools, collaboration platforms, and component databases. Together, they offer engineers a comprehensive and synchronized experience, leading to improved productivity, reduced errors, and accelerated innovation in the world of electronics design.
Connect pin 1 of the ATtiny85 which is also the reset pin to pin 10 of the Arduino which is the SS (Slave Select).
Connect pin 4 which is the ground pin to the Ground pin of the Arduino.
Connect pin 5 which is the MOSI pin to pin 11 of the Arduino which is the MOSI (Master-out, Slave In).
Connect pin 6 which is the MISO pin to pin 12 of the Arduino which is the MISO (Maser-In, Slave Out).
Connect pin 7 which is the SCK pin to pin 13 of the Arduino which is the SCK (Serial Clock).
Connect pin 8 of the ATtiny85 which is the VCC pin to the Arduino 5V pin.
Finally, connect a 10uF capacitor between the Reset and GND pins of the Arduino. Make sure you connect the +Ve leg of the capacitor with the Reset pin and the other leg of the capacitor with the GND. So, that’s all about the connections.
Connect Arduino Uno with the Laptop and Upload this program. But first, you will need to add the ATtiny85 controller in the Arduino IDE.
ATtiny85 in Arduino IDE:
The ATtiny85 microcontroller is not pre-installed in the Arduino IDE and you can confirm this by going to the Tools Menu and then to board, you will see a long list of the Arduino boards, but you won’t find ATtiny85. So, this means you will have to manually install the ATtiny85 as a board in the Arduino IDE.
For this, copy the board manager URL link given below.
https://raw.githubusercontent.com/damellis/attiny/ide-1.6.x-boards-manager/package_damellis_attiny_index.json
Then come back to the Arduino IDE, go to the File Menu, and then to Preferences, and paste the link in the Additional Boards Manager URLs.
Put a comma if you have added other boards otherwise you can directly paste the board URL link and then click on the OK button.
Go to the Tools Menu, then to board, and click on the Boards Manager. Search for the ATtiny and install it.
You can see the ATtiny85 is included in this boards Package. Anyway, you can see I have already installed this board.
Now, to confirm that the ATtiny85 Microcontroller is added, go to the Tools Menu, then to Board and you can see the ATtinny Microcontrollers.
You can see different variants of the ATtiny microcontrollers. So, let’s go ahead and select the ATtiny85 controller.
Now, let’s go ahead and upload the program.
Note: Make sure you have installed the Bootloader on the ATtiny85; if not then read my getting started article on the ATtiny85.
Practical Demonstration:
I successfully controlled all the 4 Bulbs. There was no delay at all. For the practical demonstration watch video tutorial given below.
If in case you don’t have the relay module, then you can also use the LEDs.
I am particular impressed with the projects and how they are thoroughly explained. I am looking to use some of these ideas for some commercial and household products. I just completed HND electrical and electronic engineering and I’m looking for a job. I am skilled in PLC programming and motor control, electronics and electrical installation. I have also started programming in Arduino and Python. I was hoping you could mentor me and assist me with a few challenges as I am looking to design a few projects for sale.
here is my whatsapp number
+923339218213
I was hoping you could share a means of contact with me if you accept my proposal.
Regards,
Noah Agyemang