Skip to content

reidliujun/arduino_project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arduino is an open-source flexible electronics prototyping platform that allows rapid development of small computing devices. By using Xbee module on Arduino, a policy based remote light control system is designed in this report. The cloud server performs a control center in this system, and the data collected from sensors is stored in online database. Finally, the data can be shown by web browser on any users own computer or laptop.

A. Arduino devices configuration and data structure

The server contains the logic of analyzing LDR data and determining whether to turn the LED on or off. Arduino device 2 collects data from the LDR and is able to turn on and of the LED. However, it is not connected to the internet and cannot reach the server. That is why another Arduino device (1) is used. Arduino device 1 has an ethernet connection and can connect to the server through the Internet. The data is passed between two Arduino devices using ZigBee protocol. In this way, LDR values from second Arduino device can reach the server and server commands can be forwarded to the same Arduino device (2). Therefore, Arduino device 1 acts as a router between two protocols: Ethernet and ZigBee. Of course, if LDR and LED values would be connected to different Arduino devices, the Arduino device that does message forwarding should also know to which node to forward commands from the server. The two Arduino devices communicate with each other using ZigBee communication protocol. The parameters for the ZigBee TABLE I. Xbee modules recognize “+++” as the command of configuration, and configuration is implemented through serial port. The AT-style commands of Xbee start with “AT“, and will return “OK” if configuring successfully. Devices with same PAN ID belong to the same group and can talk to each other, and the destination address belongs to the other communication object.

Arduino Wireless Shields are used to allow Arduino board communicate with each other using Xbee module. When programming on Arduino, the serial select switch on wireless shields need to be ”USB”. When switched to “Micro“, the Xbee will be connected to communicate with the microcontroller on the Arduino. In Arduino device 1, Arduino USB2Serial board is used to connect the Arduino Ethernet board with USB serial for programming. DHCP is used so that the device can work by insert the ethernet cable into any network plug in the campus. By using “Telnet” on the device, it can telnet to the server address. The device can forward the message of LDR value to the server, and forward the response from the server to change the LED brightness value. On Arduino device 2, according to TinkerKit library, the following codes can be used to get brightness value from

LDR: TKLightSensor ldr(I0); short brightnessVal = ldr.get(); and the LED output can be set as: TKLed led(O0); led.brightness(ledValue);

Simple data exchange protocol was created in order to exchange data and control LED in a deterministic way. The protocol is text based. First character “C” indicates the start of the command. A command ends with a line feed. First integer in the command indicates command ID, second - sensor ID, third is additional parameter. Used commands are presented in table 2.

B. Server implementation After the connection is established between the two Arduino devices, the one with LDR sends measurements of LDR value every half second to the other Arduino device. This data is then forwarded to the server. The server process received data, stores LDR value to the database and decides whether to change the state of LED, that is placed in the same place as the LDR. The Server runs two programs and a database daemon.

The first program is written in Python and is used for real time communication between the server and the Arduino device. The server has a public domain “ec2-107-22-111-91.compute-1.amazonaws.com”. Program accepts connections on port 8080. It supports many simultaneous connections and can serve many Arduino devices. The only limitation is, that Arduino device have to send data to the program with its own ID and cannot use multiple different IDs for the same connection. Upon receiving data the server first checks the validity of command and then, if it is valid, extracts the LDR value. LDR value is first stored to the database and then checked by the algorithm which determines whether to change the state of the LED. Currently, the program is configured to consider that it is too dark if the LDR value is less than 600. Upon receiving such value, the server will send a command back asking Arduino device to turn on the LED (Command example “C 2 2 1023”). Then, the server expects Arduino device to acknowledge, that it received the command and changed the state of LED. Acknowledgement is necessary, as the command might be lost due to connection errors while sending data through the Internet or between Arduino devices using ZigBee. If the arduino device does not acknowledge, the server sends another command to turn on the LED if it again receives a LDR value less than 600. Upon receiving the acknowledgement, the server will not send more commands to the Arduino until the LDR value becomes at least 600 indicating that the LED should be turned off. In this way, acknowledgements guarantee reliability and lowers the amount of messages sent between the server and the Arduino device, since the server does not need to reply to all LDR data messages.

The second program is written in Javascript using Node.js and Express framework and is used to display information about LDR and LED. Node.js program runs as a web server on port 3000, therefore clients can access the information using a web browser by navigating to “ec2-107-22-111-91.compute-1.amazonaws.com”. Google Charts API is used to display gathered LDR values in a visual and easy to understand way. The data is obtained from the same database, where the Python program stores each measurement. Server also gives the current value of the LED. The database used in this project is MongoDB. It is an open source noSQL database. Mongo DB was chosen due to its powerful API and simple access from various programming languages. Furthermore, the project does not require sophisticated queries and there is no need of running a heavy weight full relational database. The database contains a table where all LDR values are stored.

About

arduino project for intelligent led control

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published