Checking the modules
It can be really frustrating when you put everything together in a nice casing, with all wires cut to the desired length, and you discover problems... So I suggest to test all modules separate and together before wiring if permanent. Use a breadboard and some Dupont cables to wire it up, and use the test programs to make sure everything works fine.
Checking the ESP8266
After wiring it up, use the next program when connected to your computer. Your serial monitor should tell you the results of an attempt to connect to your WIFI network.
Arduino Code:
void setup() { Serial.begin(9600); //<--This is the connection with your computer. Serial1.begin(115200); //<--This is the connection speed with your ESP. // WiFi SSID and Password String SSIDstring = ("#####"); //Replace ##### with your network name / SSID String PASSstring = ("#############"); //Replace ########### with the password of your network useESP("AT+RST\r\n", 2000); useESP("AT+CWMODE=1\r\n", 2000); useESP("AT+CWLAP\r\n", 8000); useESP("AT+CWJAP=\"" + SSIDstring + "\",\"" + PASSstring +"\"", 6000); useESP("AT+CIPSTATUS\r\n", 2000); useESP("AT+CIPMUX=1\r\n", 1000); useESP("AT+CIPSERVER=1,80\r\n", 1000); useESP("AT+CIFSR\r\n", 1000); } void loop() { } String useESP(String command, const int timeout) { String response = ""; Serial.println("=================================================="); Serial.println("The Arduino sends the next command to the ESP8266:"); Serial.println(command); Serial1.print(command); //<-- This is the real command to send to the ESP Serial.println(".................................................."); Serial.println("Waiting for response..."); long int time = millis(); while( (time + timeout) > millis()) { while(Serial1.available()) { char c = Serial1.read(); response += c; } } Serial.print(response); return response; }
The program communicates using serial 1 (TX1 and RX1) with the ESP8266. The program will show you the given command, and the response of the ESP8266.
Under normal circumstances, you should see the reset (RST) command, after which the ESP generates a summary. You also see a list of networks in your area, and the program tries to connect to your network. If that is possible, it will show you the given IP address. (a reference of usable commands can be found here)
When it does not connect, you still will get output on your monitor. (Otherwise your Arduino cannot communicate with your computer). If there is no response from your ESP8266 at all:
- No response at all can also be a result from a wrong baud-rate of your serial connection with the computer. (duh....) Both on 9600?
- Try a different power supply. On the web you can find problems with unstable power. You can also test with a power bank (has a USB connector itself!), a cellphone charger (idem) or even battery packs. (When you feed the Arduino 5 V through USB of a 5V line, it generates 3.3 for the ESP itself)
- An unstable kind of power can be solved with the use of a capacitor between 3.3V and ground. When there is a (little) noise on the power lines, most modules will work, but not the ESP8266. Even when its power led is on.
When there is response, but totally unreadable, too short or the word "busy..":
- Try another bitrate (baud) for the communication on Serial1 (= with the ESP). Maybe your version of firmware has a different baud rate.
- Shut down the power for some time. Every time you reset your Arduino / upload a new program, the ESP does not reset by itself. (it remains powered) In some cases, it is waiting for something (like a close command or a website to send of a given number of characters) and shall not take new orders before the current task has been finished.
Testing the FS1000a
To test the FS1000a, we need 3 more things:
- Some device or switch which uses the 433 MHz protocol for input. A big part of our project are the wireless switches, and our project is going to replace it's remote controls.
- We need the remote controls itself, to learn the code to be broadcasted.
- Therefor, we also need the 433 MHz receiver, but as we bought the RX and TX as a set...
Attach the receiver to 5V and ground, and connect one of the middle two data-pins to Arduino pin 2. You will nead an extra library if for your Arduino, so make sure RC-Switch is installed (of not, get it!).
The library of RC-Switch can handle the protocol we need. But not all power outlet sockets use the same protocol. It will be possible that you need another library of other hardware for your wireless switches, but the "klikaanklikuit" devices over here work.
Once you've setup the breadboard. just start the "ReceiveDemo_Advanced" script on your IDE. (Examples > RC-Switch > ReceiveDemo_Advanced)
Now you can use one of your remotes (maybe disable the receivers before...) and take a look at the information on your serial monitor:
Text Code:Decimal: 3700159 (24Bit) Binary: 001110000111010110111111 Tri-State: not applicable PulseLength: 306 microseconds Protocol: 1 Raw data: 9536,268,900,280,912,840,320,864,308,868,304,280,896,292,884,284,880,308,872,884,288,876,300,864,332,268,900,848,320,272,908,848,336,840,324,860,312,276,908,264,908,852,328,844,100,16,92,444,512,
Maybe I take some risk by showing you one of my codes, because everyone with an Arduino / FS1000a combination can broadcast a "3700159" code of 306 microseconds in front of my house to activate the SoundBlaster radio...
Learn all codes from your remote(s). As you can see the pair of codes (on and off for one device) are almost identical, only the "off"-code is one lower. (In my case: you can turn the SoundBlaster off with 3700158)
Now we take our breadboard again, and setup for the transmitter: de FS1000a. Wired as mentioned in the section before, you can run the next test:
Arduino Code:
#include <RCSwitch.h> RCSwitch mySwitch = RCSwitch(); #define pinTX 53 #define pulseLength 306 #define bitLength 24 #define protocol 1 void setup() { mySwitch.enableTransmit(pinTX); mySwitch.setPulseLength(pulseLength); mySwitch.setProtocol(protocol); } void loop() { mySwitch.send(3700159, bitLength); delay(2000); mySwitch.send(3700158, bitLength); delay(2000); }
With this script, the power outlet socket will be turned on and off every four seconds.
Troubleshooting:
- If you can receive the codes (with the RC-Switch library and the receiver) you would be able to send codes. If you can't receive, there is a possibility of the use of a protocol which cannot be handled by RC-Switch or this hardware.
- If you can receive codes, but sending them won't let anything happen and codes seem to change often... You may deal with a system with "rolling code". As a measure of security, some devices use a system with encryption / calculated keys. As long as you cannot get your hands on their algorithm, it won't be possible to control that kind of devices.
- When their seems to be an unpredictability in your results, there may be interfering factors or a too big distance. Remember, it is possible to add an antenna on the transmitter!
Testing the OLED I2C SSD1306 12864 LCD
The OLED is connected to two special pins: the I2C-bus. As in computers more devices can share one bus, because communication will use addresses. So you need to find the address of your screen first. That can be done with an I2C Scanner. Once you've got it, you can test your screen with the Adafruit SSD1306 library example. (Make sure you also install the Adafruit GFX library) If you'll get the warning to fix your SSD1306 library, open up the Adafruit_SSD1306.h file in your editor. The only line uncommented should be the line with your screen resolution:
Arduino Code:
/*========================================================================= SSD1306 Displays ----------------------------------------------------------------------- The driver is used in multiple displays (128x64, 128x32, etc.). Select the appropriate display below to create an appropriately sized framebuffer, etc. SSD1306_128_64 128x64 pixel display SSD1306_128_32 128x32 pixel display SSD1306_96_16 -----------------------------------------------------------------------*/ #define SSD1306_128_64 //<<-- My resolution, this line is oncommented // #define SSD1306_128_32 //<<-- Not my resolution, this line is commented // #define SSD1306_96_16 //<<-- Not my resolution, this line is commented
(Normally, this file can be found on your hard drive: users\#username#\documents\Arduino\libraries\Adafruit_SSD1306\ )
Testing the relay-bank
As you wired as mentioned before, you can use the program below to test your relays. When using for testing purposes, we do not attach the relays to outlet sockets. The relays have LED's on board, so testing is possible without the dangerous alternating current from your wall socket.
Arduino Code:
void setup() { for (int i = 22; i < 36; i = i + 2){ pinMode (i, OUTPUT); digitalWrite (i, HIGH); } void loop() { for (int i = 22; i < 36; i = i + 2){ digitalWrite (i), LOW); //<-- Turn relay ON delay(1000); } for (int i = 22; i < 36; i = i + 2){ digitalWrite (i), HIGH); //<-- Turn relay OFF delay(1000); } }
Running these code let all relays go on and off.
Troubleshooting:
- This is the only part with both alternating current and weak current(!), and the PCB has a jumper for more safety: it is possible to operate the relays with another power supply to isolate the Arduino more. In this example we leave the jumper on JD-VCC. So make sure your jumper is at the same position.
Testing the push button
Although there is nothing spectacular about testing a pushbutton, I will test it. When having troubles with the main program, there is nothing more frustrating than "things you would expect to work, but they didn't". So use the button example in the IDE (examples > 2.0 Digital > Button) to check your connections.