Embedded Programming

Sometime by Week 8...

Assignment

The assignment asked us to program a board, and ideally with an external output as well.

I had the idea of a Timer controlled NightLight in my head over the last couple of weeks. Since it was something I really needed in my life, I decided to work on that.

Concept :

The concept is basically a version of a deadman's switch, but with a 30 minute delay. A microcontroller board controls a relay that can turn an external lamp On and Off. The input to the MCU is a switch, and the logic being, the MCU turns the lamp On whenever the switch is activated, and turns it Off 30 mins from that point. This goes on unless the switch is triggered again, at which point the timer resets for another 30 minutes.

This is useful - definitely to me - but also to others, in the following cases :

  • if you either tend to fall asleep with the lights on,
  • you want some amount of light on when you get into bed but want them off once you are asleep,
  • your light switches are simply out of reach if you're in bed

While I had managed to get the XIAOs and other boards working, for this assignment I chose to use an Arduino Nano

  • I didn't want to solder anything directly to the boards, and I had no access or practice with a PCB milling machine. So the header pins could be easily enough jumper-cabled around, unlike the SamD21 or the XIAO which need a dev-board or PCB.
  • At this point, I just had one piece of everything, so I didn't want to use up a board in a deployment. (Although I almost went with the SamD21 since I don't have any plans for it yet)
  • The Nano is cheaper than the XIAO, etc by a wide margin.

The ideal board to use for such a simple application would be the ATTiny85, but unfortunately, I have had trouble getting them to work, and then, during some lab maintenance and cleanup shuffle, they have gone missing. Having been unwell as well as travelling in the past weeks, I have not been able to prioritise tackling the ATTinys, especially since the rest have been working.

Arduino Nano

I thought that having worked out all the other MCUs and having worked with the Uno in the past, the Nano would be rather easy to work with. It was, and it wasn't, like all the rest of this. Hindsight being 20-20 and all that.

I had older projects using relays triggered by LDR based input, so I used those as a starting point.
Cupheater

I replaced the LDR with a Tactile switch. The switch kept triggering weirdly, so I realised I can't get away without adding a pulldown resistor. Another lesson learnt.

Nano and Relay
The Arduino Nano with a Relay and a male-female plug that I had made earlier.

Nano and Relay The Relay wired up and tested.

This works in principle. Unfortunately, the Ikea table lamp I wanted to control has a slightly larger 2-pin plug than the female plug on my unit can accommodate.

Eventually, however, I obtained a bigger 2-pin plug that would take the larger plug, and tested out the entire system.

Relay01

Relay02

Relay03

For the above video, the time limit before turning off the Lamp is 5 seconds for demonstration, the code file uses 10 mins as the limit since that is my ideal application for a night lamp that turns off after some time.

Learning

The Nano would not show up in the IDE. Trawling the forums, the solution was simply to tick the use of "Old Bootloader" in the options.

Forum Post

Nano Issues Nano Issues

Resources

Blink without delay()
LDR with Arduino
Relay with Arduino

My Cupheater on TinkerCAD

Nano documentation https://docs.arduino.cc/hardware/nano https://robu.in/arduino-nano-board-pinout-programming-guide-2020/

Exercise Files

Nano Relay Timer using millis