First project review request. Fan controller.

Hi gang,

I am putting together my first actual project after going through the tutorials on the Ardunio. I was hoping to get some input from everyone about the project in general and a code review if possible.

Scenario: My wife and I leave a fan on at night when we are sleeping to provide white noise and air movement (think box fan on steroids). We go to bed and wake up at different times, so in the end one of us is always complaining that the other forgot to turn off the fan. I figured I would try to automate it.

Project: I decided to build a project to control the fan. There will be a push button to cycle through the modes. When the mode changes a different colored LED will light to indicate the mode. That LED will then turn off after a predetermined time to maximize the darkness in the room.

The modes are:
On: Fan on. Green.
Off: Fan off. Red.
Auto: Fan automatically controlled. Blue.

Auto mode: The fan will be automatically controlled in auto mode. My intention is to put two pressure sensitive Velostat pads under the mattress on each side of the bed. These should decrease their resistance when someone is lying on top of the mattress. When someone lies down on either side of the bed the fan will turn on. As long as one side of the bed has someone on it the fan will stay on. If both people get up the fan will remain on for a predetermined length of time, such as five minutes, to allow someone to go to the restroom or whatever. It will then turn itself off until someone lies down again.

Attached is a schematic of what I have in mind. Please forgive that the Ground bus is on the top and +5V bus is on the bottom. It throws me off, but was the easiest way for me to draw it with the Arduino right side up.

Code: I have done a fair amount of mid-level programming, though never for microcontrollers and never using a C variant language. I am hoping for some code review. Please let me know of anything that may have been done in a stupid way. In particular my implementation of void functions vs. functions that return values and my usage of enums for the mode. I don't feel like I have a very good handle on abstraction with the function definitions.

As info, the system does seem to actually work correctly on the breadboard. I just don't know that it was done in the best way.

Thank you for your time, I know it is valuable.

NappyTimeFanController.ino (6.08 KB)

Thank you for taking care of my in line posting issues. I assumed that that code would be too large to go that route, but I am new to this. Here is the relay module that I am using. It has an opto-isolated input but requires and positive and negative input to drive the module. I have it set to use a high input to energize the relay.

Thank you.

@holdingpattern, I can't argue that point. Perhaps if you had two totally separate sources of power. Not sure. That is why I'm looking for help. Thanks.

Thanks @holdingpattern. I'm don't really know what the JD style is. Can you provide a link to a product or information. It sounds pretty interesting to be able to have total isolation like that, I'm just not familiar.

Thank you very much. i will definitely look into going this route. So does this mean that to have total isolation you would need totally separate power supplies? I'm just trying to understand at what point you separate the two sides. Would having two different 5V power supplies isolate you or would you still have to worry about about electrical isolation from each power supply. For example, would you need to have transformers on each supply to provide isolation?

That module has an opto isolator, you need a separate 5V supply rated at least 150mA to power the relay coil. Connect external supply + to relay DC+ along with Arduino 5V, external - to relay DC-, Arduino output pin to relay IN terminal, set relay module jumper to LOW switching. Since you only have two wires from Arduino to relay and one of them is connected to the opto's input, it WILL be isolated.
EDIT: Assuming a LOW true type relay module.

Hi,
It would be easier and less components to wire your two pots like this;

Tom... :slight_smile:

And that zener diode will be a short circuit when the AC swings negative.

JCA34F:
And that zener diode will be a short circuit when the AC swings negative.

Good catch. That should have been a back to back pair. Thank you.

TomGeorge:
Hi,
It would be easier and less components to wire your two pots like this;

Tom... :slight_smile:

Thank you for the information. In this case they are not pots though. They are pressure sensitive pads whose resistance decreases with pressure. Since there are only two leads (effectively a rheostat) I figured I would need to create some form of a voltage divider to read the change in pressure. This does work, though there certainly may be a better or simpler way.