Last modified: 06.08.2020
started: 10.07.2019
I want to be able to control a number of Garden Lights from a web page.
Plan 1, last modified: 06.08.2020 22.09.2019
These lights are Infrared remote controlled rgb flood lights I bought cheap from ali Express. I can control these lights by sending a IR signal with a micro controller. But I want to control them from a web page using the VoffCon system. I want to use the Arduino Nano to control one or two the flood light by sending signals with a transmitting ir diode module. To tell the arduino what to do I am going to use the Nrf24L01 which is a cheap universal ISM band monolithic transceiver which works on 2.4-2.5GHz to communicate with a Wifi micro controller connected to VoffCon. So from VoffCon I can send commands to the esp32 via LAN (WiFi) and the esp32 will send the command to the Arduino Nano using a Nrf24L01.
I will also need a VS1838B infrared sensor to learn all the codes the Food light remote control can send.
I experimented with a new plan starting from 16.7.2020. In that plan I tried to skipp usagne of the Nrf24L01 see below: A new approach (Plan 2). But I was not happy with the result so I will continue working with this plan but change it by not making the Esp32 change any spotlight directly. The esp32 will be used as a hub to relay messages to Arduino Nanos, and only the nanos will command the floodlights.
This is how I plan to setup the devices needed. The blue part of the image in the middle is my house. the little icons "01" and "00" are two micro controllers located in windows in my garage.
We will have two micro controllers inside my garage. One Esp32 and one Arduino nano. Out side in the garden we will have six flood lights of two types. The color of one type is silver and the color of the other type is black. I own two silver and four black. The two types have different IR remote control codes but every thing else is the same.
I will need these items for the project
First things first, start by getting the three Libraries I need.
Information on how I connected the sensor to the arduino. I did not use the 100Ω resistor like I was suppose to.
This is the sketch I used to detect signal from the remote control. It is located in IRemote examples and is named IRrecvDemo.ino.
Information on how I connected the transmitter to the arduino. And a image of the remote control. If you view the code you should see that the irCommand array is set up like the buttons are located on the remote.
After detecting all the signal I was able to create this sketch to control the flood light. The sketch sends commands typed to the serial and then send on to the flood light.SendIRtoFloodlight.ino The data pin (send pin) must be D3. For example if a user types "ON" without the quotes then the micro controller sends the "ON" IR code to the flood light. If a user types "RED" then the flood light turns red.
I downloaded the RF24 library, connected each Arduino Nano to a Nrf24L01 by using the wiring information from the table below. Turned on both nanos, and they started communicating. easy peasy 😀.
PIN | NRF24L01 | Arduino Nano | Esp32 Development module | NodeMCU Development module | ATtiny25/45/85 [0] | ATtiny44/84 [1] | LittleWire [2] | RPI | RPi -P1 Connector |
---|---|---|---|---|---|---|---|---|---|
1 | GND | GND | GND | GND | pin 4 | pin 14 | GND | rpi-gnd | (25) |
2 | VCC | 3.3V | 3V3 | 3V3 | pin 8 | pin 1 | regulator 3.3V required | rpi-3v3 | (17) |
3 | CE | D7 | D12 | D?? | pin 2 | pin 12 | pin to 3.3V | rpi-gpio22 | (15) |
4 | CSN | D8 | D14 | D?? | pin 3 | pin 11 | RESET | rpi-gpio8 | (24) |
5 | SCK | D13 | D18 | D?? | pin 7 | pin 9 | SCK | rpi-sckl | (23) |
6 | MOSI | D11 | D23 | D?? | pin 6 | pin 7 | MOSI | rpi-mosi | (19) |
7 | MISO | D12 | D19 | D?? | pin 5 | pin 8 | MISO | rpi-miso | (21) |
8 | IRQ | - | - | - | - | - | - | - | - |
The code running on both Arduino Nanos are form a RF24 example sketch called GettingStarted.
The only difference between the codes on the Nanos is line 22. where role is changed from 0 to 1.
// Coming soon
I decided to use the RF24Network library to test how hard it would be. It turns out that it's easy. View the code on both Nanos to see how easy it really is. 😊
Spotlight Infrared Remote Controller listens for commands from the Spotlight Commander and execute them by sending Infrared signal commands to the spotlight.
// Coming soon
Spotlight Commander will listen for commands from the serial port and send them wireless's to the Spotlight Remote Controller.
// Coming soon
If it works on Nano it is not certain it will work on the esp32. But surprisingly it worked on the Esp32 dev module by connecting it like described in the sketch. Only thing I had to change was line 22 because I am using other pins for the CE and the CSN. Change pin 7 to 12 and pin 8 to 14.
By viewing the pin-out for the Esp32 Development model I was able to add the "Esp32 dev module" column in to the table above making it easy to connect the Nrf24L01 to the controller.
Here is the modified Spotlight Commander sketch for the Esp32
// Coming soon
I put one Arduino Nano in the garage window running the Spotlight Commander sketch. In the loop() I un-commented the function call "sendContinuously();" and commented out "getCommandsFromSerial();" call (in line 127) to send a continuos test signal from the commander. I connected another Arduino Nano to my laptop and ran the Spotlight Infrared remote controller sketch there. When I had a signal I saw blinking lights because it was writing to the serial and when it does that, a little yellow LED lights up.
I found that when trees were between the sender and the receiver the signal diminished dramatically but, when there was a direct line of sight between the Nanos the signal was strong and reached to the edge of my garden. I concluded that I will need a network to relay messages to nodes behind or near trees. I tested the RF24Network on the Esp32 and it just works. So, I will be using that.
I was able to run the DeviceServer and the Spotlight Commander in the same sketch.
Hello VoffCon Spotlight Commander world. This is a prove of concept and now I know WiFi and NRF24L01 will be able to work to gether. The prove is in two files see below. When running the code the spotlight changes the light but does that much slower than in the sketches above. I am changing the light after each WiFi client check which takes time. So slower is as expected.
// Coming soon
// Coming soon
Here I have a working solution. VoffCon sends commands to the server running on Esp32 and the server relays those commands to the clients. There is one client per floodlight.
Below, is a working server running on the Esp32. The server Nrf24L01 address is 00. It can process commands from VoffCon via WiFi (lan) and send them via Nrf24L01 to the Spotlight Infrared Remote Controllers. It's a relief that after all this work, this project can actually work.
// Coming soon
// Coming soon
// Coming soon
Here is the code for the flood lights. It consists of 3 files, SpotlightIRemoteController.ino, FloodLightRemote.cpp and FloodLightRemote.cpp. Each nano will listen for commands from the server and execute them by sending a Infrared signal to the flood light. The client Nrf24L01 addresses are from 01 to 04.
The client address is set in the beginning of the file SpotlightIRemoteController.ino (see: const uint16_t this_node =).
The remotes for each floodlight do not send exactly the same signals. To handle that each client must select the correct remote by defining a specific keyword in the file "FloodLightRemote.h". For example, to select the "SILVER_REMOTE_50W_1" remote, then the following must be un-commented #define SILVER_REMOTE_50W_1. Only one of the remote keywords should be un-commented. See code below.
// Coming soon
// Coming soon
// Coming soon
This part will take time. I will need to create a circuit, provide it with power and make it waterproof.
Plan 2 (canceled), last modified: 22.07.2020
I am not going to use the Nrf24L01 which should simplify and reduce the maintenance. I bought a out-door WiFi router and fitted it on my house chimney, allowing devices to connect to my local network from my garden. Each flood light will be controlled by one Esp32. For this to work I will need to be able to use the infrared transmit module with the Esp32 Micro-controller.
I bought four new 50W RGB floodlights which came with a remote control. I had some problems with the IR signals for these flood lights. I think the IR receiver is a little weaker than on my other flood lights. But I got these to work also. I used the sketch IRrecvDemo.ino in step 2 of the old plan to record the remote commands for the 50W floodlights. After that was done I changed the SendIRtoFloodlight.ino sketch in step 3 of the old plan. to include commands from this new remote control.
I put the new code into a class so, it will be easier to add the IR transmitter code to VoffCon
Here are the two files for the class FloodLightRemote
And here is the example ".ino" file which gets commands from the serial and send them to the flood light by using the class FloodLightRemote.
While testing, I found out when using the Esp32 to send IR signals, it did not work every time. The Esp32 pins are probably not powerful enough. For that reason I added a BC547B to the circuit to be able to use 5V instead of 3.3V pins and that made things reliable enough to be usable. I needed to position the IR Transmitter much closer to the floodlight than, when using the Arduino Nano, but that should be OK for this project.
When positioning the IR Transmitter, try to give commands while the flood light is showing the color BLUE or color CYAN on full power. These colors seem to interfere with the IR Transmission. If the flood light responds to the Esp32 commands when these two colors are lit, all other commands should work. Positioning the IR transmitter about 8cm from the IR receiver on the flood light seemed to be best for my project.
To add the class to VoffCon I will need to:
See below changed DeviceServer after including the class FloodLightRemote. VoffCon Cards (clients) can change the value of pin 32 to call the various IR commands.
Modifications to the VoffCon DeviceServerEsp32. I added these lines: (you can find most of them by searching for "fRemote".
The 25 available commands on pin 32 are:
0 : UP | 1 : DOWN | 2 : OFF | 3 : ON |
4 : RED | 5 : GREEN | 6 : BLUE | 7 : WHITE |
8 : RED_LIGHT | 9 : GREEN_LIGHT | 10 : PURPLE | 11 : FLASH |
12 : ORANGE | 13 : GREEN_CYAN | 14 : PURPLE_PINK | 15 : STROBE |
16 : ORANGE_LIGHT | 17 : CYAN | 18 : PINK | 19 : FADE |
20 : YELLOW | 21 : CYAN_GREEN | 22 : PINK_PURPLE | 23 : SMOOTH |
24 : FF |
You can always get them by connecting the device to a USB serial and give send the text string "NUMBERS" to the device via the serial.
The VoffCon control, the javascript class part
//comming soon
The VoffCon control, the html and css part
//comming soon
The VoffCon card
// Comming soon
// Comming soon
This is how the card looks like when it's run in VoffCon. It contains a picture where the floodlights are located around the house, and a remote control with clickable buttons allowing you to give the same command to one or more flood light. By clicking the flood lights on the card you can select and deselect the flood lights which will receive the command when you press the button on the remote control.
When trying to use the 3.3V micro controller to feed the transmitter via the 5V/VIN pin on the esp32, the signal is weak. I need to keep the transmitter about 8 cm away from the IR receiver on the flood light, it cannot be too close ether. This is bad because the light from the flood light especially cyan on full power interferes with the transmitted signal.
I tested four Esp32s in the same test, where the IR transmitters pointed to four different flood lights. I was not happy with the results. Sending commands to all of them did almost never work, I had to send the same command at least twice to make them all change to the same color. So I think I will continue with the first plan, giving command to one Esp32 which then will send commands to 5V micro controllers via Nrf24L01.