Today I would like to talk about how to make a remote control and monitoring system that can be used, for example, to control garage doors, lighting, heating, pressure control, temperature and many other parameters. But the main feature of this system is that you can remotely receive photos from a remote object. Before you begin the story, a short preface.
Once I wanted to make a photo surveillance system using a compatible Arduino M0-SD board, a VC0706 camera and a 3G/GPRS/GSM/GPS shield for Arduino. The Arduino M0-SD compatible board was chosen from the conditions that it is very easy to program (just like the Arduino UNO), the operating voltage is 3.3V - this is very convenient for working with the VC0706 camera, a large amount of ROM and RAM, several ports the UART, a separate virtual port of the USB, but the main advantage is the presence of a micro SD connector directly on the board (It is very convenient to store large amounts of data, such as images).
3G/GPRS/GSM/GPS shield for Arduino is very convenient for use with a compatible Arduino M0-SD board. There are several libraries on the Internet, as well as many examples for working with this shield. The data transfer rate (3G) is much higher than that of conventional GPRS shields (especially convenient for transmitting images). Availability of GPS module is an additional advantage.
I chose a low-cost tariff from a cellular operator for data (photos) transmission over the Internet. But the question arose: how to transfer data? MMS? FTP? How to get a notification about the receipt of data (photo)? As a result, I came to the decision to send data (photos) to e-mail and view letters through the application installed on a mobile phone. It turned out to be very convenient! :-) The finished project can be viewed at this link.
There is also a similar project for Arduino UNO by reference.
Then I decided to expand the functionality of my device. For example, add the ability to control LEDs (although in reality the possibilities are much wider). E-mail for this is not very suitable. SMS option is expensive and uncomfortable. And then I learned about the MQTT. I will not describe what he is. Let me just say: This is a really cool thing! :-) With the help of MQTT, you can exchange not only messages, but also binary files (images). In the application for the phone, you can easily create your own interface.
I looked for examples of implementation of the MQTT protocol for my 3G/GPRS/GSM/GPS shield (SIM5320) and, unfortunately, did not find the implementation I needed. But that didn't leave me alone. I decided to independently implement the necessary functionality. As a result, I managed to create a device that is controlled (indicated by three LEDs) over MQTT from an application installed on a mobile phone, and also sends a photo to the phone on command from the phone. (I will tell you a secret that I haven’t seen any examples of sending images through the MQTT broker before and did it for the first time. And when I managed to transfer the first picture I was immensely happy! :-) ) And so, I propose to go straight to the first step - a list of necessary components.
Step 1: List of Components
Step 2: Preparation of Camera
The camera has a RS-232 output for direct connection to a PC. It is necessary to remove the MAX232 (RS-232 converter) and close the contact pads between the corresponding pins 7-10 (TX), 8-9 (RX).
The six-wire cable that came with the camera needs to be slightly redone:
- Remove the two wires from the connector.
- Rearrange the red (+ 5V) and black (GND) wires as shown in the figure.
On the bare ends of the wires must be soldered tips like "female".
Step 3: Preparation of Compatible Arduino M0-SD
As already mentioned, the compatible Arduino M0-SD is hardware and software compatible with the original Arduino M0, but it also has an onboard microSD connector for connecting a memory card.
To connect the camera to the compatible Arduino M0-SD on the board it is necessary to solder the angular connector to the terminals TXD, RXD (connector X6) as shown in the figure. This port matches to the "Serial".
White (Camera RX) and yellow (Camera TX) wires from the camera must be connected respectively to the terminals of the TXD and RXD (connector X6) as shown in the figure.
Step 4: Preparation of 3G/GPRS/GSM/GPS Shield SIM5320
Before installing a sim card in the slot, you must disable the PIN code request. Then install the SIM card in the slot on the bottom side of the board as shown in the figure.
Two jumpers must be installed in the position RX-1 (D1), TX-0 (D0).
Step 5: Hardware Assembly
Hardware assembly consists of several simple operations:
- To control the LEDs, you first need to solder a small design of LEDs and current-limiting resistors (100-500 Ohm) as shown in the figure. Pay attention to the polarity of the LEDs - the anode must be soldered to the resistors (+). To reduce the parasitic exposure of the LEDs, I made a black screen out of regular cardboard.
- Сonnect the LEDs and the camera to a compatible Arduino M0-SD board as shown in the diagram. The power supply of the camera (red wire "+ 5V" and black wire "GND") must be taken from the "+5V" and the "GND" terminals from the slot. You can also use a angle connector for this.
- After that, connect the 3G/GPRS/GSM/GPS shield to the compatible Arduino M0-SD board. Do not forget to connect a 3G antenna.
Step 6: Setting MQTT Broker
I chose a very convenient and clear www.cloudmqtt.com as an MQTT broker. It provides free testing. It is also possible to receive and send messages directly on the site.
The setup procedure is as follows:
- Register online.
- Press button "Create New Instance".
- Set the name, for example "MqttCamera".
- Press button "Select Region". For example, select "US-East-1 (Northern Virginia)".
- Press button "Review".
- Press the button "Create Instance". View message "Instance succesfully created".
- Click "MqttCamera".
- Remember information: Server, User, Password, Port, API Key (We will need it at the 7th and 8th steps).
- Then you can go to the "WEBSOCKET UI" window, where you can test and debug, view and send messages (We will need this window in the next step).
Step 7: MQTT Dash App
To create a control panel in a mobile phone, I chose a very user-friendly and clear MQTT Dash app.
Install the app MQTT Dash on your phone and make the following settings:
- Open the application.
- In the MQTT dash window, click (+) to add a new control panel.
- In the window that appears, fill in the required fields, such as: Name (for example, MqttCamera), Address, Port, User name, User password (Take data from step 6).
- After filling in the fields, click the diskette icon (operation "Save").
- In the window with the list of control panels, click on the appeared line "MqttCamera".
- In the control panel window that opens, click the arrow icon to load the metrics.
- Then in the pop-up window, click on the button "SUBSCRIBE AND WAIT FOR THE METRIC".
- On a personal computer, open an account in an MQTT-broker (see the previous step), open the "WEBSOCKET UI" window, set the "metrics/exchange" topic in the "Send message" window, and record the text from the attached metrics.txt file in the "Message" window, click button "Send".
- Wait 10 seconds, make sure that the metric is received in the phone and the control panel is updated.
Then you can proceed to programming compatible Arduino M0-SD.
Step 8: Programming and Work
Before programming compatible Arduino M0-SD, you need to install on the computer all the necessary libraries (pubsubclient-master, TinyGSM-master), which I cited below. These libraries were slightly modified to work with a compatible Arduino M0-SD board, a VC0706 camera, and a 3G/GPRS/GSM/GPS SIM5320 shield.
You need to connect your cable and power supply (6V 1A for powering 3G/GPRS/GSM/GPS shield) to the compatible Arduino M0-SD.
Start Arduino IDE. In Arduino the IDE needs to choose: Tools-> Board: Arduino M0 Pro (Native USB Port).
Open the sketch MqttCamera.ino. Fill in the fields: User name, User password, API Key, Port, Server (Take data from step 6).
Open the Serial Monitor window.
Upload sketch. I do not describe in detail the programming procedure (there are enough instructions on the Internet).
After successful loading and proper assembly, the following information should appear in the Serial Monitor window:
VC0706 Camera + Arduino M0 + SIM5320 + MQTT Camera init... version: ----------------- VC0703 1.00 Ctrl infr exist User-defined sensor 525 ----------------- success! Initializing modem... Modem: AT+CGMM SIMCOM_SIM5320E Waiting for network... OK Connecting to internet OK Connecting to 18.104.22.168 fail Connecting to 22.214.171.124 OK Ping: 0
The line "Ping: XX" is a periodic message from the compatible Arduino M0-SD to the server. Instead of this information, you can send ADC measurements, input status, and more.
In the MQTT Dash app, click on the icons of the light bulbs (LED_YELLOW, LED_GREEN, LED_RED) - turn on/off. Look in the window of the Serial monitor - there should be information about something like this:
LED_YELLOW On LED_YELLOW_Off LED_GREEN On LED_GREEN off LED_RED On LED_RED Off
Click on the camera icon - send the command "SHOOT" and wait a while. The following information should appear in the Serial Monitor window:
Start Shoot! Picture taken! create IMAGE332.JPG wait to fetch 3488 byte image ...Done! Took 1456 ms Send picture (3488 bytes)...done!
And after a while (5-10 seconds) in the window "VIEW IMAGE" should be displayed photo.
For the demonstration, I directed the VC0706 camera to the LEDs so that you can see their status after I switched them in an arbitrary manner. But in real use, you can direct the camera to a room, door, street, gate, car, etc. (Of course, you must take into account the requirements of the law).
As a demonstration, I present several screenshots from a mobile phone, where the installed and actual states of the LEDs are displayed.
I hope my instruction was interesting and useful for you. I will be glad to your feedback and comments. In my plans to develop my device and share with you new innovations. Thanks for watching!