In this project, you’ll learn how to control an LED using an infrared (IR) remote with the UNIHIKER and its Carrier Board. This project is great for understanding IR communication and basic LED control. We’ll cover the hardware setup, software installation, and coding in detail. 🌟
Materials Needed:- UNIHIKER Board: The main microcontroller board. 🖥️
- UNIHIKER Carrier Board: Provides additional connectivity.🔌
- IR Remote: Any standard IR remote control. 📺
- IR Receiver: Built into the Carrier Board. 📡
- LED: Built into the Carrier Board. 💡
- USB Cable: For power and data transfer. 🔋
JLCPCB is a leading PCB prototype and fabrication manufacturer. Here’s why you should consider them for your next project:
Fast Turnaround: JLCPCB offers rapid PCB prototyping with build times as short as 24 hours. Whether you’re iterating on designs or need quick prototypes, they’ve got you covered.
Low Cost: Their pricing starts from just $2 for 1-4 layer PCBs (100x100mm size). Plus, they provide competitive rates for higher-layer counts.
Advanced Smart Factories: JLCPCB leverages fully automatic equipment and smart factories, ensuring both efficiency and quality.
PCB Assembly Services: Need assembly? JLCPCB offers PCB assembly starting at $8 for 5 PCs. They have over 560,000 in-stock parts and provide free DFM file checks.
Flex PCBs and Mechatronic Parts: They support flexible PCBs and offer mechatronic parts with cost savings of up to 68%.
Quality Assurance: Certified to ISO 9001:2015, ISO 14001:2015, and IPC-6012E standards, JLCPCB guarantees industry benchmarks.
Explore their services and experience the power of JLCPCB’s integrated solutions! 🚀
JLCPCB is Trusted by 5.4M Engineers Worldwide! Get a High-quality PCB Prototype for Just $2! Sign up to Get $80 Coupons: https://jlcpcb.com/?from=pradeep
Step 1: Setting Up the HardwareConnect the UNIHIKER to the Carrier Board:Ensure the UNIHIKER board is securely connected to the Carrier Board. The Carrier Board should have the IR receiver and LED already integrated. 🔧
Power the Boards:Connect the UNIHIKER Carrier board to a power source using a USB cable. The UNIHIKER Board can be powered through the Carrier. ⚡
Open the Mind+ IDE and select the python.
Next, click on the Blocks and open the extension tab.
Select the UNIHIKER.
Then select the connect to the remote terminal and connect with the UNIHIKER.
Install the PinPong Library:📦The PinPong library is essential for controlling the hardware components. You can install it using the following command in the terminal:
pip install pinpong
Create a Python Script:📝create a new Python file, e.g., test.py.
Import Libraries and Initialize Board:🖥️
Start by importing the necessary libraries and initializing the board:
import time
from pinpong.board import Board,Pin,IRRecv,NeoPixel
from pinpong.extension.unihiker import *
from unihiker import GUI
Board().begin()
Set Up the IR Receiver and LED:
Define the pins for the IR receiver and LED:📡💡
ir1 = IRRecv(Pin((Pin.P14)),event)
np1 = NeoPixel(Pin((Pin.P13)),1)
np1.brightness(128)
Create a Function to Handle IR Signals:
Write a function to handle the IR signals and control the LED:
def event(data):
my_variable = hex(data)
print(my_variable)
np1.range_color(0,2,0x00FF04)
Step 4: Running the CodeUpload and Run the Script:🚀Upload the below script to the UNIHIKER board and run it. You should see the LED toggle on and off when you press the corresponding button on the IR remote.
import time
from pinpong.board import Board,Pin,IRRecv,NeoPixel
from pinpong.extension.unihiker import *
from unihiker import GUI
u_gui=GUI()
u_gui.draw_text(text="UNIHIKER",x=50,y=100,font_size=20, color="#0000FF")
u_gui.draw_text(text="Carrier Board Test",x=60,y=130,font_size=10, color="#0000FF")
Board().begin()
def event(data):
my_variable = hex(data)
print(my_variable)
np1.range_color(0,2,0x00FF04)
np1 = NeoPixel(Pin((Pin.P13)),1)
np1.brightness(128)
ir1 = IRRecv(Pin((Pin.P14)),event)
while True:
time. Sleep(1)
np1.range_color(0,2,0x000000)
You can add feedback to the display to see which IR code was received and the state of the LEDs.
u_gui.fill_circle(x=120, y=200, r=50, color="white")
u_gui.draw_text(text=my_variable,x=90,y=200,font_size=10, color="#0000FF")
UNIHIKER carrier board has 3 Neo Pixel LEDs, so we can easily control all of them. Just modify the LED count as shown below.
np1 = NeoPixel(Pin((Pin.P13)),1 ) -----> np1 = NeoPixel(Pin((Pin.P13)),3)
Here is the complete program.
import time
from pinpong.board import Board,Pin,IRRecv,NeoPixel
from pinpong.extension.unihiker import *
from unihiker import GUI
u_gui=GUI()
u_gui.draw_text(text="UNIHIKER",x=50,y=100,font_size=20, color="#0000FF")
u_gui.draw_text(text="Carrier Board Test",x=60,y=130,font_size=10, color="#0000FF")
Board().begin()
np1 = NeoPixel(Pin((Pin.P13)),1)
np1.brightness(128)
def event(data):
my_variable = hex(data)
print(my_variable)
u_gui.fill_circle(x=120, y=200, r=50, color="white")
u_gui.draw_text(text=my_variable,x=90,y=200,font_size=10, color="#0000FF")
np1.range_color(0,2,0x00FF04)
ir1 = IRRecv(Pin((Pin.P14)),event)
while True:
time. Sleep(1)
np1.range_color(0,2,0x000000)
ConclusionYou’ve successfully built an IR-controlled LED using the UNIHIKER and its Carrier Board! This project can be expanded by adding more LEDs or integrating other sensors and actuators. You can also explore different IR codes and customize the functionality based on your remote control. 🎉
Feel free to ask if you have any questions or need further assistance! Happy building! 😊🚀
Comments
Please log in or sign up to comment.