This section will cover the various design attempts on an Arduino Nano. I would have used a simulation
software called TinkerCad, but it lags far too much on my laptop to be all that useful. Instead I have
built the circuits up in stages in real life. I will be recycling an older project that used a Nano as
I find it easier to breadboard small scale circuits with a Nano, plus the recycled project already has
two homemade RGB LEDs fixed in.
The first part of this is to set up a Button circuit: a button between logic High and the Input pin
and a large resistor between the Input pin and Ground, so as to return the Input to Low when the button
is open, without shorting 5V to ground and setting your microcontroller on fire. Its a questionable but
good habit to occasionally touch the main IC (or the Regulator unit on larger boards) every now and then,
just to tell if you have accidentally shorted the entire microcontroller. From past experience this has
saved quite a number of Microcontrollers from my carelessly improvised wiring.
Next, set up some LEDs and a few limiting resistors, on the Nano I'm using this comes in the form of a
sawn off 10K Variable resistor and all the LEDs being Active-Low. The LED bank is tied to a shared 5V pin
which was also used to power a small OLED screen, which has been removed to show the absolute mess of wires.
Now comes the code. The code here is somewhat messy, but its arranged to make this slightly easier to modify
and pile on more stuff later on. On the left you will see all the initialisation, the ones Highlighted are
all that matter for this stage. On the right you will see the structure for the cycling process:
Set an Integer
to be 0 to begin with, then everytime the button is pressed, the Input pin goes to High, Waits a few milliseconds
to account for any debounce oscillation, and then increases the Integer by 1. And repeat forever.
By locking it in a For loop, it makes the process run forever, and allows me to control exaclty how many possible
states the Integer can have, When it gets increased by 1, and what Triggers it to increase by 1.
Also because it allows me to overclock and test the loop by setting the Debounce delay to delay(1);
Originally, I just had 3 possible states, 4 if you count the OFF state, Int 0 meant all LEDs were off, Int 1
meant the Reds were on, Int 2 meant the Greens were on, and int 3 meant the Blues were on. Which was simple
enough, and even easier to add more stages if needed with the magical Ctrl C and Ctrl V.
what makes this structure good, is that you can squeeze just about any function into those states, So I decided
to add the tiny OLED back to the circuit, and output a little display that changed from one state to another
I even managed to Overclock this, to have 8 (0 to 7) possible configurations, and two switches that could configure
Each state in 1 of 4 ways, which would give a total of 28 possible states.
But after this, it became clear that I had to get more breadboard space.
The next stage would be to read Analog levels on the arduino using LDRs, to give an even wider range of possible states.
I tend to think of this as more of Semi-Analog. It does input an analog value on the serial plotter, But it only gives
a useful integer range of something like 130 to 720. The hope is to use this range and split this into 4 ranges,
From 130 to 277, turn off all LEDs.
From 277 to 424, turn on the Red LED
From 424 to 571, turn on the Green LED
From 571 to 720, turn on the Blue LED
I started this using a Variable Resistor, and I only just managed to capture a pulse on screen when it happened.
Using this Circit
Now a slight problem, I might have broken the LDR somehow. I tried fixing it properly onto the UNO instead
but even then I could not get it to give a large enough range of values. Here is the updated circuit layout:
Here is me shining a really powerful torchlight onto it
And here is the slightly unsatisfying result
Its definitely not an issue with the Arduino or the analog pin as I tried this again using a different pin
and tried to use a Variable Resistor instead. Even then, its just the LDR that has an issue.
For this segment, we will be using a DHT11 which apparently does not have a standard library Included in Arduino IDE
so we will first have to google for one. Once you find one, let your antivirus tell you its okay, and then copy it into
your Library directory. It might be under Documents/Arduino/Libraries. Take note of the file directory shown below.
Set up the circuit as seen here
Once that is done, go get the sample code and use it here.
Great way to test if it works, hold up the board and exhale on the sensor, especially if you're in an
air conditioned room. You can see the jump in humidity between the second and third entries on the monitor.
For this part, Plug in your ultrasonic sensor as shown here, take note of the trigger and echo pins.
Now put some random object up some distance from the sensor, such as this measuring tape roughly 11-12 cm away.
Now use this bit of code which determines the range of the object, based on the time taken to pulse and return the signal
and the speed of sound in air which is somehwere around 300m/s.
Works fairly well on the monitor, Its okay that it hesitates between 11 and 12 because the measuring tape was around 11.4cm away
Looks even better on the serial plotter. If you look closely you can see the exact point I dropped the measuring
tape on my foot by accident and started slamming on the desk.
And that's all for messing around with the sensors, now for the final project.