In this tutorial, we’ll learn how to build an Arduino-powered ceiling fan using a Raspberry Pi.
If you’re not a fan of using an Arduino, you can use a RaspberryPi with the Raspberry Pi GPIO pins, but that might take a little bit longer to set up.
We’ll also be adding an optional LED strip for a cool effect.
The idea is that the ceiling fan will power an LED on the ceiling when the ceiling lights up.
In this tutorial we’re going to create a simple ceiling fan that powers a simple LED strip on the wall.
We’ll use an Arduino Leonardo, but you could use an Anker BATT, an Arduino Mega or even an Arduino Uno if you want to build it using a different chip.
If you want, you could even just solder a Raspberry pi to the wall using the GPIO pins.
Before you begin, you’ll need an Arduino IDE.
The Arduino Leonardo IDE is available for free at Adafruit and the Raspberry pi site is the place to go if you don’t already have one.
Open up your IDE by clicking File->Open.
This will open a new window.
In the top-right corner of the window, click on the little yellow arrow to bring up the menu.
Under the menu, click Tools.
In here you’ll find the Arduino IDE for Windows.
Right-click the Arduino Leonardo file and choose Save as….
In this new window, you should see a toolbar icon.
Click on it and select the Save As button.
Next, you want a name for your Arduino project.
We’re going with the name of our project, so click on File->New.
We can name our project something like FloorFan.
Now, in the top left corner of your IDE, click New….
Here you’ll see a new tab that says Project.
Now click on FloorFan to name your project.
In my case, I named it FloorFan1.
Now we’re ready to build our ceiling fan.
In our new project, we can add some LEDs to the Arduino and then connect them to the LEDs on the Raspberry PI.
The Arduino has GPIO pins to control the lights, so we’ll need to use that pin as a source.
You’ll need the Arduino libraries to do this.
We already have the code for this, so I’ll just add a few lines to the bottom of the file.
We also need to set the brightness of the LEDs, so let’s make that a bit brighter by adding this code.
Now, when you’re finished with the code, click File->Save As….
This opens up a new dialog that looks like this.
You can click OK to close it.
Now that we’ve got our Arduino sketch working, we’re now ready to use it.
We just need to make sure the pins we’re connecting to are accessible to the code we’ve written.
Open up the Arduino sketch and then select Tools->Serial Monitor.
You should see the Arduino pinout printed out in green.
Next click the serial monitor button to open it up.
This should give you access to the pins that we’re connected to.
In order to connect to the lights on the Arduino, we need to connect the pin that controls the LED to the pin in the Arduino.
Open the Arduino code and add this code: Here we have the function we’re using to turn on the lights.
The code for the function will be shown below: Now we’re just going to connect those two pins.
When you add the code to your Arduino sketch, you will see a warning that says “The function could not be found.”
We’ll need that function later.
We’ve now connected the pins on the Arduino to the lines we’re calling to set them on the LEDs.
Now let’s see how we can wire them up to the GPIO pin.
Right click the Arduino Sketch and choose New->GPIO.
Here we’ll add a new line, that reads “Pin A to GPIO 0”.
The pin that we added to is the same pin that’s labeled “LEDS”.
This means that the LED on your Arduino will have the same brightness as the LED lights on your ceiling fan on your walls.
Now if we press the GPIO button, we should see something like this: Now we can test this out by powering up the lights and then powering down.
We could use a simple wire to power up the LED and then the fan.
Instead, let’s do it using an analogWrite function.
Open your Arduino Sketch.
Right Click on the sketch and choose Edit->New Function….
Enter an expression and then press OK.
Next we need a way to wire up the two pins that the Arduino uses for the LEDs to each other.
We need to put some code in our code to do that.
Open Up the Arduino Code Editor and add the following code to the function definition. We then