# Blockchain-Based Cloud-Enabled Security Monitoring Using Internet of Things in Smart Agriculture
## 6 Implementation  
In order to evaluate the proposed smart-agriculture security monitoring approach using blockchain and cloud technologies, we implemented a prototype using the Arduino Sensor kit with Wi-Fi capabilities to mimic the various sensors deployed in the farmland, AWS cloud components to process the sensor data, Ethereum blockchain to store the monitoring alerts and other essential information using smart contracts, and developed a web frontend to display the alerts to the users. Experimental setup: The following software or hardware components such as Arduino sensor kit, EP8266 Wi-Fi module, AWS IoT core component, AWS lambda function, infura Ethereum API Account, and Web Javascript were used to perform the experiments. The Arduino module with Wi-Fi was connected to the home Wi-Fi router for communicating to the cloud. Our security monitoring application can be developed as a product or third-party security monitoring tools for smart-agriculture IoT device's security. Arduino sensor kit contains Potentiometer, light sensor, sound sensor, air pressure sensor, temperature sensor, and accelerometer sensor to monitor and capture various environmental, physical, and other conditions. The breadboard is used to connect these sensor devices to the communication equipment, i.e., Wi-Fi module. The Wi-Fi module also acts as edge gateway for all the sensor devices mentioned in our experimental setup. The Arduino C language code was written to connect the Wi-Fi module with the home router, and external communication to the remote AWS IoT nodes for event updates. The SSID and password key details of the Wi-Fi home router are provided in the Arduino to connect to the internet. The AWS IoT core service is created in AWS Cloud with few generic configuration settings. The AWS IoT core runs on the Free RTOS operating systems for IoT-device data processing and exchanging the data using the MQTT protocol. The AWS IoT core could display the sensor device data and can be stored in cloud storage such as S3. The AWS Lambda function was written in JavaScript programming language to constantly poll the sensor-events' data from AWS core. The monitoring logic is implemented in the AWS lambda function to identify the sensor status and sensor data anomalies. The infura API calls were also performed using the AWS lambda function to update the sensor monitoring data for permanent storage in the blockchain. The infura account is needed to generate the API key and establish a connection to the Ethereum network. Therefore, the alert data is updated to the blockchain and stored in the transaction. To implement the end-to-end application, the infura API calls are used to retrieve the alert transaction from the Ethereum blockchain. The farmer may download the mobile application or web app to monitor the farm alerts remotely. Figure 3 displays the Arduino microcontroller used to control and connect to the IoT sensing devices. The temperature sensor and humidity and light sensor are connected to the microcontroller, and the microcontroller supports a Wi-Fi connection to communicate with cloud services. The sensors can be considered as agriculture application end devices. As shown in Figure 3, the temperature and light sensor positive terminals such as A3, and D3 are connected to the microcontroller PINS. The negative terminals are grounded to prevent short-circuiting issues. The microcontroller is power supplied with 5V, which is shown in Figure 3 with a red wire connection. As shown in Figure 4, the sensing device's status will be monitored using the desktop application. The Arduino controller is connected to the laptop via wired communication. The sensor measures real-time activity such as temperature and light in the farming. We installed the Arduino software application on the laptop machine to run the C code on the Arduino kit.