Last week I only had 2 lessons for robotics since a public holiday took away one lesson. This meant I wasn’t able to get a whole lot done, but I decided the next thing I want to make with the Arduino kits is a kind of lock system with a relay, as in a button which can flip a relay, and only when the relay is set to the right position can I control something else, currently an LED, with a 10K potentiometer. This idea is harder than I though it would be, but I was able to construct the hardware, which I believe is fine, in the first lesson.

While, as far as I am aware, the hardware here works, it was not built well for testing or use. Having the button and potentiometer in between all the wires makes it difficult to control the system, and so I am going to try and fix that next lesson.

I am not needing as much reference when trying to construct these systems anymore, as I am learning the general rules from which colour wire to what each pin in the relay does. I am least familiar with the potentiometer, which I needed a pinout for. For everything else in this system, I was able to remember which parts go where.

The programming has been much harder than physical construction for the previous few projects. For this one, the setup was relatively straightforward, setting variables for which parts connect to which digital/analog pin, and setting which are output and input pins. I had to work out how to code a debounce for the button input, which would prevent the system registering multiple inputs for a single button press.

This took some time to figure out, but in the end it’s not too complicated, and it makes sense. With this working, the button would successfully flip the position of the relay, and from there I needed to code a way to control the LED with a potentiometer. Since the LED can only be off or on, and it’s brightness can’t be controlled, the values from the potentiometer were mapped to 0 to 1, representing off and on respectively. However this section has been the hardest, and I haven’t yet been able to make it work. The part to control an LED with the potentiometer makes sense logically, as I take the mapped value, and switch the LED to on or off based on what it is, however I’m not sure how to do this in conjunction with the relay. This is because I don’t know if I should have the two sections (the relay and the potentiometer) running simultaneously, or if i should somehow check what position the relay is in and then allow the potentiometer to work based on that. From what I can tell, there should be no reason why I can’t run them simultaneously, as I can check for inputs at anytime, but the potentiometer won’t be able to send them unless the power is sent through the relay. I plan to spend some time testing the inputs I get when I turn the potentiometer while the relay is on, and when it’s off, and from that see what strategy seems most effective.