parts:
- ATtiny2313 @4MHz (internal oscillator)
- IR LED (series with 220-ohm resistor)
- Tact switches
- 3.7V lithium ion battery & Capacitor




avr-gcc (main.c) code:
References:
ESP8266 IR Remote
z3t0/Arduino-IRremote
ATtiny Low Power
Prototype Projects - experiments on theoretical electronics/electrical designs and actual prototype circuits.





![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
wifi.setmode(wifi.STATION) wifi.sta.config("WIFI_SSID","WIFI_PASSWORD") local GP0 = 3 local GP2 = 4 local port = 3456 print(wifi.sta.getip()) srv=net.createServer(net.UDP) srv:on("receive", function(cli, rcv) --print(rcv) rx={} for i, s in string.gmatch(rcv, "(%w+)=(%w+)") do rx[i]=s --print(i, rx[i]) end if rx.d0 then pwm.setduty(GP0,rx.d0) --print("GP0 duty",rx.d0) elseif rx.d2 then pwm.setduty(GP2,rx.d2) --print("GP2 duty",rx.d2) elseif rx.f0 and rx.c0 then pwm.setup(GP0,rx.f0,rx.c0) pwm.start(GP0) print("GP0 freq",rx.f0,"cycles", rx.c0) elseif rx.f2 and rx.c2 then pwm.setup(GP2,rx.f2,rx.c2) pwm.start(GP2) print("GP2 freq",rx.f2,"cycles", rx.c2) end cli:send(rcv) end) srv:listen(port)
wifi.setmode(wifi.STATION) wifi.sta.config("WIFI_SSID","WIFI_PASSWORD") local DAT = 4 local CLK = 3 function DL() gpio.write(DAT, gpio.LOW) gpio.mode(DAT, gpio.OUTPUT) end function DH() gpio.mode(DAT, gpio.INPUT) gpio.write(DAT, gpio.HIGH) end function CL() gpio.write(CLK, gpio.LOW) end function CH() gpio.write(CLK, gpio.HIGH) end function DR() gpio.mode(DAT, gpio.INPUT) return gpio.read(DAT) end function W8() for i = 1, 100 do tmr.delay(10000) if DR() == gpio.LOW then return true end end return false end function RB() local val = 0 for i = 0, 7 do CH() val = val*2 + DR() CL() end return val end function shtread(cmd) DH() CH() DL() CL() CH() DH() CL() for i = 0, 7 do if bit.band(cmd, 2^(7-i))==0 then DL() else DH() end CH() CL() end CH() CL() if not W8() then return nil end DH() local val = RB() DH() DL() CH() CL() DH() val = val*256 + RB() DH() CH() CL() return val end page=[[<head><meta charset="utf-8"/> <link href="http://projectproto.blogspot.com/favicon.ico" rel="icon"/> <title>ESP+SHT</title></head> <body><h1>ESP8266 and SHT1x</h1><h2 id="T">T??</h2><h2 id="H">H??</h2> <script> function update(){ var xrq = new XMLHttpRequest(); xrq.onreadystatechange=function(){ if (xrq.readyState==4 && xrq.status==200){ var th=JSON.parse(xrq.responseText); var t0=th["t"], h0=th["h"]; var t=(t0*0.01)-39.7; var hl=(0.0367*h0)+(-0.0000015955*h0*h0)-2.0468; var h=(t-25.0)*(0.01+(0.00008*h0))+hl; document.getElementById("T").innerHTML="Temperature: "+t.toFixed(2)+"°C"; document.getElementById("H").innerHTML="Humidity: "+h.toFixed(2)+"%";} } xrq.open("GET","/get/sht",true); xrq.overrideMimeType("application/json"); xrq.send(null); }setInterval(update, 1000); </script></body>]] srv=net.createServer(net.TCP) srv:listen(80,function(conn) conn:on("receive", function(client,request) local buf = ""; local _, _, mtd, path, _ = string.find(request, "([A-Z]+) (.+)?(.+) HTTP"); if(mtd == nil)then _, _, mtd, path = string.find(request, "([A-Z]+) (.+) HTTP"); end if path == "/" then buf = buf..page elseif path == "/get/sht" then t = shtread(3) h = shtread(5) if (t ~= nil and h ~= nil) then buf = buf.."{\"t\":"..t..", \"h\":"..h.."}" end end client:send(buf) client:close() collectgarbage() end) end)
int ledPin = 13; void setup(){ Serial.begin(9600); Serial.setTimeout(200); pinMode(ledPin, OUTPUT); } void loop(){ if (Serial.available()){ String c = Serial.readString(); if (c.equals("TONLED")) digitalWrite(ledPin, HIGH); else if (c.equals("TOFFLED")) digitalWrite(ledPin, LOW); else Serial.print(c); } }
allprojects { repositories { jcenter() maven { url "https://jitpack.io" } } }
compile 'com.github.felHR85:UsbSerial:4.3'
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION"; UsbDevice device; UsbDeviceConnection connection; UsbManager usbManager; UsbSerialDevice serialPort; PendingIntent pendingIntent;
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(ACTION_USB_PERMISSION)) { boolean granted = intent.getExtras().getBoolean(UsbManager.EXTRA_PERMISSION_GRANTED); if (granted) { connection = usbManager.openDevice(device); serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection); if (serialPort != null) { if (serialPort.open()) { serialPort.setBaudRate(9600); serialPort.setDataBits(UsbSerialInterface.DATA_BITS_8); serialPort.setStopBits(UsbSerialInterface.STOP_BITS_1); serialPort.setParity(UsbSerialInterface.PARITY_NONE); serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF); serialPort.read(mCallback); } else { Log.d("SERIAL", "PORT NOT OPEN"); } } else { Log.d("SERIAL", "PORT IS NULL"); } } else { Log.d("SERIAL", "PERMISSION NOT GRANTED"); } } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) { onClickStart(startButton); } else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) { //can add something to close the connection } }; };
pendingIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0); IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION); registerReceiver(broadcastReceiver, filter);
public void onClickStart(View view) { if (!isSerialStarted) { usbManager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList(); if (!usbDevices.isEmpty()) { boolean keep = true; for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) { device = entry.getValue(); int deviceVID = device.getVendorId(); if (deviceVID == 1027 || deviceVID == 9025) { //Arduino Vendor ID usbManager.requestPermission(device, pendingIntent); keep = false; } else { connection = null; device = null; } if (!keep) break; } } } }
private UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() { //Defining a Callback which triggers whenever data is read. @Override public void onReceivedData(byte[] arg0) { String data = null; try { data = new String(arg0, "UTF-8"); data.concat("/n"); tvAppend(displayView, data); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }; private void tvAppend(final TextView tv, final CharSequence text) { runOnUiThread(new Runnable() { @Override public void run() { if (text != null) { tv.append(text); } } }); }
public void onClickSend(View view) { String textInput = inputView.getText().toString(); serialPort.write(textInput.getBytes()); }
public void onClickToggle(View view) { if (isLedON == false) { isLedON = true; tvAppend(displayView, "\nLED TURNED ON\n"); serialPort.write("TONLED".getBytes()); } else { isLedON = false; serialPort.write("TOFFLED".getBytes()); tvAppend(displayView, "\nLED TURNED OFF\n"); } }
serialPort.close();
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="yourpackage.com.name"> <uses-feature android:name="android.hardware.usb.host" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/AppTheme.NoActionBar"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" /> </intent-filter> <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" android:resource="@xml/device_filter" /> <intent-filter> <action android:name="android.hardware.usb.action.USB_DEVICE_DETACHED" /> </intent-filter> </activity> </application> </manifest>
<?xml version="1.0" encoding="utf-8"?> <resources> <usb-device vendor-id="9025"/> </resources>
mScrollView.smoothScrollTo(0, displayView.getBottom());