{"id":3435,"date":"2019-09-02T05:17:01","date_gmt":"2019-09-02T04:17:01","guid":{"rendered":"http:\/\/mathscitech.org\/articles\/?p=3435"},"modified":"2024-06-03T09:17:03","modified_gmt":"2024-06-03T08:17:03","slug":"microcontrollers-nano","status":"publish","type":"post","link":"https:\/\/mathscitech.org\/articles\/microcontrollers-nano","title":{"rendered":"A microcontroller development kit for under \u00a310 (Arduino)"},"content":{"rendered":"<p>For <strong>under \u00a310<\/strong>, you can put together a microcontroller development platform, ready to program directly from your PC over USB using free Arduino software.  Once programmed, your microcontroller will run autonomously, untethered from your PC, powered by as small a battery power supply as a single 1.5V AAA or 3V CR2032 coin cell.  You can have it interact with its environment using dozens of low-cost sensors and motors.  Everything you need to explore the <a href=\"https:\/\/mathscitech.org\/articles\/sensor-systems\" target=\"_blank\" rel=\"noopener noreferrer\">exciting world of embedded systems<\/a> is available to you, typically for less than a <a href=\"https:\/\/www.londontravelpass.com\/prices.html\" target=\"_blank\" rel=\"noopener noreferrer\">day pass on the London underground<\/a>.<\/p>\n<div id=\"attachment_3445\" style=\"width: 410px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3445\" loading=\"lazy\" class=\"wp-image-3445\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/AA1EFDCA-C194-4018-B089-1B6BA21CEB8B-e1567484390243-695x800.jpeg\" alt=\"An Arduino Nano microcontroller development kit for under \u00a313\" width=\"400\" height=\"460\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/AA1EFDCA-C194-4018-B089-1B6BA21CEB8B-e1567484390243-695x800.jpeg 695w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/AA1EFDCA-C194-4018-B089-1B6BA21CEB8B-e1567484390243-261x300.jpeg 261w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/AA1EFDCA-C194-4018-B089-1B6BA21CEB8B-e1567484390243-130x150.jpeg 130w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/AA1EFDCA-C194-4018-B089-1B6BA21CEB8B-e1567484390243-400x460.jpeg 400w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><p id=\"caption-attachment-3445\" class=\"wp-caption-text\">A homebrew Arduino Nano microcontroller development kit for under \u00a312 (including optional OLED display)<\/p><\/div>\n<p><!--more--><br \/>\n<strong>What do you need to get started with microcontrollers?<\/strong> Apart from a PC and the willingness to experiment (Google is your friend!), below is a list that gives you an inexpensive, minimal development kit for under \u00a310. Everything is available on Amazon (prices are as of April 2019). Tools e.g. multimeter, mini pliers, wire strippers, soldering iron, can be found inexpensively from the <a href=\"https:\/\/mathscitech.org\/articles\/electronics#equipment\" target=\"_blank\" rel=\"noopener noreferrer\">equipment list.<\/a>.<\/p>\n<p><strong>Parts List for a low-cost Arduino Nano development kit<\/strong><\/p>\n<ol>\n<li>Arduino Nano microcontroller v3.0, with 30 dual inline pins for inserting directly into a solderless breadboard. <a href=\"https:\/\/www.amazon.co.uk\/TOOGOO-XTWduino-ATMEGA328P-Improve-Arduino-BLUE\/dp\/B073WBDQ9Q\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u00a32.33 ea.<\/a><\/li>\n<li>Solderless breadboard 400 tie-points, large enough to accommodate the Nano microcontroller, and additional components. <a href=\"https:\/\/www.amazon.co.uk\/SODIAL-Solderless-Breadboard-Points-Contacts\/dp\/B00JGFDKBQ\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u00a31.31<\/a>.<\/li>\n<li>Portable power using 1.5V AAA battery (30p) with LilyPad 5VDC Boost Converter (has convenient on\/off switch). <a href=\"https:\/\/www.amazon.co.uk\/Cikuso-Supply-Battery-Converter-Arduino\/dp\/B07PS6CV5R\/\" target=\"_blank\" rel=\"noopener noreferrer\">LilyPad \u00a31.87<\/a>.<\/li>\n<li>Half dozen small LEDs (3mm) and resistors (1K ohms is fine) &#8211; less than 10p<\/li>\n<li>Buzzer &#8211; with 2-pins, this is a simple component that can give a diagnostic beep, or a pitched tone driven by the Nano using <code>tone()<\/code> command. 34p ea.  (A speaker will require amplification of some kind, and while a simple 2N2222 transistor can work, it&#8217;s a bit more hassle and not essential)<\/li>\n<li>Small jumper wires (10cm male-male), 40 pc. <a href=\"https:\/\/www.amazon.co.uk\/gp\/offer-listing\/B07SM4HFSK\" target=\"_blank\" rel=\"noopener noreferrer\">\u00a31.44<\/a><\/li>\n<li>USB mini cable for programming Nano directly from PC. <a href=\"https:\/\/www.amazon.co.uk\/TOOGOO-Cable-Arduino-Controller-Board\/dp\/B073WBP87S\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u00a31.48<\/a>.<\/li>\n<li><a href=\"https:\/\/www.arduino.cc\/en\/Main\/Software\" target=\"_blank\" rel=\"noopener noreferrer\">Arduino software IDE (FREE!)<\/a> for programming the Nano using the <a href=\"https:\/\/mathscitech.org\/articles\/c-for-systems\" target=\"_blank\" rel=\"noopener noreferrer\">C language<\/a> (Tip: get the zip download for portable installation)<\/li>\n<\/ol>\n<p><strong>Total: \u00a38.87<\/strong><\/p>\n<p>Optional (fun, but not required, as text-based debugging is not really the way to go in embedded development &#8212; easier and much more memory efficient to use LEDs and or tones)<\/p>\n<ul>\n<li>OLED display 4-pins, 128&#215;64 pixels, giving 8 rows for text or graphics, communicates using I2C (2-wires), <a href=\"https:\/\/github.com\/adafruit\/Adafruit_SSD1306\/blob\/master\/examples\/ssd1306_128x64_i2c\/ssd1306_128x64_i2c.ino\" target=\"_blank\" rel=\"noopener noreferrer\">open-source software driver<\/a> available for the Nano. <a href=\"https:\/\/www.amazon.co.uk\/Cikuso-0-96in-Display-SSD1306-Arduino-Photo-Color\/dp\/B07Q4335H7\/\" target=\"_blank\" rel=\"noopener noreferrer\">\u00a32.13<\/a>.<\/li>\n<\/ul>\n<p><strong>What can you do with this setup?<\/strong><\/p>\n<p>Once you have this built, it is straight-forward to explore the capabilities of the versatile <a href=\"https:\/\/en.wikipedia.org\/wiki\/ATmega328\" target=\"_blank\" rel=\"noopener noreferrer\">ATmega 328P AVR<\/a> 8-bit microcontroller. Note this is the same microcontroller as in the Arduino Uno, so libraries for the UNO will work with the Nano (with minor adjustments for pins and capabilities).<\/p>\n<p>Example projects in order of simplicity:<\/p>\n<p><strong>(1) Light Stage<\/strong> Earlier this year, my daughter Jasmine (7yrs) and I designed and built this LED Light Stage together. She built the amphitheatre out of newspaper and some scrap wood, and wired the LEDs around around the stage, I programmed the Nano to flash the lights to create a Glastonbury music festival effect. Notice her Lego Friends dotted about the stage \ud83d\ude42<\/p>\n<p><i>Glastonbury Music Festival set for Lego Friends<\/i><\/p>\n<div id=\"attachment_3488\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3488\" loading=\"lazy\" class=\"size-large wp-image-3488\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0815-800x281.png\" alt=\"Light Stage built using various colored LEDs powered by a 6V battery (2x CR2032 coin cells) and an Arduino Nano to custom flash twelve yellow and red LEDs for a dynamic live rock concert effect.\" width=\"640\" height=\"225\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0815-800x281.png 800w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0815-300x105.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0815-150x53.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0815-400x141.png 400w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0815.png 930w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><p id=\"caption-attachment-3488\" class=\"wp-caption-text\">Light Stage built using various colored LEDs powered by a 6V battery (2x CR2032 coin cells) and an Arduino Nano to custom flash twelve yellow and red LEDs for a dynamic live rock concert effect.<\/p><\/div>\n<div id=\"attachment_3486\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3486\" loading=\"lazy\" class=\"size-large wp-image-3486\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0819-800x251.png\" alt=\"Arduino Nano powered by 1.5V AAA with 5V boost converter, controlling twelve LEDs independently.\" width=\"640\" height=\"201\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0819-800x251.png 800w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0819-300x94.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0819-150x47.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0819-400x126.png 400w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0819.png 824w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><p id=\"caption-attachment-3486\" class=\"wp-caption-text\">Arduino Nano powered by 1.5V AAA with 5V boost converter, controlling twelve LEDs independently.<\/p><\/div>\n<p><strong>(2) Music Box w\/ Light Display<\/strong> We then used the same Nano setup to create a light &amp; sound module that plays four songs in a looped sequence through a <a href=\"https:\/\/mathscitech.org\/articles\/electronics#pc_speaker\" target=\"_blank\" rel=\"noopener noreferrer\">tiny PC speaker<\/a>, while flashing a series of 12 yellow &amp; red leds. Jasmine used this to add music-box style sound to her toy ice-cream van. The songs are programmable note by note, using the Nano command <code>tone(pin, Hz, duration)<\/code>, and a music frequency lookup chart (e.g, middle C is 261.63Hz, and A in the same octave is 440Hz, see below).<\/p>\n<p><i>Musical Notes and Associated Frequencies<\/i><\/p>\n<div id=\"attachment_5830\" style=\"width: 452px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/001-KeyboardAndFrequencies.png\"><img decoding=\"async\" aria-describedby=\"caption-attachment-5830\" loading=\"lazy\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/001-KeyboardAndFrequencies.png\" alt=\"\" width=\"442\" height=\"177\" class=\"size-full wp-image-5830\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/001-KeyboardAndFrequencies.png 442w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/001-KeyboardAndFrequencies-300x120.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/001-KeyboardAndFrequencies-150x60.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/001-KeyboardAndFrequencies-400x160.png 400w\" sizes=\"auto, (max-width: 442px) 100vw, 442px\" \/><\/a><p id=\"caption-attachment-5830\" class=\"wp-caption-text\">Musical notes &#038; <a href=\"http:\/\/pages.mtu.edu\/~suits\/notefreqs.html\" rel=\"noopener noreferrer\" target=\"_blank\">associated frequencies<\/a> (Hz).  (Mathematical aside: Note that the modern Western musical scale is multiplicative &#8212; there are 12 semitones in an octave, and each octave is double the frequency of the one below.  Based on this, the frequency ratio between successive semitone is 12th-root of 2 = 2^(1\/12) = 1.05946309436, or a FIXED ~6% increase in frequency from note to note.  This is the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Equal_temperament\" rel=\"noopener noreferrer\" target=\"_blank\">equitempered system<\/a> popularized by Bach in the 18th century.)<\/p><\/div>\n<p><strong>(3) Digital Voltmeter<\/strong> It&#8217;s not hard to build your own digital voltmeter, with 0-5V range, using the Nano&#8217;s 10-bit analog-to-digital (A\/D) converter. Connect one jumper cable to ground, and the other to the analog pin you&#8217;re reading from, and you now have voltmeter probes. The A\/D chip will output a reading from 0 to 1023 counts, with each count 4.89mV (= 5V\/1023). To see the values, read the pin using the Arduino instruction analogRead(pin) and write out the result to a small external <a href=\"https:\/\/mathscitech.org\/articles\/electronics#oled\" target=\"_blank\" rel=\"noopener noreferrer\">OLED display<\/a>. (The OLED Display is controlled by a SSD1306 display chip with Arduino device driver <code>ssd1306_i2c.ino<\/code> from Adafruit that comes standard with the Arduino IDE. <a href=\"https:\/\/randomnerdtutorials.com\/guide-for-oled-display-with-arduino\/\" target=\"_blank\" rel=\"noopener noreferrer\">OLED tutorial<\/a>.<\/p>\n<div id=\"attachment_3482\" style=\"width: 520px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3482\" loading=\"lazy\" class=\"size-full wp-image-3482\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0805.png\" alt=\"Digital Voltmeter, 0-5V range, 4.89mV resolution, AAA powered, using Arduino Nano and OLED display\" width=\"510\" height=\"327\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0805.png 510w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0805-300x192.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0805-150x96.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0805-400x256.png 400w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\" \/><p id=\"caption-attachment-3482\" class=\"wp-caption-text\">Digital Voltmeter, 0-5V range, 4.89mV resolution, AAA powered, using Arduino Nano and OLED display<\/p><\/div>\n<p><strong>(4) Traffic light controller for 4-way intersection<\/strong> Using low-cost LED traffic light modules (\u00a30.79 ea.), I was able to put together in about 60 minutes a timed traffic light demonstration. Total cost \u00a37.40 = \u00a33.16 for 4x traffic light LED modules, \u00a32.50 Arduino Nano microcontroller with mini-USB programming cable, \u00a31.65 for AAA 1.5V to 5V boost converter power supply, 10p AAA battery. On top, \u00a35.30 in solderless breadboards for easy wiring (4xZY55-, 1&#215;170- tie points) and a ZY-001 baseboard for mounting the ZY breadboards). The C code for running this is less than 50 lines (see Appendix 5).  Note, if your traffic light modules have a rather dim green LED, there is an easy workaround covered in Appendix 4.  Challenge Extension: integrate sensors to detect the approach of toy cars, using either low-cost short-range RFID tags, or 4x vibration sensors on the approaching roadways (typical motion sensors or short range sonar\/radar will trigger false detections from the child&#8217;s arms moving around in the sensor&#8217;s field of view.)<\/p>\n<div id=\"attachment_3639\" style=\"width: 1366px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0861.png\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3639\" loading=\"lazy\" class=\"wp-image-3639 size-full\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0861.png\" alt=\"Traffic controller for 4-way intersection using Arduino Nano microcontroller in 50 lines of C code (timed rotation only, no sensors)\" width=\"1356\" height=\"354\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0861.png 1356w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0861-300x78.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0861-800x209.png 800w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0861-150x39.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0861-400x104.png 400w\" sizes=\"auto, (max-width: 1356px) 100vw, 1356px\" \/><\/a><p id=\"caption-attachment-3639\" class=\"wp-caption-text\">Traffic controller for 4-way intersection using Arduino Nano microcontroller in 50 lines of C code (timed rotation only, no sensors)<\/p><\/div>\n<p><strong>(5) Long-Range RFID Sensor &amp; Alarm<\/strong> I also built a long-range boundary sensor using the Nano as the core microcontroller interfaced with an RFID tag reader board and a high-gain RFID antenna capable of creating an 8-foot perimeter. The microcontroller is interfaced with a flashing strobe and 100dB siren to alert when an RFID tag crosses into detection range (see below).<\/p>\n<p><i>RFID Perimeter Sensor with Arduino Nano as core microcontroller<\/i><br \/>\nPrototype version 0.1: board mounted (literally on a piece of pine!) stored in Pelican case.<\/p>\n<div id=\"attachment_3464\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3464\" loading=\"lazy\" class=\"size-large wp-image-3464\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/Dawson549-RFID_Perimeter_Sensor_V1-800x313.png\" alt=\"RFID Perimeter Sensor, prototype v0.1\" width=\"640\" height=\"250\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/Dawson549-RFID_Perimeter_Sensor_V1-800x313.png 800w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/Dawson549-RFID_Perimeter_Sensor_V1-300x117.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/Dawson549-RFID_Perimeter_Sensor_V1-150x59.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/Dawson549-RFID_Perimeter_Sensor_V1-400x156.png 400w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/Dawson549-RFID_Perimeter_Sensor_V1.png 1158w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><p id=\"caption-attachment-3464\" class=\"wp-caption-text\">RFID Perimeter Sensor, prototype v0.1<\/p><\/div>\n<p>Prototype version 0.2: Pelican case mounted, with all components drilled and screwed into the case, and connectors panel mounted.<\/p>\n<div id=\"attachment_3465\" style=\"width: 667px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3465\" loading=\"lazy\" class=\"size-full wp-image-3465\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0797.png\" alt=\"RFID perimeter sensor v0.2, case mounted.\" width=\"657\" height=\"464\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0797.png 657w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0797-300x212.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0797-150x106.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0797-400x282.png 400w\" sizes=\"auto, (max-width: 657px) 100vw, 657px\" \/><p id=\"caption-attachment-3465\" class=\"wp-caption-text\">RFID perimeter sensor v0.2, case mounted.<\/p><\/div>\n<p><strong>The possibilities are endless<\/strong> To build your own creations, you can choose from <a href=\"https:\/\/mathscitech.org\/articles\/electronics#devices\" target=\"_blank\" rel=\"noopener noreferrer\">dozens of low-cost sensors and motors<\/a> compatible with the Arduino, including: infra-red detectors, magnetic reed switches, DC motors, motion detectors, ultrasound ranging, ethernet, 2.4G wireless, RFID, knock sensors, temperature, soil humidity\/moisture, photo-interruptor, photoresistor (light detection), relays (for power control), tilt switch, dual axis joystick, flame sensor, sound detection, microphone, smoke, alcohol, methane, color, keypad, bluetooth, barometric pressure, OLED display, GPS, gyroscope\/accelerometer, inertial measure unit (IMU), and computer-to-computer communications via high-speed serial TTL.<\/p>\n<div id=\"attachment_3489\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3489\" loading=\"lazy\" class=\"size-large wp-image-3489\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0822-800x326.png\" alt=\"Plug &amp; Play Sensor modules, from $0.50 to $2.00 each. Shown: flame detector (light spectrum), sound detector (microphone), magnetic reed switch, Hall effect sensor, metal touch sensor, and thermistor (human touch)\" width=\"640\" height=\"261\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0822-800x326.png 800w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0822-300x122.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0822-150x61.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0822-400x163.png 400w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0822.png 813w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><p id=\"caption-attachment-3489\" class=\"wp-caption-text\">Plug &amp; Play Sensor modules, from $0.50 to $2.00 each. Shown: flame detector (light spectrum), sound detector (microphone), magnetic reed switch, Hall effect sensor, metal touch sensor, and thermistor (human touch)<\/p><\/div>\n<p><strong>What you create is limited only by your own imagination.<\/strong> Happy creating!<\/p>\n<hr \/>\n<h3>Pushing the Boat Out with the ATTINY microcontrollers &#8211; Super Low-Power, Low-Cost, Small Size<\/h3>\n<p>(April 30th, 2021)<\/p>\n<p>Two years ago I wrote the above, and it is still valid (though electronic component prices seem to have increased by 1.5-3x since then, ostensibly due to the COVID pandemic\/semiconductor crisis).  You can still find most of the components to keep the cost below \u00a312.<\/p>\n<p>Since then, I&#8217;ve added a few techniques to enable rapid prototyping with Atmel microcontrollers.<\/p>\n<p>The first is a <strong>3-instruction Forth<\/strong> platform written for the Atmel328P processor (Nano, Uno, etc.) and communicating over a serial link with the host computer, typically your laptop (you currently need RealTerm free software to open the connection, after which you can drop into GForth).  <\/p>\n<p>The key value that this software brings is that you can work directly with the microcontroller in an interactive, dynamic Forth environment (I use GForth on Windows).  Using this it&#8217;s taken me as little as 30 minutes to wire up and test the functionality of a new sensor or component, without the compile, deploy, and fix programming loop that Arduino&#8217;s native C-code forces upon you.  A Forth installation gives you a dynamic, fully interactive environment in which your code can be live-tested and edited\/extended.<\/p>\n<p>Once you&#8217;re happy with your application and have worked through all the quirks and bugs in your design, then it&#8217;s usually a straightforward matter to create an untethered application.  You simply translate what worked from Forth back into C code and compile the driver logic directly into the Nano.<\/p>\n<p>Even more nifty is that you can use the same Arduino\/Forth development chain and drop from the Nano to the ATTiny85 (DIP-8, 5 I\/O pins) or ATTiny84 (DIP-14, 11 I\/O pins) microcontroller.  This really shrinks things down and delivers lower power, lower cost, and significantly smaller sized little things.  For starters, the ATTiny85 is DIP-8, the Nano is DIP-30.  The ATTiny85 sips on avg 3mA power in a benchmark use vs. 20mA power for the Nano.  So, as long as none of the rest of your components require 5VDC (check your IC ratings!), you can get away with the need for a DC boost converter and simply power your device entirely using a 3V battery (could be a 3V coin cell, a 3V LiIon battery, or 2x any 1.5V battery whether button cell, AAA, or AA, C or D batteries)!  With a bit of soldering and some small prototype PCB you can make some nifty little gadgets.<\/p>\n<div id=\"attachment_7074\" style=\"width: 338px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2104.png\"><img decoding=\"async\" aria-describedby=\"caption-attachment-7074\" loading=\"lazy\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2104.png\" alt=\"\" width=\"328\" height=\"305\" class=\"size-full wp-image-7074\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2104.png 328w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2104-300x279.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2104-150x139.png 150w\" sizes=\"auto, (max-width: 328px) 100vw, 328px\" \/><\/a><p id=\"caption-attachment-7074\" class=\"wp-caption-text\">Knight Rider LED device powered by ATtiny85 controlling shift out register IC 74595 all powered by 3V button cell battery<\/p><\/div>\n<p>Code that works on the Nano typically needs only a new pin assignment to Atiny using preprocessing conditionals #ifdef TINY85 &#8230; #endif and #ifdef NANO &#8230; #endif to keep a single code base.  For an example with details on how to do this, including code for dropping from Nano into ATTiny, and what you need to do to compile for the Tiny uCs, see my article on <a href=\"https:\/\/mathscitech.org\/articles\/talking-sensors\" rel=\"noopener noreferrer\" target=\"_blank\">Making Sensors Talk for Under \u00a35<\/a>.<\/p>\n<div id=\"attachment_6707\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/04\/03-TalkingPIRsensor_06b_2021-04-03.jpg\"><img decoding=\"async\" aria-describedby=\"caption-attachment-6707\" loading=\"lazy\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/04\/03-TalkingPIRsensor_06b_2021-04-03-300x186.jpg\" alt=\"\" width=\"300\" height=\"186\" class=\"size-medium wp-image-6707\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/04\/03-TalkingPIRsensor_06b_2021-04-03-300x186.jpg 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/04\/03-TalkingPIRsensor_06b_2021-04-03-800x497.jpg 800w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/04\/03-TalkingPIRsensor_06b_2021-04-03-768x477.jpg 768w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/04\/03-TalkingPIRsensor_06b_2021-04-03-150x93.jpg 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/04\/03-TalkingPIRsensor_06b_2021-04-03-400x248.jpg 400w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/04\/03-TalkingPIRsensor_06b_2021-04-03.jpg 850w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-6707\" class=\"wp-caption-text\">Bringing Junk Model Robots to life with Talking Motion Sensors (April Fools Prank, 2021)<\/p><\/div>\n<p>Enjoy!<\/p>\n<h3>Further Reading<\/h3>\n<ul>\n<li><a href=\"https:\/\/mathscitech.org\/articles\/exploring-electronics\" target=\"_blank\" rel=\"noopener noreferrer\">Electronics in the Junior School &#8211; Gateway to Technology<\/a><\/li>\n<li><a href=\"https:\/\/mathscitech.org\/articles\/turtle-logo-forth\" target=\"_blank\" rel=\"noopener noreferrer\">Coding for Pre-Schoolers: a &#8216;Turtle Logo&#8217; in Forth<\/a>&nbsp;<\/li>\n<li><a href=\"https:\/\/mathscitech.org\/articles\/exploring-electronics\" target=\"_blank\" rel=\"noopener noreferrer\">Photo gallery of electronic projects<\/a> not requiring microcontrollers, including:\n<ol>\n<li><a href=\"https:\/\/mathscitech.org\/articles\/building-music-synthesizer\" target=\"_blank\" rel=\"noopener noreferrer\">Building a 13-key pure analog electronic piano<\/a><\/li>\n<p> (musical keyboard) using only transistors, capacitors, and resistors to generate the sound<\/p>\n<li>a universal siren simulator capable of adjusting the pitch of the &#8220;nee&#8221; and &#8220;naw&#8221; separately, as well as the speed of the nee-naws,\n<li>a plant thirst detector,\n<li>a UV black light,\n<li>a magic wand using tiny magnets, capable of creating magic effects using magnetic reed switches,\n<li>various LED flashlights and small handheld reading lights,\n<li>lighting for lego house using 2x 3V button batteries,\n<li>a 5-cell lemon juice battery,\n<li>a wearable circuit for a homemade Christmas jumper,\n<li>a step motor controller.\n<\/ol>\n<\/ul>\n<div id=\"attachment_3444\" style=\"width: 650px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3444\" loading=\"lazy\" class=\"size-large wp-image-3444\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/527DED14-7493-4E68-A585-3BA8D82144EB-800x600.jpeg\" alt=\"Medly of electronics projects built from Nov 2018 - April 2019. \" width=\"640\" height=\"480\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/527DED14-7493-4E68-A585-3BA8D82144EB-800x600.jpeg 800w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/527DED14-7493-4E68-A585-3BA8D82144EB-300x225.jpeg 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/527DED14-7493-4E68-A585-3BA8D82144EB-150x113.jpeg 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/527DED14-7493-4E68-A585-3BA8D82144EB-400x300.jpeg 400w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><p id=\"caption-attachment-3444\" class=\"wp-caption-text\">Medly of electronics projects built from Nov 2018 &#8211; April 2019.<\/p><\/div>\n<p>&nbsp;<\/p>\n<ul>\n<li>For an <a href=\"https:\/\/mathscitech.org\/articles\/electronics\" target=\"_blank\" rel=\"noopener noreferrer\">exhaustive supply list<\/a> of electronics components, supplies, equipment, microcontrollers, sensors &amp; motors.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><a id=\"uc-refs\"><\/a><\/p>\n<h2>Appendices<\/h2>\n<p><strong>Appendix 0: Comparison Table for Recommended Microcontrollers<\/strong><br \/>\n<div id=\"attachment_7184\" style=\"width: 1070px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/Electronic_uC_Chip_List-1.png\"><img decoding=\"async\" aria-describedby=\"caption-attachment-7184\" loading=\"lazy\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/Electronic_uC_Chip_List-1.png\" alt=\"\" width=\"1060\" height=\"512\" class=\"size-full wp-image-7184\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/Electronic_uC_Chip_List-1.png 1060w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/Electronic_uC_Chip_List-1-300x145.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/Electronic_uC_Chip_List-1-800x386.png 800w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/Electronic_uC_Chip_List-1-768x371.png 768w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/Electronic_uC_Chip_List-1-150x72.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/Electronic_uC_Chip_List-1-400x193.png 400w\" sizes=\"auto, (max-width: 1060px) 100vw, 1060px\" \/><\/a><p id=\"caption-attachment-7184\" class=\"wp-caption-text\">Microcontroller Comparison table: Arduino Nano, Attiny, ESP, etc.<\/p><\/div><\/p>\n<hr\/>\n<p><strong>Appendix 1A. Pinout of Arduino Nano v3<\/strong><br \/>\n<div id=\"attachment_3462\" style=\"width: 692px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" aria-describedby=\"caption-attachment-3462\" loading=\"lazy\" class=\"size-full wp-image-3462\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0781.png\" alt=\"Arduino Nano pinout\" width=\"682\" height=\"532\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0781.png 682w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0781-300x234.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0781-150x117.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.0781-400x312.png 400w\" sizes=\"auto, (max-width: 682px) 100vw, 682px\" \/><p id=\"caption-attachment-3462\" class=\"wp-caption-text\">Arduino Nano pinout<\/p><\/div><\/p>\n<p><strong>Appendix 1B. <a href=\"https:\/\/components101.com\/microcontrollers\/arduino-nano\" target=\"_blank\" rel=\"noopener noreferrer\">Pin Specification and User Guide for Arduino Nano<\/a> (Components 101.com)<\/strong><\/p>\n<p><strong>Appendix 2. Pinout of ATtiny85\/84<\/strong><br \/>\n<div id=\"attachment_6430\" style=\"width: 590px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/screenshot.1950.png\"><img decoding=\"async\" aria-describedby=\"caption-attachment-6430\" loading=\"lazy\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/screenshot.1950.png\" alt=\"\" width=\"580\" height=\"419\" class=\"size-full wp-image-6430\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/screenshot.1950.png 580w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/screenshot.1950-300x217.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/screenshot.1950-150x108.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2021\/01\/screenshot.1950-400x289.png 400w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/a><p id=\"caption-attachment-6430\" class=\"wp-caption-text\">Wiring the Tiny84 to program it using Sparkfun&#8217;s Tiny AVR programmer (intended for Tiny85).<\/p><\/div><\/p>\n<p><strong>Appendix 3. Arduino C cheat sheet<\/strong><br \/>\n<a href=\"http:\/\/mathscitech.org\/papers\/02a-Arduino_Cheat_Sheet.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">PDF1<\/a><\/p>\n<p><a href=\"http:\/\/mathscitech.org\/papers\/02b-Arduino_Cheat_Sheet.pdf\" target=\"_blank\" rel=\"noopener noreferrer\">PDF2<\/a><\/p>\n<p><strong>Appendix 4. Traffic light module &#8211; Hack to increase green LED brightness<\/strong><br \/>\nThe LEDs may be nice and big (10mm?) in your traffic light module.  If the green LED on yours is much dimmer than the others and not easily seen, try the following <a href=\"https:\/\/youtu.be\/53HuJlzYR00?t=403\" rel=\"noopener noreferrer\" target=\"_blank\">workaround<\/a>: solder a 33R resistor across the terminals of the surface-mounted 330R resistor, creating a parallel connection through the LED with higher voltage.  The original low brightness is due to the designer applying the same surface-mounted 330R current-limiting resistor to each LED, instead of using a lower value for green.<\/p>\n<div id=\"attachment_6967\" style=\"width: 468px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2096.png\"><img decoding=\"async\" aria-describedby=\"caption-attachment-6967\" loading=\"lazy\" src=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2096.png\" alt=\"\" width=\"458\" height=\"347\" class=\"size-full wp-image-6967\" srcset=\"https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2096.png 458w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2096-300x227.png 300w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2096-150x114.png 150w, https:\/\/mathscitech.org\/articles\/wp-content\/uploads\/2019\/09\/screenshot.2096-400x303.png 400w\" sizes=\"auto, (max-width: 458px) 100vw, 458px\" \/><\/a><p id=\"caption-attachment-6967\" class=\"wp-caption-text\">To increase the brightness of the Green LED, solder a 33-ohm resistor across the surface-mount 330R resistor  to create a lower-resistance, higher-voltage\/current parallel path.<\/p><\/div>\n<p><strong>Appendix 5. Traffic controller software<\/strong><\/p>\n<p><code><br \/>\n\/* This program uses the Arduino Nano low cost development board to control a Traffic Light module (R\/Y\/G LEDs)<br \/>\nNote: Took 60 minutes from concept to completion.<br \/>\n*\/<\/p>\n<p>\/* 2019-09-29---Sun---12:07<br \/>\n   Assad Ebrahim<br \/>\n   Board: Arduino Nano<br \/>\n   Processor: Atmega 328P<br \/>\n   Port: COM5<br \/>\n   Programmer: USBtinyISP  (not applicable \/ relevant)<br \/>\n*\/<\/p>\n<p>\/\/ requires 6 pins<br \/>\n#define NS_RED     5  \/\/ north-south lights<br \/>\n#define NS_YELLOW  6<br \/>\n#define NS_GREEN   7<br \/>\n#define EW_RED     2  \/\/ east-west lights<br \/>\n#define EW_YELLOW  3<br \/>\n#define EW_GREEN   4<br \/>\n\/\/ constants (not pins)<br \/>\n#define EW 0<br \/>\n#define NS 1<\/p>\n<p>void setup() {<br \/>\n  pinMode(NS_RED, OUTPUT);<br \/>\n  pinMode(EW_RED, OUTPUT);<br \/>\n  pinMode(NS_YELLOW, OUTPUT);<br \/>\n  pinMode(EW_YELLOW, OUTPUT);<br \/>\n  pinMode(NS_GREEN, OUTPUT);<br \/>\n  pinMode(EW_GREEN, OUTPUT);<br \/>\n  delay(500);  \/\/ pin settle time<br \/>\n\/\/starting configuration - starts with NS lights red, EW lights green<br \/>\n  digitalWrite(NS_RED, HIGH);  digitalWrite(EW_RED, LOW);<br \/>\n  digitalWrite(NS_GREEN, LOW); digitalWrite(EW_GREEN, HIGH);<br \/>\n  digitalWrite(NS_YELLOW, LOW);<br \/>\n  digitalWrite(EW_YELLOW, LOW);<br \/>\n  delay(4000);<br \/>\n}<\/p>\n<p>void loop()<br \/>\n{ \/\/ Design:<br \/>\n  \/\/ Both stopping & starting go through Amber, but starting goes from red to red\/amber before green, while stopping goes G->A->R.<br \/>\n  \/\/ Timings staggered so law-breaking red light runners pass before crossing lane's startup sequence.<br \/>\n  stop_intersection(EW);<br \/>\n  start_intersection(NS);<br \/>\n  stop_intersection(NS);<br \/>\n  start_intersection(EW);<br \/>\n  return;<br \/>\n}<\/p>\n<p>\/\/ Functions<br \/>\nvoid stop_intersection(int inters)<br \/>\n{<br \/>\n  digitalWrite(inters==EW?EW_YELLOW:NS_YELLOW, HIGH); digitalWrite(inters==EW?EW_GREEN:NS_GREEN, LOW);<br \/>\n  delay(1000);<br \/>\n  digitalWrite(inters==EW?EW_RED:NS_RED, HIGH); digitalWrite(inters==EW?EW_YELLOW:NS_YELLOW, LOW);<br \/>\n  delay(500);<br \/>\n  return;<br \/>\n}<\/p>\n<p>void start_intersection(int inters)<br \/>\n{<br \/>\n  \/\/ start NS<br \/>\n  digitalWrite(inters==NS?NS_YELLOW:EW_YELLOW, HIGH);<br \/>\n  delay(1000);<br \/>\n  digitalWrite(inters==NS?NS_GREEN:EW_GREEN, HIGH); digitalWrite(inters==NS?NS_YELLOW:EW_YELLOW, LOW); digitalWrite(inters==NS?NS_RED:EW_RED,LOW);<br \/>\n  delay(4000);<br \/>\n}<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>For under \u00a310, you can put together a microcontroller development platform, ready to program directly from your PC over USB using free Arduino software. Once programmed, your microcontroller will run autonomously, untethered from your PC, powered by as small a battery power supply as a single 1.5V AAA or 3V CR2032 coin cell. You can [Read More&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[7,132,3,18,12],"tags":[174,121,172,173,40,128,41,170],"coauthors":[112],"class_list":["post-3435","post","type-post","status-publish","format-standard","hentry","category-education","category-electronics","category-general","category-programming","category-technology","tag-arduino","tag-education","tag-electronics","tag-microcontrollers","tag-sensors","tag-stem","tag-systems","tag-tech-for-children","odd"],"views":7470,"_links":{"self":[{"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/posts\/3435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/comments?post=3435"}],"version-history":[{"count":87,"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/posts\/3435\/revisions"}],"predecessor-version":[{"id":11771,"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/posts\/3435\/revisions\/11771"}],"wp:attachment":[{"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/media?parent=3435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/categories?post=3435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/tags?post=3435"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/mathscitech.org\/articles\/wp-json\/wp\/v2\/coauthors?post=3435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}