{"id":22120386,"url":"https://github.com/znitche/attiny-voltmeter","last_synced_at":"2025-07-25T12:33:15.327Z","repository":{"id":251417336,"uuid":"835922687","full_name":"zNitche/attiny-voltmeter","owner":"zNitche","description":"measuring voltage using attiny13 and attiny85","archived":true,"fork":false,"pushed_at":"2024-08-07T20:31:57.000Z","size":143,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T06:34:32.581Z","etag":null,"topics":["attiny13","attiny85","voltage-measurement","voltmeter"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zNitche.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-30T19:47:30.000Z","updated_at":"2024-10-06T18:52:57.000Z","dependencies_parsed_at":"2024-12-02T08:03:49.497Z","dependency_job_id":null,"html_url":"https://github.com/zNitche/attiny-voltmeter","commit_stats":null,"previous_names":["znitche/attiny-voltmeter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zNitche/attiny-voltmeter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zNitche%2Fattiny-voltmeter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zNitche%2Fattiny-voltmeter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zNitche%2Fattiny-voltmeter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zNitche%2Fattiny-voltmeter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zNitche","download_url":"https://codeload.github.com/zNitche/attiny-voltmeter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zNitche%2Fattiny-voltmeter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267007598,"owners_count":24020261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["attiny13","attiny85","voltage-measurement","voltmeter"],"created_at":"2024-12-01T14:23:11.249Z","updated_at":"2025-07-25T12:33:14.931Z","avatar_url":"https://github.com/zNitche.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# attiny-voltmeter\nmeasuring voltage using attiny13/attiny85\n\n### Motivation\nRecently I bought a BMS to use in my future project (PicoWeatherStationV3 foreshadowing) to protect its spare power supply, this cheap 1S boards have one critical flaw, battery low voltage cutoff is 2.5V (lowest safe voltage for 18650 lipol battery is around 3.1V), without way to change it (at least I don't know any). \n\nI thought to myself I can build simple one myself, all I need is Mosfet transistor, some fuses and a way to control Mosfet basing on current battery voltage. In the past I built voltmeter using RaspberryPi Pico + LM4040, but for this application this setup is too expensive + takes too much space.\n\nMy final choice was Attiny13/Attiny85 as it is relative cheap, small and works in following voltage ranges (2.7-5.5) so it can be powered directly from battery without using voltage stabilizer or buck/boost converter.\n\nI got myself USBasp programmer + Attiny13 and Attiny85 (to test which one fits better), wired prototype board and I got to work.\n\n### Uploading code\nIn order to upload code to Attiny I gonna use USBasp ISP programmer and Arduino IDE 2.3.2.\n\n### Serial communication\nDespite not having dedicated TX/RX pins both microcontrollers support SoftwareSerial. All what is needed is a USB \u003c-\u003e UART converter, for example `PL2303`.\n\n### Error with USB permissions on Linux\nIf you encounter permission error while using USBasp programmer:\n\n1. Create rule file.\n```\ntouch /etc/udev/rules.d/99-usbasp.rules\n```\n\n2. Put following text into it.\n```\nSUBSYSTEM==\"usb\", ATTRS{idVendor}==\"16c0\", ATTRS{idProduct}==\"05dc\", MODE=\"0666\"\n```\n\n3. Relog (or reboot just in case).\n\n### Setting fuses\nBefore first use (or after changing properties in `Tools` tab, I'm not sure about that) don't forget to set fuses by using `Burn Bootloader`.\n\n### Attiny13 setup\nFor this little buddy I used following hardware package.\n\n```\nhttps://github.com/MCUdude/MicroCore (version 2.4.0)\n```\n\nInstalled by putting\n```\nhttps://mcudude.github.io/MicroCore/package_MCUdude_MicroCore_index.json\n```\n\nto `Additional Boards Manager URLs` in the IDE settings.\n\n#### Serial monitor setup\nPackage by MCUdude comes with built-in support for UART operations all we need is USB \u003c-\u003e UART converter and proper connection.\n\n##### Wiring\n| Converter  | Attiny13 |\n| ---------- | -------- |\n| RX         |     PB0  |\n| TX         |     PB1  |\n\n##### Baund rate\nFor this project I'm using `1.2 MHz` internal oscillator for which proper serial baundrate is `19200`.\n\n#### Hello World\nAlright with everything in place we can verify is everything is working as correctly.\n\n1. Put following code into sketch.\n\n```\nvoid setup() {}\n\nvoid loop() {\n  while (true) {\n    Serial.println(\"Hello world\");\n    delay(2000);\n  }\n}\n```\n\n2. Upload using Programmer.\n```\nCtrl + Shift + U\n```\n\nAnd if you are the lucky one, you should see `Hello World` printing every 2 seconds. \n\n### Attiny85 setup\nFor Attiny85 I used following hardware package.\n\n```\nhttps://github.com/SpenceKonde/ATTinyCore (version 1.5.2)\n```\n\nInstalled by putting\n```\nhttps://drazzy.com/package_drazzy.com_index.json\n```\n\nto `Additional Boards Manager URLs` in the IDE settings.\n\n#### Serial monitor setup\nPackage by SpenceKonde comes with built-in support for uart operations all we need is USB \u003c-\u003e UART converter and proper connection.\n\n##### Wiring\n| Converter  |   Attiny85    |\n| ---------- | ------------- |\n| RX         |     PB0       |\n| TX         |   A1 / PB1    |\n\n##### Baund rate\nFor this project I'm using `1 MHz` internal oscillator for which proper serial baundrate is `9600`.\n\n#### Hello World\nAlright with everything in place we can verify is everything is working as correctly.\n\n1. Put following code into sketch.\n\n```\nvoid setup() {\n  Serial.begin(9600);\n}\n\nvoid loop() {\n  while (true) {\n    Serial.println(\"Hello world\");\n    delay(2000);\n  }\n}\n```\n\n2. Upload using Programmer.\n```\nCtrl + Shift + U\n```\n\nYou should see `Hello World` printing every 2 seconds. \n\n### Attiny85 voltage measurements\nI created following circuit with voltage divider in ratio 1:4.3 (1V on ADC pin = 4.3V of source voltage).\n\n![wiring](media/wiring/stable_vcc.png)\n\nI hooked Attiny to UART converter (powering it from the same converter), switched ADC reference to internal 1.1V, set PSU to 4V and took some readings.\n\n![graph_no_sampling](media/graphs/85_no_sampling.png)\n\nIt is quite noisy, isn't it ? Let's check if it can be tweaked with some sampling.\n\n![graph_10x_sampling](media/graphs/85_10x_sampling.png)\n\nYup It helped, now it looks much better.\n\n### Attiny13 voltage measurements\nAttiny13 has 1Kb of internal space, too little for using ADC and Serial libs at the same time, so I had to figure out a way to test it.\n\n### Field Test (Attiny85 and Attiny13)\nI modified previous circuit, added LED to indicate if voltage is below certain threshold + powered Attiny directly from battery.\n\n![wiring](media/wiring/battery_vcc.png)\n\nThis way I can test if variable supply voltage can make readings worse.\nI uploaded following sketches and tested it.\n\n- [attiny13](/sketches/attiny13/attiny13.ino)\n- [attiny85](/sketches/attiny85/attiny85.ino)\n\nAfter some tests it looks like variable supply voltage doesn't affect readings much, it still works great.\n\n### Summary\nAttiny does a good job as a voltmeter, and it will be core part (Attiny85, because of bigger flash size) of simple kind of BMS I talked about. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fznitche%2Fattiny-voltmeter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fznitche%2Fattiny-voltmeter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fznitche%2Fattiny-voltmeter/lists"}